This document explains how to get a mapped network drive to work within a Windows Agent job. You can use the net use command from within an agent job or add it to an agent environment to use with multiple jobs.
Using the Net Use Command in an Agent Job
If you have only one or two jobs on a Windows server with a mapped drive, you can set the net use command by entering it as the first command of a job:
net use z: \\snap\share1\agent007 /user:agent007 xxxxxxx (where x is the password)
Using the Net Use Command in an Agent Environment
If you are running multiple agent jobs on a Windows server with a mapped drive, we recommend that you create an Agent Environment and use it within your agent jobs.
Create a new Agent Environment Variable using the Robot Schedule Explorer.
On the Properties window, enter the Name, Description, User, Password, Confirm Password, and Working Path that will be used for the signon and the working path.
Create an Environment Variable using the following settings as an example:
Value: mapped & net use z: \\snap\share1\agent007 /user:agent007 xxxxxxx (where x is the password)
If you do not have a password, the settings would be as follows:
Value: mapped & net use z: \\snap\share1\agent007 /user:agent007
The word 'mapped' in the net use command is not important. It just allows you to use the 'net use' command.
You must enter your Windows server username and password in the job command in plain text (or use a reserved command variable). After the Agent Job runs, that information is visible in the Agent job spooled file.
For the duration of that Agent Job, the mapping of the z: drive is valid.
To use the Net Use command in an Agent Environment:
From the Agent Environment Properties window, click Add to create a new Environment Variable.
The Agent Environment Variable Properties window displays.
Set the name and net use command.
Click OK to save the variable.
Setting the Agent Environment in the Agent Job
Once your agent environment is created, you must connect your agent job to it to use the net use command. Do this from the Agent Environment tab of the job’s Job Properties panel.
Select Shared as the Environment Type.
Click the prompt button (...) to select the WINMAPPED Environment. The fields are populated automatically when you select the shared agent environment.
Click OK to save the job.
Disconnecting the Mapped Drives
You should disconnect the mapped drive whenever possible. Disconnect from the mapped drive with the following commands (should be the last two commands for the Agent job):
net use Z: /DELETE
This prevents the shared drive’s server from using all of its allowed connections. This can happen if many Agent Jobs using this Environment run in a short period of time.
You can check the number of connections by logging into the PC that is being shared and opening a command prompt. The 'net session' command shows all of the open inbound sessions. To clear sessions from a particular server, use the following command:
net session \\COMPUTERNAME /DELETE
Testing the Mapped Drive Connection
Use the following procedure to test if your new Agent Environment is connecting to the mapped drive.
Create a .bat file on the Windows server you are connecting to. Name it testfile.bat. The contents of the .bat file should be as follows:
Enter the following commands into an agent job that uses the Agent Environment:
NET USE Z: /DELETE
The first command changes to the z: drive (the mapped drive). The second command runs the testfile.bat file that you created on your z: drive. The third command exits the z: drive so the mapping can be removed. The fourth command ends the mapped drive.
Run the agent job.
If successful, the Agent Log file shows how it executed the commands on the mapped drive (showing the time).