#1 08 Dec 2011 21:02

rene
Member
Registered: 08 Dec 2011
Posts: 1

passing variable from vbscript to batch file

Hello.  I am very new to vbscripting so please be patient with me.

I am trying to create a script that will check the version of an exe file and post the info to a txt file.

I start with a batch file

gwver.bat

IPCONFIG |FIND "IP" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~1%

for /F  %%* in (c:\ver.vbs) do set ver=%%*


echo %date% ,  %username% , %computername% , %IP% , GW version = , %ver% , winxp  >> c:\install.txt 

for the value of %ver%  - which would be the file version of the exe file I call on ver.vbs

strComputer = "."
Dim ver
Set vbShell = CreateObject("WScript.Shell")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_Datafile Where Name = 'c:\\novell\\Groupwise\\grpwise.exe'")

For Each objFile in colFiles
    ver = objFile.Version

batchFile = c:\gwver.bat

vbShell.run batchFile & ver

The result in the txt file is

Thu 12/08/2011 ,  rene , WLLB-RENE , 205.189.26.163 , GW version = ,  , winxp  

This is not working.  How do I get that variable of ver from the vbs script to the batch file.

Thank you.

Rene

Offline

#2 09 Dec 2011 02:25

jaffamuffin
Member
Registered: 21 Mar 2009
Posts: 19

Re: passing variable from vbscript to batch file

rene wrote:

Hello.  I am very new to vbscripting so please be patient with me.

I am trying to create a script that will check the version of an exe file and post the info to a txt file.

I start with a batch file

gwver.bat

IPCONFIG |FIND "IP" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~1%

for /F  %%* in (c:\ver.vbs) do set ver=%%*


echo %date% ,  %username% , %computername% , %IP% , GW version = , %ver% , winxp  >> c:\install.txt 


Rene

I'm going to guess that you might want to change you for to read

for /F  %%A in ('c:\ver.vbs') do set ver=%%A

Offline

#3 09 Dec 2011 02:27

jaffamuffin
Member
Registered: 21 Mar 2009
Posts: 19

Re: passing variable from vbscript to batch file

does the vbscript print out the value of ver to the screen, or does that last line pass it to the batch script as a param?

Offline

#4 31 Oct 2012 21:30

britter440
Member
Registered: 31 Oct 2012
Posts: 3

Re: passing variable from vbscript to batch file

I see this one pretty much got abandoned, but I figured that I'd drop the answer here for anyone that came along.

You reference the arguments within you *.bat file by using a "%" and the argument number.  Let's say that you've got an executable on your C: drive called myexe.exe and you want to run it with the 1st and 5th argument from your script.  The line would look like this:

c:\myexe.exe %1 %5

Offline

Board footer

Powered by FluxBB