Please help with issue of passing variables

Author Message
rene_p

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 12/9/2011
  • Status: offline
Please help with issue of passing variables Friday, December 09, 2011 1:32 AM (permalink)
0
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




 
#1
    MrYoson

    • Total Posts : 8
    • Scores: 0
    • Reward points : 0
    • Joined: 12/9/2011
    • Status: offline
    Re:Please help with issue of passing variables Friday, December 09, 2011 2:55 AM (permalink)
    0
    If you are trying to pass 'ver' as an argument to the batch file, try this: 

    vbShell.run chr(34) & batchFile & chr(34) & " " & ver
    where chr(34) is a double-quote.
     
    #2
      rene_p

      • Total Posts : 2
      • Scores: 0
      • Reward points : 0
      • Joined: 12/9/2011
      • Status: offline
      Re:Please help with issue of passing variables Friday, December 09, 2011 3:07 AM (permalink)
      0
      Thanks for the response.  I am one step closer.  A variable is no being passed but the wrong one.  The resulting output to the text file is now
       
      Fri 12/09/2011 ,  Administrator , RENE-494ECED0E8 , 192.168.189.136 , GW version = , Next , winxp  
       
      So for whatever reason the last command in the vbs script Next is being passed as a variable.
       
      Rene
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        Re:Please help with issue of passing variables Friday, December 09, 2011 3:40 AM (permalink)
        0
        The issue that I see is that passing a variable named ver to the batch file does not magically create an environment variable name ver. Try changing this line:
         
        echo %date% ,  %username% , %computername% , %IP% , GW version = , %ver% , winxp  >> c:\install.txt 
         
        to:
         
        echo %date% ,  %username% , %computername% , %IP% , GW version = , %1% , winxp  >> c:\install.txt 

         
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          MrYoson

          • Total Posts : 8
          • Scores: 0
          • Reward points : 0
          • Joined: 12/9/2011
          • Status: offline
          Re:Please help with issue of passing variables Friday, December 09, 2011 4:13 AM (permalink)
          0
          EDIT: the above reply by ebgreen is most likely the correct solution, try his before this 

          1) 'do you have a 'Next' at the end of your For Each?
          For Each objFile in colFiles
          ver = objFile.Version
          batchFile = c:\gwver.bat
          vbShell.run chr(34) & batchFile & chr(34) & " " & ver
          Next

          the loop should look like that in order for it to work properly.

          2) you could also try outputting some information in each loop iteration to help narrow down the problem, i suggest:
          For Each objFile in colFiles       
          ver = objFile.Version
          msgbox objFile.Name & " " & ver
          batchFile = c:\gwver.bat
          vbShell.run chr(34) & batchFile & chr(34) & " " & ver
          Next

          3) a final option would be to just use FileSystemObject instead of WMI. FileSystemObject is a bit simpler and faster IF the script only deals with files on the local machine. FileSystemObject is a bit limited compared
          to WMI but if you only need to get the file versions of some files, FSO is the way to go Set objFSO = CreateObject("Scripting.FileSystemObject")

          Set folder = fso.GetFolder("c:\novell\Groupwise")
          Set files = folder.Files
          For Each objFile in colFiles      
          ver = objFSO.GetFileVersion(objFile)
          batchFile = c:\gwver.bat
          vbShell.run chr(34) & batchFile & chr(34) & " " & ver
          Next

          keep me updated, good luck
          <message edited by MrYoson on Friday, December 09, 2011 4:23 AM>
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9