What right is needed to start new processes from batch files?

  • Thread starter Thread starter Stefano Gatto
  • Start date Start date
S

Stefano Gatto

An user-account on our Windows 2000 server is configured without the right
to logon interactively. The only way batch files can be executed on its
behalf is through the Windows Scheduler.

The problem we have is with those batch files that need to launch new
processes. Actually all lines are executed except those that launch new
processes. See exemple below. Lines that launch new processes are ignored or
fail.

Does anyone know what particular right we should grant to that
non-interactive user, so that batch files launched in its name can spawn new
processes? Thanks a lot.

Exemple: this batch file is launched by Windows Scheduler on behalf on this
user. All lines are executed properly except the one opening a new process:
"cmd /c dir > log.txt". This line fails from executing, maybe because it
needs a new process to be created to host cmd.

echo Batch file starts on %date% - %time% > log.txt
echo This batch file starts a new process now: > log.txt
cmd /c dir > log.txt
echo This batch file is finished > log.txt

C:\>type log.txt
Batch file starts on 12-mar-2004 - 9:09:13
This batch file starts a new process now:
This batch file is finished

C:\>

As you may notice, the result of "dir" is not traced in the log, so I
imagine it has not been executed. Does someone has an idea why?

I hope my explanations are clear enough otherwise please ask details. Thanks
Stefano
 
I just figured out that this user has "Log on as batch job" in the local and
domain security settings.

Can someone help me? Is there some info I should still provide you with?

Many thanks, Stefano
 
I just realized today that this user was not member of any of the local
groups, so by adding it to the "Users" local group the problem is solved.

The local security setting "Log on as batch job" has been granted
automatically to this user by the system at the moment when I scheduled the
job to run in its behalf.

Thanks, Stefano
 
Stefano Gatto said:
Exemple: this batch file is launched by Windows Scheduler on behalf on this
user. All lines are executed properly except the one opening a new process:
"cmd /c dir > log.txt". This line fails from executing, maybe because it
needs a new process to be created to host cmd.

echo Batch file starts on %date% - %time% > log.txt
echo This batch file starts a new process now: > log.txt
cmd /c dir > log.txt
echo This batch file is finished > log.txt

C:\>type log.txt
Batch file starts on 12-mar-2004 - 9:09:13
This batch file starts a new process now:
This batch file is finished

Not sure how you are getting your log.txt file to have
all the lines it does have in it. the ">" redirection
character should overwrite the log.txt file every time
it is used. Maybe you are using ">>".

If that is the case then when you do the "cmd /c dir > log.txt"
you are starting a second process which is trying to open
and write to log.txt -- which is already opened by the first
process. This causes a fatal error and the "cmd /c dir >
log.txt" fails

1. You should also capture stderr as well as stdout if you
want to get all the output of the command - including errors.
cmd /c dir >> log.txt 2>>1
("1" refers for file handle 1, stdout and
"2" refers to file handle 2, stderr -- "0" is stdin)

2. When testing, allow scheduled tasks to interact with the
desktop. Lets you to observe if anything unexpected happens.

3. Don't do your logging redirection in the batch file. Do it
when you set up the at command:
AT 12:59 c:\temp\dm.cmd ^> c:\temp\dm.log 2^>^>1
(the caret "^" is an escape character)
Or in the scheduled tasks GUI
 
Thanks a lot for your answer Matt, it's really useful.

First of all, yes you are correct I use >> not >.

Then, I think the problem was that this user (belonging to the domain, not
local to the computer - sorry for not having said that before) was not part
of any of the local groups (Users, Powerusers, Administrators), and
therefore I think it could just "log on as batch" (local right that got
granted automatically at the moment I scheduled the batch to run on his
behalf), i.e. have at its disposal 1 process and no more than 1.
I understand that to be able to launch new process beyond the first one it
must be part of either the Users, or Powerusers, or Administrators local
group.

I have the impression that > and >> open, write and close the resource (file
or stream) so that the next (synchronous) command should not fail.

Thanks for the n>> syntax and the ^ too, I did not know them.

Stefano
Geneva, Switzerland
 
Back
Top