I have a VBScript which list drives’ letters. I want to get the drives’ letters in a batch script and use it somewhere. For example think the output of VBScript is “C:\;D:\;F:\”, then I want to tell batch script to get this info remove C:\ from it and write D:\;F:\ in a text file. I want to do it only via batch script.
Here is a VBScript for a example:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
drives = ""
For Each objDisk in colDisks
if drives > "" then
drives = drives & chr(13)
end if
drives = drives & objDisk.DeviceID & "\"
Next
So How to do that?
Thanks,
Majid Pasha
Not sure if this works for you but you can execute the batch file from the vb script and pass the list of drives as a parameter.
Example VB Sript:
And you can test it by creating the file test.bat as:
Otherwise, if it has to be the batch file that kicks it off, you can start the vb script with the
Startcommand, but not sure how you return a value to the batch file so the only way I can think of right now would be for the vb script to write the drives to a file using the FileSystemObject (FSO) and then you can read that in the batch file using code similar to:The documentation I link to for FSO includes a very simple sample for writing to a text file.