Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Windows scheduler: Running a batch file as another user?

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 07-03-2008
Andrew Hodgson
 
Posts: n/a
Windows scheduler: Running a batch file as another user?

Hi,

I have an account which is in the users and IIS_WPG group. I would
like this account to run a batch file every hour, however, when I
schedule the script to run when I am logged in as an account with
administrator privileges to run under that user, and when I start the
job, it fails. I can see from the audit log that the user is being
logged in and out, but it doesn't start. I attempted to run the
scheduler logged in as the account I wanted the script to run under,
however, it does not give me access.

So my question is: What are the minimum permissions I need to grant in
order to let this script run as a scheduled job under the limited
account?

Thanks.
Andrew.

Reply With Quote
  #2  
Old 07-03-2008
Pegasus \(MVP\)
 
Posts: n/a
Re: Windows scheduler: Running a batch file as another user?


"Andrew Hodgson" <me3@privacy.net> wrote in message
news:2bf0t3ti8glcacqg48ve0dvbijtolkufcf@news.giganews.com...
> Hi,
>
> I have an account which is in the users and IIS_WPG group. I would
> like this account to run a batch file every hour, however, when I
> schedule the script to run when I am logged in as an account with
> administrator privileges to run under that user, and when I start the
> job, it fails. I can see from the audit log that the user is being
> logged in and out, but it doesn't start. I attempted to run the
> scheduler logged in as the account I wanted the script to run under,
> however, it does not give me access.
>
> So my question is: What are the minimum permissions I need to grant in
> order to let this script run as a scheduled job under the limited
> account?
>
> Thanks.
> Andrew.


Just because you cannot see the result from your scheduled
job does not mean that it did not run. Try coding it like this:

@echo off
echo %date% %time% %UserName% >> c:\test.log
"c:\tools\YourCommand.exe" 1>>c:\test.log 2>>&1

Not schedule this batch file, then check out c:\test.log.
Make sure the account you use for the scheduled job
has a non-blank password.


Reply With Quote
  #3  
Old 07-03-2008
JohnB
 
Posts: n/a
Re: Windows scheduler: Running a batch file as another user?

I don't have anything to add to your answer but, I have a general question
on your batch file.

I've redirected the results of a DOS command to a text file before, and I
always used this symbol: ">"
But you have a double >
I tested it and get the same results with both. Why 2?

And, what does this command do: >>c:\test.log 2>>&1

I can see that it's again redirecting the output to test.log, but what I
don't understand is what follows test.log (2>>&1)

Always looking to learn something new ;-)





"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
news:OvhcoS8fIHA.4140@TK2MSFTNGP04.phx.gbl...
>
> "Andrew Hodgson" <me3@privacy.net> wrote in message
> news:2bf0t3ti8glcacqg48ve0dvbijtolkufcf@news.giganews.com...
>> Hi,
>>
>> I have an account which is in the users and IIS_WPG group. I would
>> like this account to run a batch file every hour, however, when I
>> schedule the script to run when I am logged in as an account with
>> administrator privileges to run under that user, and when I start the
>> job, it fails. I can see from the audit log that the user is being
>> logged in and out, but it doesn't start. I attempted to run the
>> scheduler logged in as the account I wanted the script to run under,
>> however, it does not give me access.
>>
>> So my question is: What are the minimum permissions I need to grant in
>> order to let this script run as a scheduled job under the limited
>> account?
>>
>> Thanks.
>> Andrew.

>
> Just because you cannot see the result from your scheduled
> job does not mean that it did not run. Try coding it like this:
>
> @echo off
> echo %date% %time% %UserName% >> c:\test.log
> "c:\tools\YourCommand.exe" 1>>c:\test.log 2>>&1
>
> Not schedule this batch file, then check out c:\test.log.
> Make sure the account you use for the scheduled job
> has a non-blank password.
>



Reply With Quote
  #4  
Old 07-03-2008
Pegasus \(MVP\)
 
Posts: n/a
Re: Windows scheduler: Running a batch file as another user?

Good questions! The command
echo %date% > c:\test.txt
will write the current date into c:\test.txt.

The command
echo %time% >> c:\test.txt
will ***add*** the current time to whatever
is already in c:\test.txt.

The command
xcopy.exe /.. /.. /.. .. .. 1>c:\test.log 2>c:\test.err
will write the ***standard*** output from the xcopy
command into c:\test.log and the ***error*** output
(if any) into c:\test.err. If you want both outputs in
c:\test.log then you have to code it like so:
xcopy.exe /.. /.. /.. .. .. 1>c:\test.log 2>&1

I cannot tell you if and where this might be documented.


