can I run command line parameters through VB code without creating and calling a batch file?

toddw0

can I run command line parameters through VB code without creating and calling a batch file?

by toddw0 » Sun, 10 Feb 2013 18:21:55

I need to run the following arguments on the command line:

cd c:\Program files\Microsoft SQL Server\90\Shared
sac out server1.out -DE

This will export the database engine settings from SQL server to a file called server1.out

I know how to do this using a batch file and then calling it from VB using the shell command but I need to do it directly from VB instead, is this possible


Renee

can I run command line parameters through VB code without creating and calling a batch file?

by Renee » Tue, 12 Feb 2013 19:22:56

Yes:

Dim CmdArg() As String = Environment.GetCommandLineArgs

Parsing is already done for you in the substrings of CmdArg()



Frank Car

can I run command line parameters through VB code without creating and calling a batch file?

by Frank Car » Wed, 13 Feb 2013 21:24:58

It's part of the System namespace so you should already have it.

If you're using VB6 or earlier, you'll need to use the Command function to return the command line parameters and parse it in your code.




toddw0

can I run command line parameters through VB code without creating and calling a batch file?

by toddw0 » Thu, 14 Feb 2013 20:23:57

What is the name of the reference I need to add to my project to get Environment to work
TaDa

can I run command line parameters through VB code without creating and calling a batch file?

by TaDa » Fri, 15 Feb 2013 22:25:59

Use the Process and ProcessStartInfo Classes.
Dick Donn

can I run command line parameters through VB code without creating and calling a batch file?

by Dick Donn » Sun, 17 Feb 2013 00:28:01

I am using VB6 unfortunately.

If you want to create a console application using VB6 .. here's a useful link http://www.xaprb.com/blog/2005/10/14/how-to-create-a-vb6-console-program/

It sounds like you probably just want to shell the command .. so maybe something along these lines is what you are looking for ...

dim arg as string = "c:\Program files\Microsoft SQL Server\90\Shared\sac out server1.out -DE"

shell("cmd /c " & arg)

Hope that is what you were searching for.

Richard


toddw0

can I run command line parameters through VB code without creating and calling a batch file?

by toddw0 » Sun, 17 Feb 2013 23:27:00

I am using VB6 unfortunately.