Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Calling an executable with parameters

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Calling an executable with parameters
  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 an executable with parameters - 12/3/2007 4:41:58 AM   
  pblecha

 

Posts: 4
Score: 0
Joined: 11/6/2007
Status: offline
I'm writing a script that will call an executable and run it with passed in parameters.  However, I can't get it to run correctly.

Any ideas?

Here is the script:


dim
fcObject, fileCollection, fcListString, fileName, fileExt, bpaOutputName, subVarOutputName

set
fcObject = createobject("scripting.filesystemobject")

set
WshShell = wscript.createobject("wscript.shell")

set
fileCollection = fcObject.Drives("C:").RootFolder.subfolders("templates").files

for
each file in fileCollection
fileName = fcObject.GetBaseName(file)
fileExt = fcObject.GetExtensionName(file)
bpaOutputName = fileName & "_bpa." & fileExt
subVarOutputName = fileName & "_subvar." & fileExt
if fileExt = "xml" then

msgbox("""C:\Program Files\ConfigMgr 2007 Toolkit\DCM Tools\BPAtoDCM.exe /nologo /scope Microsoft.Sample c:\templates\""" & file.Name & """ c:\templates\""" & bpaOutputName & """)
wshshell.run """C:\Program Files\ConfigMgr 2007 Toolkit\DCM Tools\BPAtoDCM.exe /nologo /scope Microsoft.Sample c:\templates\"" & file.Name & "" c:\templates\"" & bpaOutputName", 7,
true

wshshell.run """C:\Program Files\ConfigMgr 2007 Toolkit\DCM Tools\DCMSubVar.exe """ & bpaOutputName & """ """ & subVarOutputName, 7,
true

msgbox("Processing complete: " & file.Name)
end if
next
 
 
Post #: 1
 
 RE: Calling an executable with parameters - 12/3/2007 4:49:01 AM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If you take the string this outputs
msgbox("""C:\Program Files\ConfigMgr 2007 Toolkit\DCM Tools\BPAtoDCM.exe /nologo /scope Microsoft.Sample c:\templates\""" & file.Name & """ c:\templates\""" & bpaOutputName & """)

Does it work? ...and I mean exactly as it appears in that msgbox...not what you know it should be...change it to an input box and set it as the default value so you can easily copy and paste it


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to pblecha)
 
 
Post #: 2
 
 RE: Calling an executable with parameters - 12/3/2007 5:21:08 AM   
  pblecha

 

Posts: 4
Score: 0
Joined: 11/6/2007
Status: offline
Actually, it doesn't work.  It comes back with superfluous quotation marks that cause the execution following it to break.

Thus far this hasn't worked.  And nobody has a really clear explanation of how to format an input string passing in variables using those bloody triple-quotation-marks.

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Calling an executable with parameters - 12/3/2007 5:36:04 AM   
  mcds99


Posts: 434
Score: 4
Joined: 2/28/2006
Status: offline
Break it up in to parts and reassemble it doesn't hurt to over simplify.


      

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to pblecha)
 
 
Post #: 4
 
 RE: Calling an executable with parameters - 12/3/2007 5:45:42 AM   
  ehvbs

 

Posts: 2196
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi pblecha,

the important fact: a " in a VBScript string has to be coded as ""

the strategy:

(a) test a 'real life' command in a dos box/command line window

(b) use the clipboard to get this in your source file

(c) replace " with ""; add " at the start and the end to make it a string literal

(d) replace constants from the sample with variable names like this

        "...constant..."  => "..." & Variable & "..."

       or

        "...constant..."  => "...§SuitableName§..."
                                         ...
                                         sCmd = Replace( sCmd, "§SuitableName§", Varaible )

If you follow these steps, the resulting string may not be easy to read, but it should work.

Good luck!

ehvbs

(in reply to pblecha)
 
 
Post #: 5
 
 RE: Calling an executable with parameters - 12/3/2007 7:26:57 AM   
  pblecha

 

Posts: 4
Score: 0
Joined: 11/6/2007
Status: offline
Thanks.  This is in fact very helpful!

I'm still a bit confused on your use of constants; I'm not passing in constants, I'm passing in a FileSystemObject.File.

Just FYI, the executable I'm calling in the first line (ignoring the msgbox, which is just for testing only) requires the following parameter switches:

/nologo - turns off some silly logo
/scope is the AuthoringScopeId for the file, which I'm still unsure what the heck they mean....

And then I pass in two values: 1) the name of the xml file to be processed; and 2) the name of the output file.  That is why I have paths in there; it will save back to the directory containing the xml files (c:\templates) with an updated name, which then gets passed into the SECOND executable call (and once I know how the first one works, the second one ought to follow suit).

I did as recommended; tried it first as a command-line call, and copied the working command code into my vbscript; now I'm going through and replacing as you suggest, which is why I'm now asking about the variables.

? :)

UPDATED:

Awesome.  Here is the command line that seems to work:


"""c:\program files\configmgr 2007 toolkit\dcm tools\bpatodcm"" /nologo /scope Microsoft.Sample c:\templates\" & file.Name & " c:\templates\"& bpaOutputName & ""

Thanks! :)


< Message edited by pblecha -- 12/3/2007 7:32:48 AM >

(in reply to ehvbs)
 
 
Post #: 6
 
 
 
  

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 an executable with parameters 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