batch file; prevent usres from breaking

  • Thread starter Thread starter JIM.H.
  • Start date Start date
J

JIM.H.

Hello,
When a user launches a batch file, I need to prevent users
from breaking the batch process. How can I do that?
Thanks,
Jim.
 
Use a .vbs file to execute it invisibly. That's one option.

Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.Run "C:\file.bat", 0, False
Set oShell = Nothing

The second argument, 0, means that the window of the program you're
executing is invisible. The third arg, false, means that the .vbs script
need not wait for the process you're executing to finish before it moves on
to the next step.

See here for details:
http://msdn.microsoft.com/library/en-us/script56/html/wsMthRun.asp

Ray at work
 
Hello, thanks for the reply.
When I use START I have to use EXIT in the batch file so
that windows will close, do I have to user EXIT if I use
ShellExecute.exe? Also with START /I I am expecting the
called batch file should have the variables I defined with
SET command in the calling batch file, am I wrong?
Thanks,
Jim.
 
JIM.H. said:
Hello, thanks for the reply.
When I use START I have to use EXIT in the batch file so
that windows will close, do I have to user EXIT if I use
ShellExecute.exe? Also with START /I I am expecting the
called batch file should have the variables I defined with
SET command in the calling batch file, am I wrong?
Thanks,
Jim.

Instead of calling the batch file directly, you can call the command
interpreter (CMD.EXE) and then specify exactly what you want to happen to
the window when it is finished. Cmd.exe will accept /C to close or /K to
keep the window open:
Start Cmd.exe /C x:\path\childscript.bat
Start Cmd.exe /K x:\path\childscript.bat

When called by ShellExecute.exe the window will be hidden, but the process
will automatically close without calling EXIT:
Start ShellExecute.exe /f:x:\path\childscript.bat /r:hidden

The /I switch does the opposite of what I think you want. By default if you
change some variables in one batch file they will be available in the child
process, so don't specify /I.
 
Thanks Marty,
It is really helpful information. What is the benefit of
using START before ShellExecute.exe
Thanks,
Jim.
-----Original Message-----



Instead of calling the batch file directly, you can call the command
interpreter (CMD.EXE) and then specify exactly what you want to happen to
the window when it is finished. Cmd.exe will accept /C to close or /K to
keep the window open:
Start Cmd.exe /C x:\path\childscript.bat
Start Cmd.exe /K x:\path\childscript.bat

When called by ShellExecute.exe the window will be hidden, but the process
will automatically close without calling EXIT:
Start
ShellExecute.exe /f:x:\path\childscript.bat /r:hidden
 
Back
Top