Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net use fails from scheduled task 2

Status
Not open for further replies.

substitute

Technical User
Oct 19, 2002
152
0
0
GB
I have a batch file which copies a set of files from a Windows 2000 server to another server. The file runs nightly as a scheduled task. The basic procedure looks like:

net use l: /delete
net use l: \\server\share\folder password /user:domain\user /persistent:no
xcopy e:\files l:\ /c/y

I've added stout and stderr redirection to a log file so I know what is happening.

The first time the procedure runs the first command fails "network name cannot be found" (as expected), the second succeeds and the third copies the files.

The next and every subsequent time the first command fails as before, the second fails "the local device name is already in use" and the third fails "Invalid drive specification"

If I change the drive letter (e.g. to M) the next run succeeds and the subsequent ones fail again.

I can run the procedure at any time in an interactive session. I've tried a range of credentials for the scheduled task including administrator. I've added a plain "net use" at the start and it confirms there are no drive mappings.

The procedure worked fine for a year until I rebooted the server 2 weeks ago. No Microsoft updates have been applied for some time.

The reason I map the drive with credentials is that my server isn't in the same domain as the remote server and there is no trust set up (it is against company policy) but the remote share needs to be protected against casual interference by average joe users.

Any ideas out there? I'm losing my hair over this!

Ian
 
Try adding the following between your 2 current net use statements:
net use \\server\share\folder /delete

Or change your first net use statement to be all inclusive:
net use l: \\server\share\folder /delete

I think you are only getting partial removal with:
net use l: /delete

RoadKi11

"This apparent fear reaction is typical, rather than try to solve technical problems technically, policy solutions are often chosen." - Fred Cohen
 
try this one, it is not necessary to use a drive letter:

net use \\server\share\folder password /user:domain\user /persistent:no
REM Check if you have access to the remote folder
if exist \\server\share\folder (
REM here can you write more than one scriptline if you need it
xcopy e:\files \\server\share\folder\ /c/y
echo all files from drive e: have been copied
net use \\server\share\folder /d
) else (
REM here can you write more than one scriptline if you need it
echo You have no access to the remote computer!
net use
)

I make forst the connection to the remote computer, than I check if the remote folder does exist and if so, you can copy your files and afterwards remove the connection. Otherwise you get an error message. You can also use variables for the servername and sharename (plus destination folder) and be more flexable and get more detailed error messages.
 
Both Roadkill and Derpate make useful suggestions - thanks Derpate for pointing out I don't actually need a drive letter and thanks Roadkill for suggesting disconnecting the actual folder as well as the drive letter - I'm trying that one tonight to see if anything happens.

What I've actually done is set up a one-way trust between my server and the corporate network (ie I trust them but they don't trust me - which they've allowed) and I then run the task using my credentials on the remote system. I've also given my remote self permissions to access the local files. That means I don't have to supply any credentials in the batch file, or even map anything.

The weird thing is that the Task Scheduler is apparently still holding on to the earlier drive mappings even though NET USE says it isn't - I can now use DIR L:\ in a scheduled task to get a listing of remote files without mapping L: (as long as the task uses the remote credentials.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top