Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Group policy??

I'm trying to write a Login script to map network drives I was wondering ig someone could give an example to look at to see why mine wont run!
1 Solution
To map a network drive at startup just use the NET USE command in your script. Here's an extract from the MS Help for this.

Net use
Connects a computer to or disconnects a computer from a shared resource, or displays information about computer connections. The command also controls persistent net connections.

net use [devicename | *] [\\computername\sharename[\volume]] [password | *]] [/user:[domainname\]username] [[/delete] | [/persistent:{yes | no}]]

net use devicename [/home[password | *]] [/delete:{yes | no}]

net use [/persistent:{yes | no}]



Used without parameters, net use retrieves a list of network connections.


Assigns a name to connect to the resource or specifies the device to be disconnected. There are two kinds of device names: disk drives (D: through Z:) and printers (LPT1: through LPT3:). Type an asterisk instead of a specific device name to assign the next available device name.


Specifies the name of the server and the shared resource. If computername contains blank characters, enclose the entire computer name from the double backslash (\\) to the end of the computer name in quotation marks (" "). The computer name may be from 1 to 15 characters long.


Specifies a NetWare volume on the server. You must have Client Service for NetWare (Windows 2000 Professional) or Gateway Service for NetWare (Windows 2000 Server) installed and running to connect to NetWare servers,


Specifies the password needed to access the shared resource.


Produces a prompt for the password. The password is not displayed when you type it at the password prompt.


Specifies a different user name with which the connection is made.


Specifies another domain. For example, net use d:\\server\share /user:admin\mariel connects the user identifier mariel as if the connection were made from the admin domain. If domainname is omitted, the current logged on domain is used.


Specifies the user name with which to log on.


Cancels the specified network connection. If the user specifies the connection with an asterisk, all network connections are canceled.


Connects a user to the home directory.


Controls the use of persistent network connections. The default is the setting used last. Deviceless connections are not persistent.


Saves all connections as they are made, and restores them at next logon.


Does not save the connection being made or subsequent connections. Existing connections are restored at the next logon. Use the /delete switch to remove persistent connections.

Here's how you do it using VBScript and WSH.  The following code maps H: to a specific user's home directory on the server and maps G: to a shared folder on the server.  If the username doesn't match the user's home directory then H: will be mapped to the root of the Users folder so the user can browse for their home directory.

<------Begin Code------>

'The following line will force the script to continue running in the event of an error.
on error resume next

Dim oNet, sUser, cInitial, startTime

'Here you're creating a Windows Script Host Network
'Object.  This object has methods and properties that will
'allow you to determine username and map network drives.
Set oNet = CreateObject("WScript.Network")
' Get the user name. On Windows 9x, the use may not be logged
' on when the script starts running; keep checking every 1/2 a
' second until they are logged on.
sUser = oNet.UserName
startTime = Now

Do While sUser = ""
   If DateDiff("s", startTime, Now) > 30 Then Wscript.Quit
   Wscript.Sleep 500
   sUser = oNet.UserName

'The RemoveNetworkDrive method below is used to force the
'removal of an previous drive mappings for h: and g:.
oNet.RemoveNetworkDrive "h:", True, True
oNet.RemoveNetworkDrive "g:", True, True

'The following two lines map h: and g:.
'Since I specified <b>on error resume next</b>, if there's
'an error because \\Server\Users\UserName doesn't exist
'the next line will be executed and no error message will
'be displayed.
oNet.MapNetworkDrive "h:", "\\Server\Users\" & sUser
oNet.MapNetworkDrive "g:", "\\Server\Shared"

'If the previous mapping for h: was successful, then this
'following line will produce an error, but on error
'resume next will handle that for us.  If the previous
'mapping was NOT successful, then h: will be mapped to
oNet.MapNetworkDrive "h:", "\\Server\Users"

<------End Code------>

This is a working login script, just cut and paste it into a text file and save it with a .vbs extension.  Change <b>Server</b> to your server name and <b>Users</b> and <b>Shared</b> to your network shares and you're good to go.

Hope this helps.
Jayman07Author Commented:
Great help thank you so much

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now