Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using shell to call .bat file with parameters 1

Status
Not open for further replies.

lmohr79

Technical User
Jan 18, 2005
39
US
I've just joined the forum and have found it very helpful! Thank you!

I'm new to VB.net and programming in general - my background is general analysis and research in banking, so please bear with me.

I'm trying to call a batch file with SHELL that includes 2 parameters in VB.net. The batch file works just fine on its own when called with a shortcut on the desktop.

What appears to happens in VB.net is that the parameters are enclosed in the double quote string in the Shell.

This is what works in the shortcut on the desktop:

"C:\Program Files\lending\convert.bat" daily review
(daily and review are the 2 parameters that are passed to %1 and %2 in the bat file)

This is what I have in VB.net:
Dim strPath As String = "C:\Program Files\lending\"
Dim strApp As string = "convert.bat"
Dim sCmdLine As String
sCmdLine = strPath & strApp & " daily review"
Call Shell(sCmdLine, AppWinStyle.NormalFocus)

The value of sCmdLine is:
"C:\Program Files\lending\convert.bat daily review"

Is it possible to have the "value" of sCmdLine as:
"C:\Program Files\lending\convert.bat" daily review

Right now when I run the app, the command window appears to launch, but the .bat file doesn't appear to run, which leads me to believe that Shell can't "find the file".

Any insight would be helpful!

Call Shell(sCmdLine, AppWinStyle.NormalFocus)
 
Your alternative value for sCmdLine is correct.

Try:

Code:
sCmdLine = """C:\Program Files\lending\convert.bat"" daily review"

A pair of " characters within a string is replaced by a single " character.


Bob Boffin
 
Thanks for the help! This worked just fine.

[bigsmile] And thank you for the quick answer!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top