Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Volume Number from FilesystemObject 1

Status
Not open for further replies.

JB3K

Technical User
Oct 10, 2002
4
GB
Does anyone know a way to return the Volume Number? I see there are DriveLetter and VolumeName options, but I really need to know the Volume Number before commiting a drive letter change in the script. Any ideas?

Many thanks
JB3K
 
What do you call "Volume number" ? Water is not bad as soon as it stays out human body ;-)
 
well specifically, if I use the resource kit utility 'diskpart' which is command line control of Disk Manager, then a volume has:
volume number
drive letter
volume name
and more

the volume number is what i need to reference.
 
Try these to see if they give you what you want.

I can not find a way of doing it with FileSystemObject but this is with WMI

The first one may have the info in Device Id, on my machine it returns Disk #0 Partition #0

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskPartition",,48)
For Each objItem in colItems
Wscript.Echo "Access: " & objItem.Access
Wscript.Echo "Availability: " & objItem.Availability
Wscript.Echo "BlockSize: " & objItem.BlockSize
Wscript.Echo "Bootable: " & objItem.Bootable
Wscript.Echo "BootPartition: " & objItem.BootPartition
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode
Wscript.Echo "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
Wscript.Echo "CreationClassName: " & objItem.CreationClassName
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "DiskIndex: " & objItem.DiskIndex
Wscript.Echo "ErrorCleared: " & objItem.ErrorCleared
Wscript.Echo "ErrorDescription: " & objItem.ErrorDescription
Wscript.Echo "ErrorMethodology: " & objItem.ErrorMethodology
Wscript.Echo "HiddenSectors: " & objItem.HiddenSectors
Wscript.Echo "Index: " & objItem.Index
Wscript.Echo "InstallDate: " & objItem.InstallDate
Wscript.Echo "LastErrorCode: " & objItem.LastErrorCode
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "NumberOfBlocks: " & objItem.NumberOfBlocks
Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
Wscript.Echo "PowerManagementCapabilities: " & objItem.PowerManagementCapabilities
Wscript.Echo "PowerManagementSupported: " & objItem.PowerManagementSupported
Wscript.Echo "PrimaryPartition: " & objItem.PrimaryPartition
Wscript.Echo "Purpose: " & objItem.Purpose
Wscript.Echo "RewritePartition: " & objItem.RewritePartition
Wscript.Echo "Size: " & objItem.Size
Wscript.Echo "StartingOffset: " & objItem.StartingOffset
Wscript.Echo "Status: " & objItem.Status
Wscript.Echo "StatusInfo: " & objItem.StatusInfo
Wscript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName
Wscript.Echo "SystemName: " & objItem.SystemName
Wscript.Echo "Type: " & objItem.Type
Next

This one returns the Volume serial number, although I do not think this is what you are after but you may find something useful

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each objItem in colItems
Wscript.Echo "Access: " & objItem.Access
Wscript.Echo "Availability: " & objItem.Availability
Wscript.Echo "BlockSize: " & objItem.BlockSize
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Compressed: " & objItem.Compressed
Wscript.Echo "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode
Wscript.Echo "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
Wscript.Echo "CreationClassName: " & objItem.CreationClassName
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "DriveType: " & objItem.DriveType
Wscript.Echo "ErrorCleared: " & objItem.ErrorCleared
Wscript.Echo "ErrorDescription: " & objItem.ErrorDescription
Wscript.Echo "ErrorMethodology: " & objItem.ErrorMethodology
Wscript.Echo "FileSystem: " & objItem.FileSystem
Wscript.Echo "FreeSpace: " & objItem.FreeSpace
Wscript.Echo "InstallDate: " & objItem.InstallDate
Wscript.Echo "LastErrorCode: " & objItem.LastErrorCode
Wscript.Echo "MaximumComponentLength: " & objItem.MaximumComponentLength
Wscript.Echo "MediaType: " & objItem.MediaType
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "NumberOfBlocks: " & objItem.NumberOfBlocks
Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
Wscript.Echo "PowerManagementCapabilities: " & objItem.PowerManagementCapabilities
Wscript.Echo "PowerManagementSupported: " & objItem.PowerManagementSupported
Wscript.Echo "ProviderName: " & objItem.ProviderName
Wscript.Echo "Purpose: " & objItem.Purpose
Wscript.Echo "Size: " & objItem.Size
Wscript.Echo "Status: " & objItem.Status
Wscript.Echo "StatusInfo: " & objItem.StatusInfo
Wscript.Echo "SupportsFileBasedCompression: " & objItem.SupportsFileBasedCompression
Wscript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName
Wscript.Echo "SystemName: " & objItem.SystemName
Wscript.Echo "VolumeName: " & objItem.VolumeName
Wscript.Echo "VolumeSerialNumber: " & objItem.VolumeSerialNumber
Next



Regards
Steve Friday
 
Thanks SF but this gave me partition numbers relating to the disk rather than the volume number.
What would work too I guess is if I could search the text output from running diskpart and then run a particular script if this was T or F. But I must admit my scripting days are few. Is this possible?

eg if in diskpart.txt there exists


Microsoft DiskPart version 5.1.3553
Copyright (C) 1999-2001 Microsoft Corporation.
On computer: LNEEML01

DiskPart is starting the disk management services.

Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 F MAIL02 NTFS Simple 137 GB Healthy
Volume 1 E MAIL01 NTFS Simple 137 GB Healthy
Volume 2 R CD-ROM 0 B
Volume 3 C SYSTEM NTFS Partition 18 GB Healthy System
Volume 4 D OS_Utils NTFS Partition 16 GB Healthy



Then if I could match the string MAIL02 and take the volume number = 0 then i could get around it.

too hard?

thanks anyway

JB3K
 
Try this, I am presuming that you already have the text file

Dim fso
Set fso = Wscript.Createobject("Scripting.FilesystemObject")
set diskpart = fso_OpenTextFile("C:\Diskpart.txt",1)
newdetails = ""
Do Until diskpart.AtEndOfStream
strline = diskpart.ReadLine
If InStr(strline,"MAIL02") Then
details = split(Trim(strline)," ")
for i = 0 to ubound(details) -1
If NOT details(i) = "" Then
newdetails = newdetails & "," & details(i)
End If
Next
list = Split(newdetails,",")
Volume = list(1)
Volnumber = list(2)
dletter = list(3)
label = list(4)
msgbox volume & " " & volnumber & VBCrlf & "Drive Letter: " & dletter & VBCrlf & "Label: " & label
End If
Loop
diskpart.Close
Regards
Steve Friday
 
Steve=dead_set_legend

Thanks for your help, I used that script to determine the volume number and used that to run either set 0 or set 1 of a similar set of scripts on the RIGHT volume.

Thanks for your help

JB3K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top