开发者

Get VBScript Output result in Batch Script and use it in another place

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 VB开发者_如何学运维Script 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:

dim sh
dim drives
drives = "C:\;D:\;F:\"
set sh = CreateObject("wscript.shell")
sh.run "test.bat " & Chr(34) & drives & Chr(34)

And you can test it by creating the file test.bat as:

@echo off
echo %1
pause

Otherwise, if it has to be the batch file that kicks it off, you can start the vb script with the Start command, 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:

start c:\test.vbs 
set /p drives= < test.txt
echo %drives%
pause

The documentation I link to for FSO includes a very simple sample for writing to a text file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