473,672 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Star tInfo.FileName = "cmd.exe"
CMDProcess.Star tInfo.Arguments = "\c md C:\temp\temp"
'---End XLNT Shell Variables-----------------------------
'============== =============== =============== =============== =
'=== END VARIABLE DECLARATION AND INITIALIZATION ============
'============== =============== =============== =============== =

'============== =============== =============== =============== =
'=== EXECUTE JOB AND KEEP TRACK OF TIME =============== ======
'============== =============== =============== =============== =
CMDProcess.Star t() <--- 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 1606
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 ProcessStartInf o()
Dim myNewApp As New Process()

myNewApp.StartI nfo.FileName = "C:\FILENAME.EX E"
myNewApp.StartI nfo.Arguments = "/Q"
myNewApp.StartI nfo.WorkingDire ctory = "C:\Temp"
myNewApp.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal

myNewApp.Start( )
Miro
"Matt" <Kr****@gmail.c omwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.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.Star tInfo.FileName = "cmd.exe"
CMDProcess.Star tInfo.Arguments = "\c md C:\temp\temp"
'---End XLNT Shell Variables-----------------------------
'============== =============== =============== =============== =
'=== END VARIABLE DECLARATION AND INITIALIZATION ============
'============== =============== =============== =============== =

'============== =============== =============== =============== =
'=== EXECUTE JOB AND KEEP TRACK OF TIME =============== ======
'============== =============== =============== =============== =
CMDProcess.Star t() <--- 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.Star tInfo.FileName = "cmd.exe"
CMDProcess.Star tInfo.Arguments = "\c md C:\temp\temp"
CMDProcess.Star t() <--- 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.Direc tory.CreateDire ctory( "C:\temp\te mp" )

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 ProcessStartInf o()
Dim myNewApp As New Process()
myNewApp.StartI nfo.FileName = "cmd.exe"
myNewApp.StartI nfo.Arguments = "\c md C:\temp\temp"
myNewApp.StartI nfo.WorkingDire ctory = "C:\Temp"
myNewApp.StartI nfo.WindowStyle = ProcessWindowSt yle.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.StartI nfo.FileName = "cmd.exe"
myNewApp.StartI nfo.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.StartI nfo
.FileName = "program1.e xe"
.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
715
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 anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
3
3680
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 by another process. This occurs even if I release the object using fs.Close() and fs = Nothing. Please help (my code is given below) Best regards
8
3216
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 responsive at all times during production. I'm experiencing some problems with my application not responding or responding slow. I suspeced the problem had to do with high CPU utilization
4
2723
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 process. To add // another service to this process, change the following line to // create a second service object. For example, // // ServicesToRun = new System.ServiceProcess.ServiceBase {new Service1(), new MySecondUserService()};
0
8404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8931
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8828
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8680
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4418
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.