|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Trouble with "Process's" please help!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 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 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 Show quoteHide quote "Matt" <Kru***@gmail.com> wrote in message news:1156274671.901073.38000@b28g2000cwb.googlegroups.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 > Matt wrote:
> Dim CMDProcess As Process = New Process Have a play with the StartInfo UseShellExecute property.> 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 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. 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. Matt wrote:
> I'm not trying to create a directory, that was just something I tossed Fair enough.> in there to see if it would work. > myNewApp.StartInfo.FileName = "cmd.exe" Shouldn't that be "/c md C:\temp\temp" ?> myNewApp.StartInfo.Arguments = "\c md C:\temp\temp" > The reason I want to do things this way is so that I can measure when That's because when you kick off a /Windows/ process from /DOS/, DOS > the process ends, whereas if I just did it like this... > > Process.Start("cmd.exe", "/c " & Command) > > I can't tell. 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.
.NET equivilant of isnumeric
Conversion Drawing images in different shapes VB.Net Merging Datasets Incorrect behavior of IIf in VB.NET (.NET Framework 1.1 SP1) can I use Imports with a VB2005 class namespace? Trouble Instanciating Structures Remove x number of charaters from string. Vb.net Getting error LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in atlmincr database connection |
|||||||||||||||||||||||