473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Trouble with "Process's" please help!

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
5 1576
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit...
3
by: Loane Sharp | last post by:
Hi there I use the FileStream object to download a zip file over the internet to my local disk. The file downloads successfully, but when I attempt to unzip it, I'm told that the file is in use...
8
by: Henrik | last post by:
Hi Is there any way to see what the System process is doing? We have developed an application running at a production site to measure and optimize the production. The application needs to be...
4
by: hagaihe | last post by:
Hello, I've written a Windows service and i need help to implement the meaning of the sentence which is generated automatically by the IDE // More than one user Service may run within the same...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.