"JohnB" <jbrigan@yahoo.com> wrote in message
news:eKHFai8fIHA.3940@TK2MSFTNGP05.phx.gbl...
>I don't have anything to add to your answer but, I have a general question
>on your batch file.
>
> I've redirected the results of a DOS command to a text file before, and I
> always used this symbol: ">"
> But you have a double >
> I tested it and get the same results with both. Why 2?
>
> And, what does this command do: >>c:\test.log 2>>&1
>
> I can see that it's again redirecting the output to test.log, but what I
> don't understand is what follows test.log (2>>&1)
>
> Always looking to learn something new ;-)
>
>
>
>
>
> "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
> news:OvhcoS8fIHA.4140@TK2MSFTNGP04.phx.gbl...
>>
>> "Andrew Hodgson" <me3@privacy.net> wrote in message
>> news:2bf0t3ti8glcacqg48ve0dvbijtolkufcf@news.giganews.com...
>>> Hi,
>>>
>>> I have an account which is in the users and IIS_WPG group. I would
>>> like this account to run a batch file every hour, however, when I
>>> schedule the script to run when I am logged in as an account with
>>> administrator privileges to run under that user, and when I start the
>>> job, it fails. I can see from the audit log that the user is being
>>> logged in and out, but it doesn't start. I attempted to run the
>>> scheduler logged in as the account I wanted the script to run under,
>>> however, it does not give me access.
>>>
>>> So my question is: What are the minimum permissions I need to grant in
>>> order to let this script run as a scheduled job under the limited
>>> account?
>>>
>>> Thanks.
>>> Andrew.

>>
>> Just because you cannot see the result from your scheduled
>> job does not mean that it did not run. Try coding it like this:
>>
>> @echo off
>> echo %date% %time% %UserName% >> c:\test.log
>> "c:\tools\YourCommand.exe" 1>>c:\test.log 2>>&1
>>
>> Not schedule this batch file, then check out c:\test.log.
>> Make sure the account you use for the scheduled job
>> has a non-blank password.
>>

>
>



Reply With Quote
  #5  
Old 07-03-2008
JohnB
 
Posts: n/a
Re: Windows scheduler: Running a batch file as another user?

I've been in IT since DOS 3.1 days and I don't ever remember seeing anything
about redirecting the error output, so I will have to make a note of that
one.... because I sure won't use it often enough to remember it :) Good
stuff!!


"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
news:%23Z7Dmv8fIHA.3352@TK2MSFTNGP04.phx.gbl...
> Good questions! The command
> echo %date% > c:\test.txt
> will write the current date into c:\test.txt.
>
> The command
> echo %time% >> c:\test.txt
> will ***add*** the current time to whatever
> is already in c:\test.txt.
>
> The command
> xcopy.exe /.. /.. /.. .. .. 1>c:\test.log 2>c:\test.err
> will write the ***standard*** output from the xcopy
> command into c:\test.log and the ***error*** output
> (if any) into c:\test.err. If you want both outputs in
> c:\test.log then you have to code it like so:
> xcopy.exe /.. /.. /.. .. .. 1>c:\test.log 2>&1
>
> I cannot tell you if and where this might be documented.
>
>
> "JohnB" <jbrigan@yahoo.com> wrote in message
> news:eKHFai8fIHA.3940@TK2MSFTNGP05.phx.gbl...
>>I don't have anything to add to your answer but, I have a general question
>>on your batch file.
>>
>> I've redirected the results of a DOS command to a text file before, and I
>> always used this symbol: ">"
>> But you have a double >
>> I tested it and get the same results with both. Why 2?
>>
>> And, what does this command do: >>c:\test.log 2>>&1
>>
>> I can see that it's again redirecting the output to test.log, but what I
>> don't understand is what follows test.log (2>>&1)
>>
>> Always looking to learn something new ;-)
>>
>>
>>
>>
>>
>> "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
>> news:OvhcoS8fIHA.4140@TK2MSFTNGP04.phx.gbl...
>>>
>>> "Andrew Hodgson" <me3@privacy.net> wrote in message
>>> news:2bf0t3ti8glcacqg48ve0dvbijtolkufcf@news.giganews.com...
>>>> Hi,
>>>>
>>>> I have an account which is in the users and IIS_WPG group. I would
>>>> like this account to run a batch file every hour, however, when I
>>>> schedule the script to run when I am logged in as an account with
>>>> administrator privileges to run under that user, and when I start the
>>>> job, it fails. I can see from the audit log that the user is being
>>>> logged in and out, but it doesn't start. I attempted to run the
>>>> scheduler logged in as the account I wanted the script to run under,
>>>> however, it does not give me access.
>>>>
>>>> So my question is: What are the minimum permissions I need to grant in
>>>> order to let this script run as a scheduled job under the limited
>>>> account?
>>>>
>>>> Thanks.
>>>> Andrew.
>>>
>>> Just because you cannot see the result from your scheduled
>>> job does not mean that it did not run. Try coding it like this:
>>>
>>> @echo off
>>> echo %date% %time% %UserName% >> c:\test.log
>>> "c:\tools\YourCommand.exe" 1>>c:\test.log 2>>&1
>>>
>>> Not schedule this batch file, then check out c:\test.log.
>>> Make sure the account you use for the scheduled job
>>> has a non-blank password.
>>>

