By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Trouble with "Process's" please help!

P: n/a
Ok so I'm trying to run a simple dos command shell through a VB.NET
2005 program. The oddest thing is happening given the following piece
of code:
'================================================= ===========
'=== VARIABLE DECLARATION AND INITIALIZATION ================
'================================================= ===========
'---General Variables------------------------------------
Dim CMDProcess As Process = New Process
'---End General Variables--------------------------------
'---XLNT Shell Variables---------------------------------
CMDProcess.StartInfo.FileName = "cmd.exe"
CMDProcess.StartInfo.Arguments = "\c md C:\temp\temp"
'---End XLNT Shell Variables-----------------------------
'================================================= ===========
'=== END VARIABLE DECLARATION AND INITIALIZATION ============
'================================================= ===========

'================================================= ===========
'=== EXECUTE JOB AND KEEP TRACK OF TIME =====================
'================================================= ===========
CMDProcess.Start() <--- Does not work
Process.Start("cmd.exe", "/c md C:\temp\temp") <---- Works
If I create a new instance of the "Process" object and then try to
start it, the command will not work. But if I just simply call
Process.start the command works!

I need to be able to use the created object to do this job. If anyone
could offer any thoughts I would be very appreciative.

Thanks
Matt

Aug 22 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
When you say the command doesn't work...what is the behavior? Do you get any
errors, is there a message box, does an exception get thrown? And if
so...what is the message?

I’m wondering if the CMDProcess object is able to actually find cmd.exe.

Kim Greenlee

--
digipede - Many legs make light work.
Grid computing for the real world.
http://www.digipede.net
http://krgreenlee.blogspot.net

Aug 22 '06 #2

P: n/a
I checked my process start program and the only difference I an see that I
have and you have is the
Dim of the Processes in the begining. This works for me... dont know if you
want to see if it works for u.

my code is as follows:
Dim StartInfo As New ProcessStartInfo()
Dim myNewApp As New Process()

myNewApp.StartInfo.FileName = "C:\FILENAME.EXE"
myNewApp.StartInfo.Arguments = "/Q"
myNewApp.StartInfo.WorkingDirectory = "C:\Temp"
myNewApp.StartInfo.WindowStyle = ProcessWindowStyle.Normal

myNewApp.Start()
Miro
"Matt" <Kr****@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
Ok so I'm trying to run a simple dos command shell through a VB.NET
2005 program. The oddest thing is happening given the following piece
of code:
'================================================= ===========
'=== VARIABLE DECLARATION AND INITIALIZATION ================
'================================================= ===========
'---General Variables------------------------------------
Dim CMDProcess As Process = New Process
'---End General Variables--------------------------------
'---XLNT Shell Variables---------------------------------
CMDProcess.StartInfo.FileName = "cmd.exe"
CMDProcess.StartInfo.Arguments = "\c md C:\temp\temp"
'---End XLNT Shell Variables-----------------------------
'================================================= ===========
'=== END VARIABLE DECLARATION AND INITIALIZATION ============
'================================================= ===========

'================================================= ===========
'=== EXECUTE JOB AND KEEP TRACK OF TIME =====================
'================================================= ===========
CMDProcess.Start() <--- Does not work
Process.Start("cmd.exe", "/c md C:\temp\temp") <---- Works
If I create a new instance of the "Process" object and then try to
start it, the command will not work. But if I just simply call
Process.start the command works!

I need to be able to use the created object to do this job. If anyone
could offer any thoughts I would be very appreciative.

Thanks
Matt

Aug 22 '06 #3

P: n/a
Matt wrote:
Dim CMDProcess As Process = New Process
CMDProcess.StartInfo.FileName = "cmd.exe"
CMDProcess.StartInfo.Arguments = "\c md C:\temp\temp"
CMDProcess.Start() <--- Does not work
Process.Start("cmd.exe", "/c md C:\temp\temp") <---- Works
Have a play with the StartInfo UseShellExecute property.
IIRC, that has some bearing on how things work.

Failing that, try "%COMSPEC%" instead of "cmd.exe"

Or, better still, looking at what you're actually doing:

System.IO.Directory.CreateDirectory( "C:\temp\temp" )

HTH,
Phill W.
Aug 23 '06 #4

P: n/a
I'm not trying to create a directory, that was just something I tossed
in there to see if it would work. What I'm ultimately trying to do is
to run dos commands from a VB.NET app.

I was under the impression given the following code.

Dim StartInfo As New ProcessStartInfo()
Dim myNewApp As New Process()
myNewApp.StartInfo.FileName = "cmd.exe"
myNewApp.StartInfo.Arguments = "\c md C:\temp\temp"
myNewApp.StartInfo.WorkingDirectory = "C:\Temp"
myNewApp.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myNewApp.Start()

That the "Arguments" part of it would indicate what dos command I
wanted to execute. When I run the following code I get a dos window
showing up but it doesn't make a directory. How do I get it to execute
it?

The reason I want to do things this way is so that I can measure when
the process ends, whereas if I just did it like this...

Process.Start("cmd.exe", "/c " & Command)

I can't tell.

Aug 23 '06 #5

P: n/a
Matt wrote:
I'm not trying to create a directory, that was just something I tossed
in there to see if it would work.
Fair enough.
myNewApp.StartInfo.FileName = "cmd.exe"
myNewApp.StartInfo.Arguments = "\c md C:\temp\temp"
Shouldn't that be "/c md C:\temp\temp" ?
The reason I want to do things this way is so that I can measure when
the process ends, whereas if I just did it like this...

Process.Start("cmd.exe", "/c " & Command)

I can't tell.
That's because when you kick off a /Windows/ process from /DOS/, DOS
doesn't wait for it to finish /unless/ you use the START command with
the "/WAIT" flag, effectively

START /WAIT winprog1.exe a b c d
IF ERRORLEVEL 1 GOTO Boom

The VB.Net way to start and wait for a Process would be more like this:

With myNewApp.StartInfo
.FileName = "program1.exe"
.Arguments = "a b c"
.Start()
.WaitForExit( ... ' can't remember the arguments; sorry
End With

HTH,
Phill W.
Aug 24 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.