Folder Management With Vbscript: You Are Here: Folders
Folder Management With Vbscript: You Are Here: Folders
ActiveXperts.com > ActiveXperts Network Monitor > WindowsManagement > Scripts >
Storage > Folders
Quicklinks
You can use any of the VBScript programs below in ActiveXperts Network
Monitor. Click here for an explanation about how to include scripts in ActiveXperts
Network Monitor.
Uses the Shell object to display the Browse for Folder dialog box. After a folder has been
selected, the script reports whether or not the folder is read-only.
Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
objPath = objFolderItem.Path
objPath = Replace(objPath, "\", "\\")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer &
"\root\cimv2")
Uses the Shell object to copy the folder C:\Scripts to D:\Archives. Displays the Copying
Files progress dialog as the folder is being copied.
Const FOF_CREATEPROGRESSDLG = &H0&
ParentFolder = "D:\Archive"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ParentFolder)
objFolder.CopyHere "C:\Scripts", FOF_CREATEPROGRESSDLG
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create _
("C:\Finance", "FinanceShare", FILE_SHARE, _
MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
Compress a Folder
Copy a Folder
Demonstration script that uses the FileSystemObject to copy a folder to a new location.
Script must be run on the local computer.
Const OverWriteFiles = TRUE
Create a Folder
Demonstration script that uses the FileSystemObject to create a folder. Script must be run
on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("C:\FSO")
Delete a Folder
Demonstration script that uses the FileSystemObject to delete a folder. Script must be run
on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("C:\FSO")
Stops sharing a shared folder named FinanceShare. This does not delete the folder from
the local hard drive, but simply stops making it available over the network.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Deletes a published folder named FinanceShare from Active Directory. This does not
delete the share itself, it simply removes it from Active Directory.
Set objContainer = GetObject("LDAP://CN=FinanceShare, " _
& "OU=Finance, DC=fabrikam, DC=com")
objContainer.DeleteObject (0)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
ShowSubFolders Subfolder
Next
End Sub
Returns a list of all the folders on a computer. This can take 15 minutes or more to
complete, depending on the number of folders on the computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Lists all the folders on a computer that were created after 3/1/2002.
Const LOCAL_TIME = TRUE
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer &
"\root\cimv2")
Uses a WMI Associators of query to list all the subfolders of the folder C:\Scripts.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Demonstration script that uses the FileSystemObject to return the folder name and size
for all the subfolders in a folder. Script must be run on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
Set colSubfolders = objFolder.Subfolders
Lists all the shared folders that have been published in Active Directory.
Const ADS_SCOPE_SUBTREE = 2
Do Until objRecordSet.EOF
Wscript.Echo "Share Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "UNC Name: " & objRecordSet.Fields("uNCName").Value
Wscript.Echo "Managed By: " & objRecordSet.Fields("ManagedBy").Value
objRecordSet.MoveNext
Loop
Returns a list of Shell object verbs (context menu items) for the Recycle Bin.
Const RECYCLE_BIN = &Ha&
For i = 0 to colVerbs.Count - 1
Wscript.Echo colVerbs.Item(i)
Next
Uses a WMI Associators of query to return the local path of a network share named
Scripts.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Demonstration script that uses the FileSystemObject to check if a folder is hidden and, if
it is not, hides it. Script must be run on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
Uses the Shell object to move the folder C:\Scripts to D:\Archives. Displays the Copying
Files progress dialog as the folder is being moved.
Const FOF_CREATEPROGRESSDLG = &H0&
TargetFolder = "D:\Archive"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(TargetFolder)
objFolder.MoveHere "C:\Scripts", FOF_CREATEPROGRESSDLG
Uses a WMI Associators of query to return the local path of all the network shares on a
computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Move a Folder
Demonstration script that uses the FileSystemObject to move a folder from one location
to another. Script must be run on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\Scripts" , "M:\helpdesk\management"
Publishes a shared folder in Active Directory, assigning the folder a description and three
keywords.
Set objComputer = GetObject _
("LDAP://OU=Finance, DC=fabrikam, DC=com")
Rename a Folder
Demonstration script that uses the FileSystemObject to rename a folder. Script must be
run on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\FSO\Samples" , "C:\FSO\Scripts"
dtmTargetDate = "20020301000000.000000-420"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer &
"\root\cimv2")
Returns a list of all the folders whose path begins with C:\S.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Searches Active Directory for any shared folders that have the keyword "finance."
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Do Until objRecordSet.EOF
Wscript.Echo "Share Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "UNC Name: " & objRecordSet.Fields("uNCName").Value
Wscript.Echo "Managed By: " & objRecordSet.Fields("ManagedBy").Value
objRecordSet.MoveNext
Loop
Uncompress a Folder
Demonstration script that uses the FileSystemObject to verify that a folder exists. If the
folder does exist, the script binds to that folder. Script must be run on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("C:\FSO") Then
Set objFolder = objFSO.GetFolder("C:\FSO")
Else
Wscript.Echo "Folder does not exist."
End If