Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Calling a batch file with arguements through VBScript

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,62188
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Calling a batch file with arguements through VBScript
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Calling a batch file with arguements through VBScript - 7/7/2008 9:12:56 AM   
  kalcee

 

Posts: 8
Score: 0
Joined: 6/17/2008
Status: offline
Hello all,

I have a batch file by the name of MEMBERS. It basically returns of the names of the members of the given group name. The syntax is as follows

      
This was done by linking the batch file to another VBScript that retrieves the names of all group members.

I included this in a VBScript to get the members of many such groups. I used the objShell.Run thing. But the problem comes here. I have the name of all groups in an excel file and I am calling them using

      
So the overall command is

      

Here, it is taking the one with in the quotations as a group name instead of going to that location and getting the actual group name. So, how do I make the command in such a way that It goes to the location and pick up the name of the group ?

I hope I was clear in explaining my problem. Any help would be deeply appreciated
 
 
Post #: 1
 
 RE: Calling a batch file with arguements through VBScript - 7/7/2008 9:24:58 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
If you search for terms like .Run or Double quotes you should come across threads discussing the proper way to double quote .Run parameters.

_____________________________

"... 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

(in reply to kalcee)
 
 
Post #: 2
 
 RE: Calling a batch file with arguements through VBScript - 7/7/2008 9:33:21 AM   
  kalcee

 

Posts: 8
Score: 0
Joined: 6/17/2008
Status: offline
I figured out how to add the double quotes. The line I wrote works properly if I directly give a groupname. For eg, if my group name is AA, the command I am supposed to give is members "AA".

As the double quotes are a must in the syntax, my final code becomes

      

But I cant address the excel location properly as the objExcel thing is being taken as a groupname. Any ways I ll try searching with the suggestions u gave

< Message edited by kalcee -- 7/7/2008 9:39:53 AM >

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Calling a batch file with arguements through VBScript - 7/8/2008 3:15:18 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
Try using a variable, so something like:

strGroup = objExcel.Cells(358,11).Value
objShell.Run(members """ & strGroup & """)

_____________________________

"... 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

(in reply to kalcee)
 
 
Post #: 4
 
 RE: Calling a batch file with arguements through VBScript - 7/8/2008 5:45:13 AM   
  kalcee

 

Posts: 8
Score: 0
Joined: 6/17/2008
Status: offline
That looks like the way I am supposed to proceed on. But I am still getting an error. This is what I ve wrote.

strGrp = objExcel.Cells(358,11).Value
objShell.Run("%comspec% /k \somepath & members "" & strGrp & """). Its still takin & strGrp & as a groupname and gives the message that such group doesnt exist. I know tat i must be givin some kind of syntax in a wrong way but cudnt figure out wat tat is.

Here the first ampersand is required to run the members command after i add a path where that batch file exists..

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Calling a batch file with arguements through VBScript - 7/8/2008 5:54:48 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
Put this in to make sure you are getting the right value from excel:


strGrp = objExcel.Cells(358,11).Value
WScript.Echo strGrp
objShell.Run("%comspec% /k \somepath & members "" & strGrp & """)

_____________________________

"... 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

(in reply to kalcee)
 
 
Post #: 6
 
 RE: Calling a batch file with arguements through VBScript - 7/8/2008 7:25:01 AM   
  kalcee

 

Posts: 8
Score: 0
Joined: 6/17/2008
Status: offline
The WScript.Echo gives the desired output. But that output is not being reflected in the objShell.Run line. 

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Calling a batch file with arguements through VBScript - 7/8/2008 7:52:33 AM   
  kalcee

 

Posts: 8
Score: 0
Joined: 6/17/2008
Status: offline
ahhh!! Finally got it. I knew that it has got to be with the damn double quotes. This is what I gave

strGrp = chr(34) & objExcel.Cells(358,11).Value & chr(34)
objShell.Run("%comspec% /k \somepath & members " & strGrp &"")

Big thanks to u ebgreen for initially giving the idea to use a variable. It never actually occured to my little brain :)

(in reply to kalcee)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Calling a batch file with arguements through VBScript Page: [1]
Jump to:





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
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts