Process Check loop

G

Guest

Hello All

I have the following code below that starts an external process batch file.
I would like to have the application display a dialog box confirming that the
process has ended. When I run the code below, I get an exception error

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.dll

Additional information: No process is associated with this object.

Here is the code

Public Sub UploadFile()
Dim p As New Process
p.Start("c:\ofac\ftpUpload.cmd")
Do While p.HasExited = False <-- Here is where the error occurs
Loop
If p.HasExited = True Then
MsgBox("File successfully uploaded", MsgBoxStyle.Information,
"OFAC File Generator")
End If

End Sub
 
C

Crouchie1998

The 'cmd' file isn't a process.

Processes are usually 'exe' files.

Crouchie1998
BA (HONS) MCP MCSE
 
K

Kaoru Kodaka

Dear Crouchie1998,

The 'cmd' file isn't a process.

Processes are usually 'exe' files.

This means He/She should use below.

p.Start("%COMSPEC% c:\ofac\ftpUpload.cmd")
 
J

John Wildes

I'm sorry but that's not correct either, if I use that, i get a SYSTEM
CANNOT FIND FILE exception.

Any more ideas.

thanks for the help
john
 
K

Kaoru Kodaka

Dear John,

I'm sorry, I didn't know the Start method doesn't extract
environment variables.

You can use below code instead of it.

p.Start("cmd.exe c:\ofac\ftpUpload.cmd")

If target OS is Windows 9x, You have to use "command.com"
instead of "cmd.exe".

I hope this will help you.



I'm sorry but that's not correct either, if I use that, i get a SYSTEM
CANNOT FIND FILE exception.

Any more ideas.

thanks for the help
john
 
J

John Wildes

Kaoru,

I tried this as well before you posted it, and it seems that I cannot pass
an executable with parameters, I even created a .vbs script file, which
calls the cmd file from VB.net and it stills gives me an Exception either,
FILE NOT FOUND when I'd enter p.Start("wscript.exe
c:\OFAC\ftpFileUpload.vbs") or p.Start("cmd.exe "c:\OFAC\fileUpload.cmd")

The process runs when I just call the cmd or the vbs file, but what I want
to happen is to report back to the application that it has finished and then
notify the user that it has finished.

thanks for the help
john

Kaoru Kodaka said:
Dear John,

I'm sorry, I didn't know the Start method doesn't extract
environment variables.

You can use below code instead of it.

p.Start("cmd.exe c:\ofac\ftpUpload.cmd")

If target OS is Windows 9x, You have to use "command.com"
instead of "cmd.exe".

I hope this will help you.
 
J

John Wildes

I did figure out how to pass arguments to the process

Public Sub UploadFile()

Dim p As New Process

Dim fileName As String

Dim args As String

fileName = "wscript.exe"

args = "C:\OFAC\ftpShellVBS.vbs"

p.StartInfo.FileName = fileName

p.StartInfo.Arguments = args

p.Start()

End Sub



Using the StartInfo.Arguments for the Process you can pass arguments like specifiing the script file to be run for WScript. It will also properly pass the HasExited part of my code, unfortunately it is at the WScriptLevel and not CMD level where my batch file is running. Just an FYI

john



John Wildes said:
Kaoru,

I tried this as well before you posted it, and it seems that I cannot pass
an executable with parameters, I even created a .vbs script file, which
calls the cmd file from VB.net and it stills gives me an Exception either,
FILE NOT FOUND when I'd enter p.Start("wscript.exe
c:\OFAC\ftpFileUpload.vbs") or p.Start("cmd.exe "c:\OFAC\fileUpload.cmd")

The process runs when I just call the cmd or the vbs file, but what I want
to happen is to report back to the application that it has finished and then
notify the user that it has finished.

thanks for the help
john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top