>>
>>

>
>



Reply With Quote
  #6  
Old 09-03-2008
Andrew Hodgson
 
Posts: n/a
Re: Windows scheduler: Running a batch file as another user?

On Thu, 6 Mar 2008 16:41:16 -0500, "JohnB" <jbrigan@yahoo.com> wrote:

>I've been in IT since DOS 3.1 days and I don't ever remember seeing anything
>about redirecting the error output, so I will have to make a note of that
>one.... because I sure won't use it often enough to remember it :) Good
>stuff!!


I have always used this in Unix, didn't realise either it worked in
Windows though.

Thanks.
Andrew.
Reply With Quote
  #7  
Old 09-03-2008
Andrew Hodgson
 
Posts: n/a
Re: Windows scheduler: Running a batch file as another user?

On Thu, 6 Mar 2008 20:59:54 +0100, "Pegasus \(MVP\)"
<I.can@fly.com.oz> wrote:

>
>"Andrew Hodgson" <me3@privacy.net> wrote in message
>news:2bf0t3ti8glcacqg48ve0dvbijtolkufcf@news.giganews.com...
>> Hi,
>>
>> I have an account which is in the users and IIS_WPG group. I would
>> like this account to run a batch file every hour, however, when I
>> schedule the script to run when I am logged in as an account with
>> administrator privileges to run under that user, and when I start the
>> job, it fails. I can see from the audit log that the user is being
>> logged in and out, but it doesn't start. I attempted to run the
>> scheduler logged in as the account I wanted the script to run under,
>> however, it does not give me access.
>>
>> So my question is: What are the minimum permissions I need to grant in
>> order to let this script run as a scheduled job under the limited
>> account?
>>
>> Thanks.
>> Andrew.

>
>Just because you cannot see the result from your scheduled
>job does not mean that it did not run. Try coding it like this:


Actually in the scheduled task window it said it did not run, and the
batch file does create a log which did not get populated.

We can run it fine if the account it is in the administrators group.
The user has full rights to the relevant directories - including the
log files directory.

Thanks.
Andrew.
Reply With Quote
  #8  
Old 09-03-2008
Pegasus \(MVP\)
 
Posts: n/a
Re: Windows scheduler: Running a batch file as another user?


"Andrew Hodgson" <me3@privacy.net> wrote in message
news:me86t31b0mq42d5jeolg71gkoq7p5jqshh@news.giganews.com...
> On Thu, 6 Mar 2008 20:59:54 +0100, "Pegasus \(MVP\)"
> <I.can@fly.com.oz> wrote:
>
>>
>>"Andrew Hodgson" <me3@privacy.net> wrote in message
>>news:2bf0t3ti8glcacqg48ve0dvbijtolkufcf@news.giganews.com...
>>> Hi,
>>>
>>> I have an account which is in the users and IIS_WPG group. I would
>>> like this account to run a batch file every hour, however, when I
>>> schedule the script to run when I am logged in as an account with
>>> administrator privileges to run under that user, and when I start the
>>> job, it fails. I can see from the audit log that the user is being
>>> logged in and out, but it doesn't start. I attempted to run the
>>> scheduler logged in as the account I wanted the script to run under,
>>> however, it does not give me access.
>>>
>>> So my question is: What are the minimum permissions I need to grant in
>>> order to let this script run as a scheduled job under the limited
>>> account?
>>>
>>> Thanks.
>>> Andrew.

>>
>>Just because you cannot see the result from your scheduled
>>job does not mean that it did not run. Try coding it like this:

>
> Actually in the scheduled task window it said it did not run, and the
> batch file does create a log which did not get populated.
>
> We can run it fine if the account it is in the administrators group.
> The user has full rights to the relevant directories - including the
> log files directory.
>
> Thanks.
> Andrew.


You must give the user a non-blank password and you must
set your group policy so that this user can log on as a batch job.


Reply With Quote
  #9  
Old 09-03-2008
Andrew Hodgson
 
