Saturday, February 12, 2011

Qtp - Folders and files management


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("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts")
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
objPath = Replace(objPath, "\", "\\")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = '" & objPath & "'")
For Each objFile in colFiles
Wscript.Echo "Readable: " & objFile.Readable
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("Shell.Application")
set objFolder = objShell.NameSpace(ParentFolder)
objFolder.NewFolder "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("Shell.Application")
Set objFolder = objShell.NameSpace(ParentFolder)
objFolder.CopyHere "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 = objWMIService.ExecQuery( _
"Select * from Win32_Directory where Name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Copy("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 = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create _
("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 = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Compress
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("Scripting.FileSystemObject")
objFSO.CopyFolder "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("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("C:\FSO")
Delete a Folder

Deletes 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
errResults = objFolder.Delete
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("Scripting.FileSystemObject")
objFSO.DeleteFolder("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 = objWMIService.ExecQuery _
("Select * from Win32_Share Where Name = 'FinanceShare'")
For Each objShare in colShares
objShare.Delete
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")
objContainer.DeleteObject (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("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\Scripts")
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
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 = objWMIService.ExecQuery("Select * from Win32_Directory")
For Each objFolder in colFolders
Wscript.Echo objFolder.Name
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("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
If objFolder.Attributes AND 2 Then
Wscript.Echo "Hidden folder."
End If
If objFolder.Attributes AND 4 Then
Wscript.Echo "System folder."
End If
If objFolder.Attributes AND 16 Then
Wscript.Echo "Folder."
End If
If objFolder.Attributes AND 32 Then
Wscript.Echo "Archive bit set."
End If
If objFolder.Attributes AND 2048 Then
Wscript.Echo "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("WbemScripting.SWbemDateTime")
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
dtmTargetDate.SetVarDate "3/1/2004", LOCAL_TIME
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory Where " _
& "CreationDate > '" & dtmTargetDate & "'")
For each objFolder in colFolders
dtmConvertedDate.Value = objFolder.CreationDate
Wscript.Echo objFolder.Name & VbTab & _
dtmConvertedDate.GetVarDate(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 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='c:\scripts'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder in colSubfolders
Wscript.Echo objFolder.Name
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("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Scripts")
Wscript.Echo "Date created: " & objFolder.DateCreated
Wscript.Echo "Date last accessed: " & objFolder.DateLastAccessed
Wscript.Echo "Date last modified: " & objFolder.DateLastModified
Wscript.Echo "Drive: " & objFolder.Drive
Wscript.Echo "Is root folder: " & objFolder.IsRootFolder
Wscript.Echo "Name: " & objFolder.Name
Wscript.Echo "Parent folder: " & objFolder.ParentFolder
Wscript.Echo "Path: " & objFolder.Path
Wscript.Echo "Short name: " & objFolder.ShortName
Wscript.Echo "Short path: " & objFolder.ShortPath
Wscript.Echo "Size: " & objFolder.Size
Wscript.Echo "Type: " & objFolder.Type
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
Wscript.Echo "Archive: " & objFolder.Archive
Wscript.Echo "Caption: " & objFolder.Caption
Wscript.Echo "Compressed: " & objFolder.Compressed
Wscript.Echo "Compression method: " & objFolder.CompressionMethod
Wscript.Echo "Creation date: " & objFolder.CreationDate
Wscript.Echo "Encrypted: " & objFolder.Encrypted
Wscript.Echo "Encryption method: " & objFolder.EncryptionMethod
Wscript.Echo "Hidden: " & objFolder.Hidden
Wscript.Echo "In use count: " & objFolder.InUseCount
Wscript.Echo "Last accessed: " & objFolder.LastAccessed
Wscript.Echo "Last modified: " & objFolder.LastModified
Wscript.Echo "Name: " & objFolder.Name
Wscript.Echo "Path: " & objFolder.Path
Wscript.Echo "Readable: " & objFolder.Readable
Wscript.Echo "System: " & objFolder.System
Wscript.Echo "Writeable: " & objFolder.Writeable
Next
List Network Shares

Lists all the shared folders on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
For each objShare in colShares
Wscript.Echo "Allow Maximum: " & objShare.AllowMaximum
Wscript.Echo "Caption: " & objShare.Caption
Wscript.Echo "Maximum Allowed: " & objShare.MaximumAllowed
Wscript.Echo "Name: " & objShare.Name
Wscript.Echo "Path: " & objShare.Path
Wscript.Echo "Type: " & objShare.Type
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("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
Wscript.Echo objSubfolder.Name, objSubfolder.Size
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("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, unCName, ManagedBy from " _
& "'LDAP://DC=Fabrikam,DC=com' where objectClass='volume'"
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
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
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("Shell.Application")
Set objFolder = objShell.NameSpace(RECYCLE_BIN)
Set objFolderItem = objFolder.Self
Set colVerbs = objFolderItem.Verbs
For i = 0 to colVerbs.Count - 1
Wscript.Echo colVerbs.Item(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 = objWMIService.ExecQuery _
("Select * from Win32_Directory Where Hidden = True")
For Each objFile in colFiles
Wscript.Echo objFile.Name
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 = objWMIService.ExecQuery("Select * From Win32_Share")
For Each objShare in colShares
Set colAssociations = objWMIService.ExecQuery _
("Associators of {Win32_Share.Name='" & objShare.Name & "'} " _
& " Where AssocClass=Win32_ShareToDirectory")
For Each objFolder in colAssociations
Wscript.Echo objShare.Name & vbTab & objFolder.Name
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("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
If objFolder.Attributes = objFolder.Attributes AND 2 Then
objFolder.Attributes = objFolder.Attributes 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("Shell.Application")
Set objFolder = objShell.NameSpace(TargetFolder)
objFolder.MoveHere "C:\Scripts", FOF_CREATEPROGRESSDLG
Move a Folder Using WMI

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 errResults = objFolder.Rename("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 = objWMIService.ExecQuery _
("Select * from Win32_Share Where Name = 'FinanceShare'")
For Each objShare in colShares
errReturn = objShare.SetShareInfo(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 = objWMIService.ExecQuery _
("Associators of {Win32_Share.Name='Scripts'} Where " _
& "AssocClass=Win32_ShareToDirectory")
For Each objFolder in colShares
Wscript.Echo objFolder.Name
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("Scripting.FileSystemObject")
objFSO.MoveFolder "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 = objComputer.Create("volume", "CN=FinanceShare")
objShare.Put "uNCName", "\\atl-dc-02\FinanceShare"
objShare.Put "Description", "Public share for users in the Finance group."
objShare.Put "Keywords", Array("finance", "fiscal", "monetary")
objShare.SetInfo
Rename a Folder

Renames the folder C:\Scripts to C:\Repository.
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
errResults = objFolder.Rename("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("Scripting.FileSystemObject")
objFSO.MoveFolder "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 = objWMIService.ExecQuery _
("Select * from Win32_Directory Where CreationDate > '" & _
dtmtargetDate & "'")
For Each objFolder in colFolders
Wscript.Echo objFolder.Name
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 = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name Like '%c:\\S%'")
For Each objFolder in colFolders
Wscript.Echo "Name: " & objFolder.Name
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("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, unCName, ManagedBy from "
& "'LDAP://DC=Reskit,DC=com'" _
& " where objectClass='volume' and Keywords = 'finance*'"
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
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

Uncompresses 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
errResults = objFolder.Uncompress
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("Scripting.FileSystemObject")
If objFSO.FolderExists("C:\FSO") Then
Set objFolder = objFSO.GetFolder("C:\FSO")
Else
Wscript.Echo "Folder does not exist."
End If
Physical and Logical Disks - Sample Code


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.


Add a Volume Mount Point

Adds a new volume mount point for the folder W:\Scripts. Note that in the WQL query, you must use two slashes rather than one, and you must also include two slashes at the end of the folder path. Thus the folder X:\Scripts\WMI would be listed as X:\\Scripts\\WMI\\.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_Volume Where Name = 'D:\\'")
For Each objItem in colItems
objItem.AddMountPoint("W:\\Scripts\\")
Next
Associate Disk Partitions with Physical Disk Drives

Returns the DeviceID of all the physical disk drives installed on a computer, and indicates the partitions that have been created on those disks.
strComputer = "."
Set wmiServices = GetObject _
("winmgmts:{impersonationLevel=Impersonate}!//" & strComputer)
Set wmiDiskDrives = wmiServices.ExecQuery _
("SELECT Caption, DeviceID FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
WScript.Echo wmiDiskDrive.Caption & " (" & wmiDiskDrive.DeviceID & ")"
strEscapedDeviceID = Replace _
(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strEscapedDeviceID & """} WHERE AssocClass = " & _
"Win32_DiskDriveToDiskPartition")
For Each wmiDiskPartition In wmiDiskPartitions
WScript.Echo vbTab & wmiDiskPartition.DeviceID
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
wmiDiskPartition.DeviceID & """} WHERE AssocClass = " & _
"Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
WScript.Echo vbTab & vbTab & wmiLogicalDisk.DeviceID
Next
Next
Next
Analyze Volume Defragmentation

Analyzes the defragmentation status of all the volumes on a computer. This is equivalent to running defrag.exe with the command-line options -a (analyze) and -v (verbose).
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume")
For Each objVolume in colVolumes
errResult = objVolume.DefragAnalysis(blnRecommended, objReport)
If errResult = 0 then
Wscript.Echo "Average file size: " & objReport.AverageFileSize
Wscript.Echo "Average fragments per file: " & _
objReport.AverageFragmentsPerFile
Wscript.Echo "Cluster size: " & objReport.ClusterSize
Wscript.Echo "Excess folder fragments: " & _
objReport.ExcessFolderFragments
Wscript.Echo "File percent fragmentation: " & _
objReport.FilePercentFragmentation
Wscript.Echo "Fragmented folders: " & objReport.FragmentedFolders
Wscript.Echo "Free soace: " & objReport.FreeSpace
Wscript.Echo "Free space percent: " & objReport.FreeSpacePercent
Wscript.Echo "Free space percent fragmentation: " & _
objReport.FreeSpacePercentFragmentation
Wscript.Echo "MFT percent in use: " & objReport.MFTPercentInUse
Wscript.Echo "MFT record count: " & objReport.MFTRecordCount
Wscript.Echo "Page file size: " & objReport.PageFileSize
Wscript.Echo "Total excess fragments: " & _
objReport.TotalExcessFragments
Wscript.Echo "Total files: " & objReport.TotalFiles
Wscript.Echo "Total folders: " & objReport.TotalFolders
Wscript.Echo "Total fragmented files: " & _
objReport.TotalFragmentedFiles
Wscript.Echo "Total MFT fragments: " & objReport.TotalMFTFragments
Wscript.Echo "Total MFT size: " & objReport.TotalMFTSize
Wscript.Echo "Total page file fragments: " & _
objReport.TotalPageFileFragments
Wscript.Echo "Total percent fragmentation: " & _
objReport.TotalPercentFragmentation
Wscript.Echo "Used space: " & objReport.UsedSpace
Wscript.Echo "Volume name: " & objReport.VolumeName
Wscript.Echo "Volume size: " & objReport.VolumeSize
If blnRecommended = True Then
Wscript.Echo "This volume should be defragged."
Else
Wscript.Echo "This volume does not need to be defragged."
End If
Wscript.Echo
End If
Next
Bind to a Specific Disk Drive

Demonstration script that uses the FileSystemObject to return available disk space on a specific disk drive. Script must be run on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDrive = objFSO.GetDrive("C:")
Wscript.Echo "Available space: " & objDrive.AvailableSpace
Change the Drive Letter of a Volume

Changes the drive letter of volume D to Q. If you modify this script to change the drive letter of a volume other than D, note that the volume name in the WQL query must include both the colon (:) and two slashes (\\). Thus drive C would look like this: C:\\. When specifying the new drive letter, however, you only have to include the colon (in the sample script, Q:).
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume Where Name = 'D:\\'")
For Each objVolume in colVolumes
objVolume.DriveLetter = "Q:"
objVolume.Put_
Next
Dismount a Volume

Dismounts volume E from the file system. If you modify this script to dismount a different volume (such as X), note that your WQL query must specify the drive letter followed by a colon and then followed by two slashes. Thus volume X would be listed as X:\\. The two parameters: 1) force the volume to be dismounted, even if users are currently connected to it; and, 2) place the volume in a no-automount, offline state. This script can be modified by setting either (or both) of these parameters to False.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_Volume Where Name = 'E:\\'")
For Each objItem in colItems
objItem.Dismount(True, True)
Next
Defragment a Volume

Defragments volume D on a computer. If you modify this script to defragment a different volume (such as X), note that your WQL query must specify the drive letter followed by a colon and then followed by two slashes. Thus volume X would be listed as X:\\.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume Where Name = 'D:\\'")
For Each objVolume in colVolumes
errResult = objVolume.Defrag()
Next
Format a Volume

Formats drive D using the NTFS file system. Drives could also be formatted using the FAT or FAT32 file systems. Note that this method cannot be used to format floppy drives. If you modify this script to format a different volume (such as drive X), also note that your WQL query must specify the drive letter followed by a colon and then followed by two slashes. Thus drive X would be listed as X:\\.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume Where Name = 'D:\\'")
For Each objVolume in colVolumes
errResult = objVolume.Format("NTFS")
Next
List All Disk Drives

Demonstration script that uses the FileSystemObject to return a list of all the disk drives installed on a computer. Script must be run on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
Wscript.Echo "Drive letter: " & objDrive.DriveLetter
Next
List Available Disk Space

Returns the amount of free space for each hard disk installed on a computer.
Const HARD_DISK = 3
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
For Each objDisk in colDisks
Wscript.Echo "DeviceID: "& vbTab & objDisk.DeviceID
Wscript.Echo "Free Disk Space: "& vbTab & objDisk.FreeSpace
Next
List CD-ROM Properties

Returns information about all the CD-ROM drives installed on a computer.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
For Each objItem in colItems
Wscript.Echo "Availability: " & objItem.Availability
For Each strCapability in objItem.Capabilities
Wscript.Echo "Capability: "& strCapability
Next
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Device ID: " & objItem.DeviceID
Wscript.Echo "Drive: " & objItem.Drive
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "Media Loaded: " & objItem.MediaLoaded
Wscript.Echo "Media Type: " & objItem.MediaType
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
Wscript.Echo "SCSI Bus: " & objItem.SCSIBus
Wscript.Echo "SCSI Logical Unit: " & objItem.SCSILogicalUnit
Wscript.Echo "SCSI Port: " & objItem.SCSIPort
Wscript.Echo "SCSI Target ID: " & objItem.SCSITargetId
Next
List Disk Drive Properties Using FSO

Demonstration script that uses the FileSystemObject to return the properties of all the disk drives installed on a computer. Script must be run on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
Wscript.Echo "Available space: " & objDrive.AvailableSpace
Wscript.Echo "Drive letter: " & objDrive.DriveLetter
Wscript.Echo "Drive type: " & objDrive.DriveType
Wscript.Echo "File system: " & objDrive.FileSystem
Wscript.Echo "Free space: " & objDrive.FreeSpace
Wscript.Echo "Is ready: " & objDrive.IsReady
Wscript.Echo "Path: " & objDrive.Path
Wscript.Echo "Root folder: " & objDrive.RootFolder
Wscript.Echo "Serial number: " & objDrive.SerialNumber
Wscript.Echo "Share name: " & objDrive.ShareName
Wscript.Echo "Total size: " & objDrive.TotalSize
Wscript.Echo "Volume name: " & objDrive.VolumeName
Next
List Disk Partition Properties

Lists the properties of all the disk partitions on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskPartitions = objWMIService.ExecQuery _
("Select * from Win32_DiskPartition")
For each objPartition in colDiskPartitions
Wscript.Echo "Block Size: " & objPartition.BlockSize
Wscript.Echo "Bootable: " & objPartition.Bootable
Wscript.Echo "Boot Partition: " & objPartition.BootPartition
Wscript.Echo "Description: " & objPartition.Description
Wscript.Echo "Device ID: " & objPartition.DeviceID
Wscript.Echo "Disk Index: " & objPartition.DiskIndex
Wscript.Echo "Index: " & objPartition.Index
Wscript.Echo "Name: " & objPartition.Name
Wscript.Echo "Number Of Blocks: " & _
objPartition.NumberOfBlocks
Wscript.Echo "Primary Partition: " & _
objPartition.PrimaryPartition
Wscript.Echo "Size: " & objPartition.Size
Wscript.Echo "Starting Offset: " & _
objPartition.StartingOffset
Wscript.Echo "Type: " & objPartition.Type
Next
List Disk Space by User on the Local Computer

Uses disk quotas to return information about disk space usage per-user for drive C on the local computer.
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
For Each objUser in colDiskQuotas
Wscript.Echo "Logon name: " & objUser.LogonName
Wscript.Echo "Quota used: " & objUser.QuotaUsed
Next
List Drive Types

Identifies the drive type (floppy drive, hard drive, CD-ROM, etc.) for each physical drive installed on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
Wscript.Echo "DeviceID: "& objDisk.DeviceID
Select Case objDisk.DriveType
Case 1
Wscript.Echo "No root directory. Drive type could not be " _
& "determined."
Case 2
Wscript.Echo "DriveType: "& "Removable drive."
Case 3
Wscript.Echo "DriveType: "& "Local hard disk."
Case 4
Wscript.Echo "DriveType: "& "Network disk."
Case 5
Wscript.Echo "DriveType: "& "Compact disk."
Case 6
Wscript.Echo "DriveType: "& "RAM disk."
Case Else
Wscript.Echo "Drive type could not be determined."
End Select
Next
List Floppy Drive Information

Returns information about all the floppy disk drives installed on a computer.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_FloppyDrive")
For Each objItem in colItems
Wscript.Echo "Availability: " & objItem.Availability
Wscript.Echo "Configuration Manager Error Code: " & _
objItem.ConfigManagerErrorCode
Wscript.Echo "Configuration Manager User Configuration: " & _
objItem.ConfigManagerUserConfig
Wscript.Echo "Device ID: " & objItem.DeviceID
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
Wscript.Echo
Next
List Logical Disk Drive Properties

Lists the properties for all the logical disk drives on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
For each objDisk in colDisks
Wscript.Echo "Compressed: " & objDisk.Compressed
Wscript.Echo "Description: " & objDisk.Description
Wscript.Echo "DeviceID: " & objDisk.DeviceID
Wscript.Echo "DriveType: " & objDisk.DriveType
Wscript.Echo "FileSystem: " & objDisk.FileSystem
Wscript.Echo "FreeSpace: " & objDisk.FreeSpace
Wscript.Echo "MediaType: " & objDisk.MediaType
Wscript.Echo "Name: " & objDisk.Name
Wscript.Echo "QuotasDisabled: " & objDisk.QuotasDisabled
Wscript.Echo "QuotasIncomplete: " & objDisk.QuotasIncomplete
Wscript.Echo "QuotasRebuilding: " & objDisk.QuotasRebuilding
Wscript.Echo "Size: " & objDisk.Size
Wscript.Echo "SupportsDiskQuotas: " & _
objDisk.SupportsDiskQuotas
Wscript.Echo "SupportsFileBasedCompression: " & _
objDisk.SupportsFileBasedCompression
Wscript.Echo "SystemName: " & objDisk.SystemName
Wscript.Echo "VolumeDirty: " & objDisk.VolumeDirty
Wscript.Echo "VolumeName: " & objDisk.VolumeName
Wscript.Echo "VolumeSerialNumber: " & _
objDisk.VolumeSerialNumber
Next
List Mapped Network Drives

Retrieves information about mapped network drives. The information returned is similar to that available through the Win32_LogicalDisk class, which retrieves information about the logical disks found on a computer.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_MappedLogicalDisk")
For Each objItem in colItems
Wscript.Echo "Compressed: " & objItem.Compressed
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Device ID: " & objItem.DeviceID
Wscript.Echo "File System: " & objItem.FileSystem
Wscript.Echo "Free Space: " & objItem.FreeSpace
Wscript.Echo "Maximum Component Length: " & objItem.MaximumComponentLength
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Provider Name: " & objItem.ProviderName
Wscript.Echo "Session ID: " & objItem.SessionID
Wscript.Echo "Size: " & objItem.Size
Wscript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas
Wscript.Echo "Supports File-Based Compression: " & _
objItem.SupportsFileBasedCompression
Wscript.Echo "Volume Name: " & objItem.VolumeName
Wscript.Echo "Volume Serial Number: " & objItem.VolumeSerialNumber
Wscript.Echo
Next
List Physical Disk Properties

Retrieves the properties for all the physical disk drives installed on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
("Select * from Win32_DiskDrive")
For each objDiskDrive in colDiskDrives
Wscript.Echo "Bytes Per Sector: " & vbTab & _
objDiskDrive.BytesPerSector
For i = Lbound(objDiskDrive.Capabilities) to _
Ubound(objDiskDrive.Capabilities)
Wscript.Echo "Capabilities: " & vbTab & _
objDiskDrive.Capabilities(i)
Next
Wscript.Echo "Caption: " & vbTab & objDiskDrive.Caption
Wscript.Echo "Device ID: " & vbTab & objDiskDrive.DeviceID
Wscript.Echo "Index: " & vbTab & objDiskDrive.Index
Wscript.Echo "Interface Type: " & vbTab & objDiskDrive.InterfaceType
Wscript.Echo "Manufacturer: " & vbTab & objDiskDrive.Manufacturer
Wscript.Echo "Media Loaded: " & vbTab & objDiskDrive.MediaLoaded
Wscript.Echo "Media Type: " & vbTab & objDiskDrive.MediaType
Wscript.Echo "Model: " & vbTab & objDiskDrive.Model
Wscript.Echo "Name: " & vbTab & objDiskDrive.Name
Wscript.Echo "Partitions: " & vbTab & objDiskDrive.Partitions
Wscript.Echo "PNP DeviceID: " & vbTab & objDiskDrive.PNPDeviceID
Wscript.Echo "SCSI Bus: " & vbTab & objDiskDrive.SCSIBus
Wscript.Echo "SCSI Logical Unit: " & vbTab & _
objDiskDrive.SCSILogicalUnit
Wscript.Echo "SCSI Port: " & vbTab & objDiskDrive.SCSIPort
Wscript.Echo "SCSI TargetId: " & vbTab & objDiskDrive.SCSITargetId
Wscript.Echo "Sectors Per Track: " & vbTab & _
objDiskDrive.SectorsPerTrack
Wscript.Echo "Signature: " & vbTab & objDiskDrive.Signature
Wscript.Echo "Size: " & vbTab & objDiskDrive.Size
Wscript.Echo "Status: " & vbTab & objDiskDrive.Status
Wscript.Echo "Total Cylinders: " & vbTab & _
objDiskDrive.TotalCylinders
Wscript.Echo "Total Heads: " & vbTab & objDiskDrive.TotalHeads
Wscript.Echo "Total Sectors: " & vbTab & objDiskDrive.TotalSectors
Wscript.Echo "Total Tracks: " & vbTab & objDiskDrive.TotalTracks
Wscript.Echo "Tracks Per Cylinder: " & vbTab & _
objDiskDrive.TracksPerCylinder
Next
List Volume Mount Points

Enumerates all the volume mount points on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("SELECT * FROM Win32_MountPoint")
For Each objItem In colItems
WScript.Echo "Directory: " & objItem.Directory
WScript.Echo "Volume: " & objItem.Volume
WScript.Echo
Next
List Volume Properties

Retrieves the properties of all the volumes installed on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Volume")
For Each objItem In colItems
WScript.Echo "Automount: " & objItem.Automount
WScript.Echo "Block Size: " & objItem.BlockSize
WScript.Echo "Capacity: " & objItem.Capacity
WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "Compressed: " & objItem.Compressed
WScript.Echo "Device ID: " & objItem.DeviceID
WScript.Echo "Dirty Bit Set: " & objItem.DirtyBitSet
WScript.Echo "Drive Letter: " & objItem.DriveLetter
WScript.Echo "Drive Type: " & objItem.DriveType
WScript.Echo "File System: " & objItem.FileSystem
WScript.Echo "Free Space: " & objItem.FreeSpace
WScript.Echo "Indexing Enabled: " & objItem.IndexingEnabled
WScript.Echo "Label: " & objItem.Label
WScript.Echo "Maximum File Name Length: " & objItem.MaximumFileNameLength
WScript.Echo "Name: " & objItem.Name
WScript.Echo "Quotas Enabled: " & objItem.QuotasEnabled
WScript.Echo "Quotas Incomplete: " & objItem.QuotasIncomplete
WScript.Echo "Quotas Rebuilding: " & objItem.QuotasRebuilding
WScript.Echo "Serial Number: " & objItem.SerialNumber
WScript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas
WScript.Echo "Supports File-Based Compression: " & _
objItem.SupportsFileBasedCompression
WScript.Echo
Next
Modify the AutoChk Timeout Value

Sets the auto-delay time for Autochk.exe to 30 seconds.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colAutoChkSettings = objWMIService.ExecQuery _
("Select * from Win32_AutochkSetting")
For Each objAutoChkSetting in colAutoChkSettings
objAutoChkSetting.UserInputDelay = 30
objAutoChkSetting.Put_
Next
Mount a Volume

Mounts volume Z to the file system. If you modify this script to mount a different volume (such as X), note that the volume name in your WQL query must include the drive letter followed by a colon and then followed by two slashes. Thus drive X would be listed as X:\\.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_Volume Where Name = 'Z:\\'")
For Each objItem in colItems
objItem.Mount()
Next
Prevent AutoChk From Running

Ensures that Autochk.exe will not run against drive C the next time the computer reboots, even if the "dirty bit" has been set on drive C.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDisk = objWMIService.Get("Win32_LogicalDisk")
errReturn = objDisk.ExcludeFromAutoChk(Array("C:"))
Run ChkDsk

Runs ChkDsk.exe against drive D on a computer.
Const FIX_ERRORS = True
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='D:'")
errReturn = objDisk.ChkDsk(FIX_ERRORS)
Rename a Volume

Changes the volume label for drive C to "Finance Volume."
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDrives = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk where DeviceID = 'C:'")
For Each objDrive in colDrives
objDrive.VolumeName = "Finance Volume"
objDrive.Put_
Next
Schedule AutoChk

Schedules Autochk.exe to run against drive C the next time the computer reboots.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDisk = objWMIService.Get("Win32_LogicalDisk")
errReturn = objDisk.ScheduleAutoChk(Array("C:"))
Verify that All Drives are Ready

Demonstration script that uses the FileSystemObject to ensure that all drives are ready (i.e., media is inserted) before echoing the drive letter and available disk space. Script must be run on the local computer.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
If objDrive.IsReady = True Then
Wscript.Echo "Drive letter: " & objDrive.DriveLetter
Wscript.Echo "Free space: " & objDrive.FreeSpace
Else
Wscript.Echo "Drive letter: " & objDrive.DriveLetter
End If
Next
Verify ChkDsk Volume Status

Indicates whether or not any hard drives on a computer have the "dirty bit" set, and should have Chkdsk.exe run.
Const LOCAL_HARD_DISK = 3
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = LOCAL_HARD_DISK ")
For Each objDisk in colDisks
Wscript.Echo "Device ID: "& vbTab & objDisk.DeviceID
Wscript.Echo "Drive Type: "& vbTab & objDisk.VolumeDirty
Next
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
For Each objUser in colDiskQuotas
Wscript.Echo "Logon name: " & objUser.LogonName
Wscript.Echo "Quota limit: " & objUser.QuotaLimit
Wscript.Echo "Quota threshold: " & objUser.QuotaThreshold
Wscript.Echo "Quota used: " & objUser.QuotaUsed
Next
File Management using VBScript


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.


List the File System Type

Identifies the file system in use for each logical disk on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
Wscript.Echo "Device ID: "& vbTab & objDisk.DeviceID
Wscript.Echo "File System: "& vbTab & objDisk.FileSystem
Next
List NTFS Properties

Retrieves NTFS file system settings from the registry.
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
strRegKey = objShell.RegRead _
("HKLM\System\CurrentControlSet\Control\FileSystem\" _
& "NtfsDisable8dot3NameCreation")
If IsNull(strRegKey) Then
Wscript.Echo "No value set for disabling 8.3 file name creation."
ElseIf strRegKey = 1 Then
WScript.Echo "No 8.3 file names will be created for new files."
ElseIf strRegKey = 0 Then
Wscript.Echo "8.3 file names will be created for new files."
End If
strRegKey = Null
strRegKey = objShell.RegRead _
("HKLM\System\CurrentControlSet\Control\FileSystem\" _
& "NtfsAllowExtendedCharacterIn8Dot3Name")
If IsNull(strRegKey) Then
Wscript.Echo "No value set for allowing extended characters in " _
& " 8.3 file names."
ElseIf strRegKey = 1 Then
WScript.Echo "Extended characters are permitted in 8.3 file names."
ElseIf strRegKey = 0 Then
Wscript.Echo "Extended characters not permitted in 8.3 file names."
End If
strRegKey = Null
strRegKey = objShell.RegRead _
("HKLM\System\CurrentControlSet\Control\FileSystem\" _
& "NtfsMftZoneReservation")
If IsNull(strRegKey) Then
Wscript.Echo "No value set for reserving the MFT zone."
ElseIf strRegKey = 1 Then
WScript.Echo _
"One-eighth of the disk has been reserved for the MFT zone."
ElseIf strRegKey = 2 Then
Wscript.Echo "One-fourth of the disk reserved for the MFT zone."
ElseIf strRegKey = 3 Then
Wscript.Echo "Three-eighths of the disk reserved for the MFT zone."
ElseIf strRegKey = 4 Then
Wscript.Echo "One half of the disk reserved for the MFT zone."
End If
strRegKey = Null
strRegKey = objShell.RegRead _
("HKLM\System\CurrentControlSet\Control\FileSystem\" _
& "NtfsDisableLastAccessUpdate")
If IsNull(strRegKey) Then
Wscript.Echo "No value set for disabling the last access update " _
& "for files and folder."
ElseIf strRegKey = 1 Then
WScript.Echo "The last access timestamp will not be updated on files " _
& "and folders."
ElseIf strRegKey = 0 Then
Wscript.Echo "The last access timestamp updated on files and " _
& "folders."
End If
strRegKey = Null
strRegKey = objShell.RegRead _
("HKLM\System\CurrentControlSet\Control\FileSystem\Win31FileSystem")
If IsNull(strRegKey) Then
Wscript.Echo "No value set for using long file names and " _
& "timestamps."
ElseIf strRegKey = 1 Then
WScript.Echo "Long file names and extended timestamps are used."
ElseIf strRegKey = 0 Then
Wscript.Echo "Long file names and extended timestamps are not used."
End If
Modify File System Properties

Disables the updating of the last access time for files and folders.
Set objShell = WScript.CreateObject("WScript.Shell")
strRegKey = objShell.RegWrite _
("HKLM\System\CurrentControlSet\Control\FileSystem\" _
& "NtfsDisableLastAccessUpdate" , 1, "REG_DWORD")
Monitor NTFS File Cache Performance

Uses cooked performance counters to monitor the performance of the NTFS file cache.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colCache = objRefresher.AddEnum _
(objWMIService, "win32_PerfFormattedData_PerfOS_Cache").ObjectSet
objRefresher.Refresh
For i = 1 to 100
For Each objCache in colCache
Wscript.Echo "Async Copy Reads Per Second" & _
objCache.AsyncCopyReadsPerSec
Wscript.Echo "Async Data Maps Per Second" & _
objCache.AsyncDataMapsPerSec
Wscript.Echo "AsyncFastReadsPerSecond" & _
objCache.AsyncFastReadsPerSec
Wscript.Echo "Async MDL Reads Per Second" & _
objCache.AsyncMDLReadsPerSec
Wscript.Echo "Async Pin Reads Per Second" & _
objCache.AsyncPinReadsPerSec
Wscript.Echo "Caption" & vbTab & objCache.Caption
Wscript.Echo "Copy Read Hits Percent " & _
objCache.CopyReadHitsPercent
Wscript.Echo "Copy Reads Per Second" & _
objCache.CopyReadsPerSec
Wscript.Echo "Data Flushes Per Second" & _
objCache.DataFlushesPerSec
Wscript.Echo "Data Flush Pages Per Second" & _
objCache.DataFlushPagesPerSec
Wscript.Echo "Data Map Hits Percent " & _
objCache.DataMapHitsPercent
Wscript.Echo "Data Map Pins Per Second" & _
objCache.DataMapPinsPerSec
Wscript.Echo "Data Maps Per Second" & _
objCache.DataMapsPerSec
Wscript.Echo "Description" & objCache.Description
Wscript.Echo "Fast Read Not Possibles Per Second" & _
objCache.FastReadNotPossiblesPerSec
Wscript.Echo "Fast Read Resource Misses Per Second" & _
objCache.FastReadResourceMissesPerSec
Wscript.Echo "Fast Reads Per Second" & _
objCache.FastReadsPerSec
Wscript.Echo "Lazy Write Flushes Per Second" & _
objCache.LazyWriteFlushesPerSec
Wscript.Echo "Lazy Write Pages Per Second" & _
objCache.LazyWritePagesPerSec
Wscript.Echo "MDL Read Hits Percent " & _
objCache.MDLReadHitsPercent
Wscript.Echo "MDL Reads Per Second" & _
objCache.MDLReadsPerSec
Wscript.Echo "Name" & vbTab & objCache.Name
Wscript.Echo "Pin Read Hits Percent" & _
objCache.PinReadHitsPercent
Wscript.Echo "Pin Reads Per Second" & _
objCache.PinReadsPerSec
Wscript.Echo "Read Aheads Per Second" & _
objCache.ReadAheadsPerSec
Wscript.Echo "Sync Copy Reads Per Second" & _
objCache.SyncCopyReadsPerSec
Wscript.Echo "Sync Data Maps Per Second" & _
objCache.SyncDataMapsPerSec
Wscript.Echo "Sync Fast Reads Per Second" & _
objCache.SyncFastReadsPerSec
Wscript.Echo "Sync MDL Reads Per Second" & _
objCache.SyncMDLReadsPerSec
Wscript.Echo "Sync Pin Reads Per Second" & _
objCache.SyncPinReadsPerSec
Wscript.Sleep 2000
objRefresher.Refresh
Next
Next