Jump to content

Windows scheduler: Running a batch file as another user?


Recommended Posts

Guest Andrew Hodgson
Posted

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.

Guest Pegasus \(MVP\)
Posted

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.

Guest JohnB
Posted

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.

>

Guest Pegasus \(MVP\)
Posted

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.

>>

>

>

Guest JohnB
Posted

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.

>>>

>>

>>

>

>

Guest Andrew Hodgson
Posted

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.

Guest Andrew Hodgson
Posted

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.

Guest Pegasus \(MVP\)
Posted

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.

Guest Andrew Hodgson
Posted

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.

Guest Bruce Sanderson
Posted

Re: Windows scheduler: Running a batch file as another user?

 

See

http://technet2.microsoft.com/windowsserver/en/library/04969a04-a424-4776-bdc7-dc5066ce79b21033.mspx?mfr=true

and

http://technet2.microsoft.com/windowsserver/en/library/89fdf70e-7d52-4f45-865d-6a61963a3a7e1033.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.

>>>

>>

>>

>

>

×
×
  • Create New...