search
top

Using Computer Startup Scripts to Map Drives in Windows 2008 R2

Sometimes there are instances in which you need to map drives on specific servers and not all. One of the ways to accomplish this is through the use of startup scripts defined in local policy. For this need I just needed a server to map to another server resource, the G:\ drive in particular.

Applies To: Windows 7,  Windows Server 2008 R2

Create the cmd script to contain the net use command to connect. In this example I am clearing anything on G, waiting 5 seconds and then connecting to my server using domain user id and password. I am saving the file in a directory I use for scripts, c:\support\scripts and calling it mapg.cmd.

net use g: /delete
sleep 5
net use g: \\myserver\g$ /user:domain\userid "password"

Now to assign computer startup scripts

Open the Local Group Policy Editor. (Run > mmc > File > Add or Remove Snap-ins > Select Group Policy Object Editor. Click OK to accept Local Policy and click OK.)

In the console tree, click Scripts (Startup/Shutdown). The path is Computer Configuration\Windows Settings\Scripts (Startup/Shutdown).

In the results pane, double-click Startup.

In the Startup Properties dialog box, click Add.

In the Add a Script dialog box, do the following:

  • In the Script Name box, type the path to the script, or click Browse to search for the script file in the Netlogon shared folder on the domain controller.
  • In the Script Parameters box, type any parameters that you want, the same way as you would type them on the command line. For example, if your script includes parameters called //logo (display banner) and //I (interactive mode), type //logo //I.

In the Startup Properties dialog box, specify the options that you want:

  • Startup Scripts for <Group Policy object>: Lists all the scripts that currently are assigned to the selected Group Policy object (GPO). If you assign multiple scripts, the scripts are processed in the order that you specify. To move a script up in the list, click it and then click Up. To move a script down in the list, click it and then click Down.
  • Add: Opens the Add a Script dialog box, where you can specify any additional scripts to use.
  • Edit: Opens the Edit Script dialog box, where you can modify script information, such as name and parameters.
  • Remove: Removes the selected script from the Startup Scripts list.
  • Show Files: Displays the script files that are stored in the selected GPO

Right click on Startup and select Properties, click Add and click browse and navigate to the script containing the net use command you would like to use.

Click OK to save the changes and reboot the server to test the drive mapping.

Fairly simple to implement and you can expand on the use in other areas. For my part it resolved an issue I tasked it for and was easy to implement.

 

5 Responses to “Using Computer Startup Scripts to Map Drives in Windows 2008 R2”

  1. I’m not sure where you are getting your info, but great topic. I needs to spend some time learning much more or understanding more. Thanks for wonderful info I was looking for this info for my mission.

  2. John says:

    How does this authenticate?

    • newlife007 says:

      In the script you create to connect the drive you pass the credentials to connect. net use g: \\myserver\g$ /user:domain\userid “password” You change the doamin\userid “password” values.

  3. Michael says:

    I learned a lot in this article. This works great in Windows 7 too. I just had to remove the “$” from the drive letter, or I would get error 53 – path not found. So this works in Win7: NET USE “\\localhost\c\…” Also, Windows 7 does not support SLEEP you give in your example. That seems to be no problem. Thanks!

  4. Michael says:

    The SLEEP and other useful utilities can be found in here. “https://www.microsoft.com/en-us/download/details.aspx?id=17657” It is part of the rktools.exe for Windows Server 2003. I simply copied the tools I needed/wanted to the Windows\System32 folder.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

top