'net use' Command Works From Command Line But Not as Scheduled Task

  • Thread starter Thread starter IF
  • Start date Start date
I

IF

Hi,

On Win2000, I wrote a script which uses the command 'net use
<drive> \\server\share /user:<username> <password> /persistent:no',
and copies some files to that drive. The script works successfully
when it is executed by a specific user from the command line.

However, 'net use' fails when executed as a command in a
scheduled task for the same user.

The advanced log in the task scheduler indicates that the job failed
with a return code of 2.

I tried ending the 'net use' command with a redirect to an output file
(net use... > output), but no information was available in that file.

Then, I added the command 'set > env_variables' to the script. The file
'env_variables' was created, and the environment variables are
exactly the same for the user as in foreground.

Thus, given that the 'net use' command works in foreground, and that
the scheduled task executes and displays the correct environment
variables, why does the 'net use' command fail in background?
Any ideas would be greatly appreciated.

Also, is there any way for me to get more detailed information in the
Advanced Log of the Scheduled Tasks, or through other means?


Thanks,
IF
 
I'll take a guess: when it runs in the background it is runs as a user
who lacks Administrator capabilities.
 
In
IF said:
Hi,

On Win2000, I wrote a script which uses the command 'net use
<drive> \\server\share /user:<username> <password> /persistent:no',
and copies some files to that drive. The script works successfully
when it is executed by a specific user from the command line.

However, 'net use' fails when executed as a command in a
scheduled task for the same user.

The advanced log in the task scheduler indicates that the job failed
with a return code of 2.

I tried ending the 'net use' command with a redirect to an output file
(net use... > output), but no information was available in that file.

Then, I added the command 'set > env_variables' to the script. The
file 'env_variables' was created, and the environment variables are
exactly the same for the user as in foreground.

Thus, given that the 'net use' command works in foreground, and that
the scheduled task executes and displays the correct environment
variables, why does the 'net use' command fail in background?
Any ideas would be greatly appreciated.

Also, is there any way for me to get more detailed information in the
Advanced Log of the Scheduled Tasks, or through other means?


Thanks,
IF

What account is the scheduled task running under? It needs to be one that
has sufficient network privileges, (not local system, etc)

Also, what's the real goal here? Mapped drives are for the convenience of
people, not computers. If you have something that needs to run w/o any
logged in user's interaction, use a UNC path.
 
Hi IF,
I tried it myself and it works well, may be you could try not adding the
username and password in the batch file, rather you can specify it on the
schedule properties.
and also try deleting the drive letter before.

Like

@echo off
net use <driveLetter> /delete
net use <drive> \\server\share /persistant:no
OR
may be you can use a user account specifically for this, who has a logon as
a batch job right

Regards
kiran
 
Back
Top