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

Process Check loop

P: n/a
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

--
Freedom isn't free... but the United States Marine Corps will pay most of
your share !!! Semper Fi!!
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
The 'cmd' file isn't a process.

Processes are usually 'exe' files.

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #2

P: n/a
Dear Crouchie1998,

On Tue, 7 Jun 2005 20:40:17 +0100
"Crouchie1998" <cr**********@spamcop.net> wrote:
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")

---
MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
kaok.Web = "http://www.antoine.st/";

Nov 21 '05 #3

P: n/a
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

"Kaoru Kodaka" <ka**@venus.dti.ne.jp> wrote in message
news:20**********************@venus.dti.ne.jp...
Dear Crouchie1998,

On Tue, 7 Jun 2005 20:40:17 +0100
"Crouchie1998" <cr**********@spamcop.net> wrote:
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")

---
MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
kaok.Web = "http://www.antoine.st/";

Nov 21 '05 #4

P: n/a
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.

On Wed, 8 Jun 2005 14:33:13 -0500
"John Wildes" <jw*****@gmail.com> wrote:
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

"Kaoru Kodaka" <ka**@venus.dti.ne.jp> wrote in message
news:20**********************@venus.dti.ne.jp...
Dear Crouchie1998,

On Tue, 7 Jun 2005 20:40:17 +0100
"Crouchie1998" <cr**********@spamcop.net> wrote:
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")

---
MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
kaok.Web = "http://www.antoine.st/";

---
MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
kaok.Web = "http://www.antoine.st/";

Nov 21 '05 #5

P: n/a
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" <ka**@venus.dti.ne.jp> wrote in message
news:20**********************@venus.dti.ne.jp...
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.

On Wed, 8 Jun 2005 14:33:13 -0500
"John Wildes" <jw*****@gmail.com> wrote:
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

"Kaoru Kodaka" <ka**@venus.dti.ne.jp> wrote in message
news:20**********************@venus.dti.ne.jp...
> Dear Crouchie1998,
>
> On Tue, 7 Jun 2005 20:40:17 +0100
> "Crouchie1998" <cr**********@spamcop.net> wrote:
>
>> 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")
>
> ---
> MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
> kaok.Web = "http://www.antoine.st/";
>

---
MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
kaok.Web = "http://www.antoine.st/";

Nov 21 '05 #6

P: n/a
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" <jw*****@gmail.com> wrote in message news:uW**************@TK2MSFTNGP09.phx.gbl...
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" <ka**@venus.dti.ne.jp> wrote in message
news:20**********************@venus.dti.ne.jp...
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.

On Wed, 8 Jun 2005 14:33:13 -0500
"John Wildes" <jw*****@gmail.com> wrote:
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

"Kaoru Kodaka" <ka**@venus.dti.ne.jp> wrote in message
news:20**********************@venus.dti.ne.jp...
> Dear Crouchie1998,
>
> On Tue, 7 Jun 2005 20:40:17 +0100
> "Crouchie1998" <cr**********@spamcop.net> wrote:
>
>> 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")
>
> ---
> MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
> kaok.Web = "http://www.antoine.st/";
>

---
MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
kaok.Web = "http://www.antoine.st/";


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.