Posts: n/a
Re: Windows scheduler: Running a batch file as another user?

On Sun, 9 Mar 2008 00:49:28 +0100, "Pegasus \(MVP\)"
<I.can@fly.com.oz> wrote:

>You must give the user a non-blank password and you must
>set your group policy so that this user can log on as a batch job.


The batch job may be the issue, thanks for that.

Andrew.
Reply With Quote
  #10  
Old 10-03-2008
Bruce Sanderson
 
Posts: n/a
Re: Windows scheduler: Running a batch file as another user?

See
http://technet2.microsoft.com/window....mspx?mfr=true
and
http://technet2.microsoft.com/window....mspx?mfr=true

Keep in mind that the Command Prompt in Windows 2000 and later is not an
emulated DOS environment; it's a native Windows 2000 (or later) command
interpreter window.
--
Bruce Sanderson
http://members.shaw.ca/bsanders

It is perfectly useless to know the right answer to the wrong question.



"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
news:%23Z7Dmv8fIHA.3352@TK2MSFTNGP04.phx.gbl...
> Good questions! The command
> echo %date% > c:\test.txt
> will write the current date into c:\test.txt.
>
> The command
> echo %time% >> c:\test.txt
> will ***add*** the current time to whatever
> is already in c:\test.txt.
>
> The command
> xcopy.exe /.. /.. /.. .. .. 1>c:\test.log 2>c:\test.err
> will write the ***standard*** output from the xcopy
> command into c:\test.log and the ***error*** output
> (if any) into c:\test.err. If you want both outputs in
> c:\test.log then you have to code it like so:
> xcopy.exe /.. /.. /.. .. .. 1>c:\test.log 2>&1
>
> I cannot tell you if and where this might be documented.
>
>
> "JohnB" <jbrigan@yahoo.com> wrote in message
> news:eKHFai8fIHA.3940@TK2MSFTNGP05.phx.gbl...
>>I don't have anything to add to your answer but, I have a general question
>>on your batch file.
>>
>> I've redirected the results of a DOS command to a text file before, and I
>> always used this symbol: ">"
>> But you have a double >
>> I tested it and get the same results with both. Why 2?
>>
>> And, what does this command do: >>c:\test.log 2>>&1
>>
>> I can see that it's again redirecting the output to test.log, but what I
>> don't understand is what follows test.log (2>>&1)
>>
>> Always looking to learn something new ;-)
>>
>>
>>
>>
>>
>> "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
>> news:OvhcoS8fIHA.4140@TK2MSFTNGP04.phx.gbl...
>>>
>>> "Andrew Hodgson" <me3@privacy.net> wrote in message
>>> news:2bf0t3ti8glcacqg48ve0dvbijtolkufcf@news.giganews.com...
>>>> Hi,
>>>>
>>>> I have an account which is in the users and IIS_WPG group. I would
>>>> like this account to run a batch file every hour, however, when I
>>>> schedule the script to run when I am logged in as an account with
>>>> administrator privileges to run under that user, and when I start the
>>>> job, it fails. I can see from the audit log that the user is being
>>>> logged in and out, but it doesn't start. I attempted to run the
>>>> scheduler logged in as the account I wanted the script to run under,
>>>> however, it does not give me access.
>>>>
>>>> So my question is: What are the minimum permissions I need to grant in
>>>> order to let this script run as a scheduled job under the limited
>>>> account?
>>>>
>>>> Thanks.
>>>> Andrew.
>>>
>>> Just because you cannot see the result from your scheduled
>>> job does not mean that it did not run. Try coding it like this:
>>>
>>> @echo off
>>> echo %date% %time% %UserName% >> c:\test.log
>>> "c:\tools\YourCommand.exe" 1>>c:\test.log 2>>&1
>>>
>>> Not schedule this batch file, then check out c:\test.log.
>>> Make sure the account you use for the scheduled job
>>> has a non-blank password.
>>>

>>
>>

>
>


Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Windows scheduler: Running a batch file as another user?"
Thread Thread Starter Forum Replies Last Post
FTP Upload batch file doesn't work properly in Task Scheduler supphavith09 Windows Server Help 1 09-02-2012 07:39 AM
Need batch file to delete user files in Windows XP mcamp32 Windows XP Support 1 26-05-2011 10:54 PM
Shutdown window after running batch file Jaiwanti Operating Systems 4 13-12-2010 06:25 PM
VBscript to run batch file carry on running hokaday Software Development 1 12-02-2010 01:34 AM
Running a batch file from another? Linn Kubler Windows Server Help 2 28-02-2008 09:57 PM


All times are GMT +5.5. The time now is 06:06 PM.