Shell Command

  • Thread starter Thread starter bh
  • Start date Start date
B

bh

I'm trying to write code to execute a .bat file.

Code in simple test.bat file runs fine from command prompt:
@Echo off
dir > "test.txt"

I've tried the following methods on code-behinds of buttons on both both an
ASP.NET and on Windows form, to no avail.

Method 1: Shell("C:\test.bat")
Method 2: Dim i as integer = Shell("C:\test.bat")
Method 3: System.Diagnostics.Process.Start("C:\test.bat")

I've checked for file.exists("C:\test.bat"), and the file is recognized
through the code; however, when I run either of the 3 methods, above, the
program doesn't break and yet the new test.txt file is not created. On the
other hand, if I set a break-point & run, for example Shell("C:\test.bat")
from the command window, I get Command "shell("C:\test.bat") is not valid.
Any ideas what could be happening here? Thanks in advance.

bh
 
I'm trying to write code to execute a .bat file.

Code in simple test.bat file runs fine from command prompt:
@Echo off
dir > "test.txt"

I've tried the following methods on code-behinds of buttons on both both an
ASP.NET and on Windows form, to no avail.

Method 1: Shell("C:\test.bat")
Method 2: Dim i as integer = Shell("C:\test.bat")
Method 3: System.Diagnostics.Process.Start("C:\test.bat")

I've checked for file.exists("C:\test.bat"), and the file is recognized
through the code; however, when I run either of the 3 methods, above, the
program doesn't break and yet the new test.txt file is not created. On the

Where did you look for test.txt? Perhaps it created it somewhere you
didn't expect?

It may have created it in the bin folder where the exe is run from.
It may have tried to create it in the program folder for Visual Studio
itself.

Are you running on Windows Vista? If so, then you are are not allowed
to write to any of the folders under program files. Instead Vista
will silently move the file to c:\users\<username>\Virtual Store
\Program Files\.....

Hope this helps

Chris
 
Mark,
I apologize for posting to both the ASP & WinForms groups on this; however,
I'd be happy to get this code working in either location, and have tried
both, which is why I posted to both. From what I found, online, the code
for the shell command seemed the same in both VB.NET & ASP.NET, and that is
why I posted to both groups. Since you say it's very different, and if
you've gotten it to work in either/both of the environments, I would really
appreciate the help to get it working in one or both places. Thank you.
 
Chris, I spoke too soon. Whil I never found the file on the machine,
anywhere, I tried explicitly putting the output file path in the .bat file,
and this time it worked. Thank you for your help.
 
Back
Top