Running a batch file as a scheduled task

G

Guest

I have a batch file on a Windows XP Pro workstation. It uses a mapped drive
to launch a process from the server. It will run successfully as a scheduled
task when a domain user is logged in. I want it to run as a scheduled task at
night when nobody is logged in to the machine. I have tried adding this line
at the beginning of the batch file:
net use u: \\servername\sharename /user:domainname\username password

The scheduled task launches but the batch file does not run. Is my syntax
incorrect, or is it not possible to run a batch file or map a drive when a
user is not logged on? I have set the scheduled task to run with
administrator credentials.

The application we are trying to run requires a drive letter, so UNC won't
work.

Perhaps there is another way to accomplish this? Scripting? Any help is
appreciated. Thanks.
 
P

Pegasus \(MVP\)

Jeff said:
I have a batch file on a Windows XP Pro workstation. It uses a mapped drive
to launch a process from the server. It will run successfully as a scheduled
task when a domain user is logged in. I want it to run as a scheduled task at
night when nobody is logged in to the machine. I have tried adding this line
at the beginning of the batch file:
net use u: \\servername\sharename /user:domainname\username password

The scheduled task launches but the batch file does not run. Is my syntax
incorrect, or is it not possible to run a batch file or map a drive when a
user is not logged on? I have set the scheduled task to run with
administrator credentials.

The application we are trying to run requires a drive letter, so UNC won't
work.

Perhaps there is another way to accomplish this? Scripting? Any help is
appreciated. Thanks.

You can easily find out what's wrong with your command line, by doing this:

Line1 @echo off
Line2 echo %date% %time% Start of task > c:\test.log
Line3 echo User=%UserName%, Path=%path% >> c:\test.log

Line4 net use u: \\servername\sharename /user:domainname\username password
1>>c:\test.log 2>c:\test.err
Line5 echo %date% %time% End of task >> c:\test.log

Now examine the two log files and all will become clear.

Using your type of coding poses a severe security risk. A far
better way would be to schedule the task under the user/password
account that you currently use in the batch file. If you do then you
won't need Line4 at all.
 
G

Guest

Thank you for the reply. I will have a chance to try it next week.
Yes, I am aware of the security risk, and am not really happy about doing it
that way. As I understand your response, all I need to do is indicate the
username and password in the scheduled taks settings, and this will will
enable the network drive to be mapped, even though nobody is logged into the
workstation. So far that hasn't worked. I will try the diagnostics you
suggest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top