You are here:
[Link] > ActiveXperts Network Monitor > WindowsManagement > Scripts >
Storage > Folders
Monitor servers, workstations, devices and applications in your network
Quicklinks
• Download ActiveXperts Network Monitor 7.2 (11850 KB)
• Download Manual (925 KB)
Folder Management with VBScript
Bind to a Folder Using the Browse for Folder Dialog Box
Create a Folder Using the Shell Object
Copy a Folder Using the Shell Object
Copy a Folder Using WMI
Create a Network Share
Compress a Folder
Copy a Folder
Create a Folder
Delete a Folder
Delete a Folder on the Local Computer
Delete a Network Share
Delete a Published Folder
Enumerate Subfolders Using Recursion
List All the Folders on a Computer
List Folder Attributes
List Folders Based on Creation Date
List the Subfolders of a Folder
List Folder Properties
List Folder Properties
List Network Shares
List the Subfolders of a Folder on the Local Computer
List Shared Folders Published in Active Directory
List Shell Object Verbs
List a Specific Set of Folders
Map All Network Shares to Local Folders
Modify Folder Attributes
Move a Folder Using the Shell Object
Move a Folder Using WMI
Modify a Network Share
Map a Network Share to a Local Folder
Move a Folder
Publish a Shared Folder in Active Directory
Rename a Folder
Rename a Folder on the Local Computer
Search for Folders by Date
Search for Folders Using Wildcards
Search for Specific Published Folders in Active Directory
Uncompress a Folder
Verify that a Folder Exists
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.
Bind to a Folder Using the Browse for Folder Dialog Box
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
Set objShell = CreateObject("[Link]")
Set objFolder = [Link] _
(WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts")
Set objFolderItem = [Link]
objPath = [Link]
objPath = Replace(objPath, "\", "\\")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer &
"\root\cimv2")
Set colFiles = [Link] _
("Select * from Win32_Directory where name = '" & objPath & "'")
For Each objFile in colFiles
[Link] "Readable: " & [Link]
Next
Create a Folder Using the Shell Object
Uses the Shell object to create a new folder named C:\Archive.
ParentFolder = "C:\"
set objShell = CreateObject("[Link]")
set objFolder = [Link](ParentFolder)
[Link] "Archive"
Copy a Folder Using the Shell Object
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("[Link]")
Set objFolder = [Link](ParentFolder)
[Link] "C:\Scripts", FOF_CREATEPROGRESSDLG
Copy a Folder Using WMI
Uses WMI to copy the folder C:\Scripts to D:\Archive.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colFolders = [Link]( _
"Select * from Win32_Directory where Name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = [Link]("D:\Archive")
Next
Create a Network Share
Creates a shared folder named FinanceShare, setting the maximum number of
simultaneous connections to 25 and adding a share description.
Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 25
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set objNewShare = [Link]("Win32_Share")
errReturn = [Link] _
("C:\Finance", "FinanceShare", FILE_SHARE, _
MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
Compress a Folder
Compresses the folder C:\Scripts.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colFolders = [Link] _
("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = [Link]
Next
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
Set objFSO = CreateObject("[Link]")
[Link] "C:\Scripts" , "C:\FSO" , OverWriteFiles
Create a Folder
Demonstration script that uses the FileSystemObject to create a folder. Script must be run
on the local computer.
Set objFSO = CreateObject("[Link]")
Set objFolder = [Link]("C:\FSO")
Delete a Folder
Deletes the folder C:\Scripts.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colFolders = [Link] _
("Select * from Win32_Directory where Name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = [Link]
Next
Delete a Folder on the Local Computer
Demonstration script that uses the FileSystemObject to delete a folder. Script must be run
on the local computer.
Set objFSO = CreateObject("[Link]")
[Link]("C:\FSO")
Delete a Network Share
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")
Set colShares = [Link] _
("Select * from Win32_Share Where Name = 'FinanceShare'")
For Each objShare in colShares
[Link]
Next
Delete a Published Folder
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")
[Link] (0)
Enumerate Subfolders Using Recursion
Demonstration script that uses the FileSystemObject to recursively list all the subfolders
(and their subfolders) within a folder. Script must be run on the local computer.
Set FSO = CreateObject("[Link]")
ShowSubfolders [Link]("C:\Scripts")
Sub ShowSubFolders(Folder)
For Each Subfolder in [Link]
[Link] [Link]
ShowSubFolders Subfolder
Next
End Sub
List All the Folders on a Computer
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")
Set colFolders = [Link]("Select * from
Win32_Directory")
For Each objFolder in colFolders
[Link] [Link]
Next
List Folder Attributes
Demonstration script that uses the FileSystemObject to enumerate the attributes of a
folder. Script must be run on the local computer.
Set objFSO = CreateObject("[Link]")
Set objFolder = [Link]("C:\FSO")
If [Link] AND 2 Then
[Link] "Hidden folder."
End If
If [Link] AND 4 Then
[Link] "System folder."
End If
If [Link] AND 16 Then
[Link] "Folder."
End If
If [Link] AND 32 Then
[Link] "Archive bit set."
End If
If [Link] AND 2048 Then
[Link] "Compressed folder."
End If
List Folders Based on Creation Date
Lists all the folders on a computer that were created after 3/1/2002.
Const LOCAL_TIME = TRUE
Set dtmTargetDate = CreateObject("[Link]")
Set dtmConvertedDate = CreateObject("[Link]")
[Link] "3/1/2004", LOCAL_TIME
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer &
"\root\cimv2")
Set colFolders = [Link] _
("Select * from Win32_Directory Where " _
& "CreationDate > '" & dtmTargetDate & "'")
For each objFolder in colFolders
[Link] = [Link]
[Link] [Link] & VbTab & _
[Link](LOCAL_TIME)
Next
List the Subfolders of a Folder
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")
Set colSubfolders = [Link] _
("Associators of {Win32_Directory.Name='c:\scripts'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder in colSubfolders
[Link] [Link]
Next
List Folder Properties
Demonstration script that uses the FileSystemObject to enumerate the properties of a
folder. Script must be run on the local computer.
Set objFSO = CreateObject("[Link]")
Set objFolder = [Link]("C:\Scripts")
[Link] "Date created: " & [Link]
[Link] "Date last accessed: " & [Link]
[Link] "Date last modified: " & [Link]
[Link] "Drive: " & [Link]
[Link] "Is root folder: " & [Link]
[Link] "Name: " & [Link]
[Link] "Parent folder: " & [Link]
[Link] "Path: " & [Link]
[Link] "Short name: " & [Link]
[Link] "Short path: " & [Link]
[Link] "Size: " & [Link]
[Link] "Type: " & [Link]
List Folder Properties
Lists the properties of the folder C:\Scripts.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colFolders = objWMIService. _
ExecQuery("Select * from Win32_Directory where name =
'c:\\Scripts'")
For Each objFolder in colFolders
[Link] "Archive: " & [Link]
[Link] "Caption: " & [Link]
[Link] "Compressed: " & [Link]
[Link] "Compression method: " & [Link]
[Link] "Creation date: " & [Link]
[Link] "Encrypted: " & [Link]
[Link] "Encryption method: " & [Link]
[Link] "Hidden: " & [Link]
[Link] "In use count: " & [Link]
[Link] "Last accessed: " & [Link]
[Link] "Last modified: " & [Link]
[Link] "Name: " & [Link]
[Link] "Path: " & [Link]
[Link] "Readable: " & [Link]
[Link] "System: " & [Link]
[Link] "Writeable: " & [Link]
Next
List Network Shares
Lists all the shared folders on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colShares = [Link]("Select * from Win32_Share")
For each objShare in colShares
[Link] "Allow Maximum: " & [Link]
[Link] "Caption: " & [Link]
[Link] "Maximum Allowed: " & [Link]
[Link] "Name: " & [Link]
[Link] "Path: " & [Link]
[Link] "Type: " & [Link]
Next
List the Subfolders of a Folder on the Local Computer
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("[Link]")
Set objFolder = [Link]("C:\FSO")
Set colSubfolders = [Link]
For Each objSubfolder in colSubfolders
[Link] [Link], [Link]
Next
List Shared Folders Published in Active Directory
Lists all the shared folders that have been published in Active Directory.
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("[Link]")
Set objCommand = CreateObject("[Link]")
[Link] = "ADsDSOObject"
[Link] "Active Directory Provider"
Set [Link] = objConnection
[Link] = "Select Name, unCName, ManagedBy from " _
& "'LDAP://DC=Fabrikam,DC=com' where objectClass='volume'"
[Link]("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = [Link]
[Link]
Do Until [Link]
[Link] "Share Name: " & [Link]("Name").Value
[Link] "UNC Name: " & [Link]("uNCName").Value
[Link] "Managed By: " & [Link]("ManagedBy").Value
[Link]
Loop
List Shell Object Verbs
Returns a list of Shell object verbs (context menu items) for the Recycle Bin.
Const RECYCLE_BIN = &Ha&
Set objShell = CreateObject("[Link]")
Set objFolder = [Link](RECYCLE_BIN)
Set objFolderItem = [Link]
Set colVerbs = [Link]
For i = 0 to [Link] - 1
[Link] [Link](i)
Next
List a Specific Set of Folders
Returns a list of all the hidden folders on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colFiles = [Link] _
("Select * from Win32_Directory Where Hidden = True")
For Each objFile in colFiles
[Link] [Link]
Next
Map All Network Shares to Local Folders
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")
Set colShares = [Link]("Select * From Win32_Share")
For Each objShare in colShares
Set colAssociations = [Link] _
("Associators of {Win32_Share.Name='" & [Link] & "'} " _
& " Where AssocClass=Win32_ShareToDirectory")
For Each objFolder in colAssociations
[Link] [Link] & vbTab & [Link]
Next
Next
Modify Folder Attributes
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("[Link]")
Set objFolder = [Link]("C:\FSO")
If [Link] = [Link] AND 2 Then
[Link] = [Link] XOR 2
End If
Move a Folder Using the Shell Object
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("[Link]")
Set objFolder = [Link](TargetFolder)
[Link] "C:\Scripts", FOF_CREATEPROGRESSDLG
Move a Folder Using WMI
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colFolders
= [Link] _ ("Select * from Win32_Directory where name =
'c:\\Scripts'") For Each objFolder in colFolders errResults =
[Link]("C:\Admins\Documents\Archive\VBScript") Next
Uses WMI to move the folder C:\Scripts to
C:\Admins\Documents\Archive\VBScript.
Modify a Network Share
Accesses a shared folder named FinanceShare, changes the maximum number of
simultaneous connections to 50, and provides a new share description.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colShares = [Link] _
("Select * from Win32_Share Where Name = 'FinanceShare'")
For Each objShare in colShares
errReturn = [Link](50, _
"Public share for HR administrators and the Finance Group.")
Next
Map a Network Share to a Local Folder
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")
Set colShares = [Link] _
("Associators of {Win32_Share.Name='Scripts'} Where " _
& "AssocClass=Win32_ShareToDirectory")
For Each objFolder in colShares
[Link] [Link]
Next
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("[Link]")
[Link] "C:\Scripts" , "M:\helpdesk\management"
Publish a Shared Folder in Active Directory
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")
Set objShare = [Link]("volume", "CN=FinanceShare")
[Link] "uNCName", "\\atl-dc-02\FinanceShare"
[Link] "Description", "Public share for users in the Finance
group."
[Link] "Keywords", Array("finance", "fiscal", "monetary")
[Link]
Rename a Folder
Renames the folder C:\Scripts to C:\Repository.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colFolders = [Link] _
("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = [Link]("C:\Script Repository")
Next
Rename a Folder on the Local Computer
Demonstration script that uses the FileSystemObject to rename a folder. Script must be
run on the local computer.
Set objFSO = CreateObject("[Link]")
[Link] "C:\FSO\Samples" , "C:\FSO\Scripts"
Search for Folders by Date
Finds all the folders created after March 1, 2002.
On Error Resume Next
dtmTargetDate = "20020301000000.000000-420"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer &
"\root\cimv2")
Set colFolders = [Link] _
("Select * from Win32_Directory Where CreationDate > '" & _
dtmtargetDate & "'")
For Each objFolder in colFolders
[Link] [Link]
Next
Search for Folders Using Wildcards
Returns a list of all the folders whose path begins with C:\S.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colFolders = [Link] _
("Select * from Win32_Directory where Name Like '%c:\\S%'")
For Each objFolder in colFolders
[Link] "Name: " & [Link]
Next
Search for Specific Published Folders in Active Directory
Searches Active Directory for any shared folders that have the keyword "finance."
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("[Link]")
Set objCommand = CreateObject("[Link]")
[Link] = "ADsDSOObject"
[Link] "Active Directory Provider"
Set [Link] = objConnection
[Link] = "Select Name, unCName, ManagedBy from "
& "'LDAP://DC=Reskit,DC=com'" _
& " where objectClass='volume' and Keywords = 'finance*'"
[Link]("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = [Link]
[Link]
Do Until [Link]
[Link] "Share Name: " & [Link]("Name").Value
[Link] "UNC Name: " & [Link]("uNCName").Value
[Link] "Managed By: " & [Link]("ManagedBy").Value
[Link]
Loop
Uncompress a Folder
Uncompresses the folder C:\Scripts.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colFolders = [Link] _
("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = [Link]
Next
Verify that a Folder Exists
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("[Link]")
If [Link]("C:\FSO") Then
Set objFolder = [Link]("C:\FSO")
Else
[Link] "Folder does not exist."
End If