NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.
Forum Discussion
THN
Dec 29, 2008Aspirant
Script to Connect to Network Drive
Good Day all,
I've gleaned so much information from these posts, that I thought it's time for me to contribute something, as well. So, here we go:
I have created a little vbscript, which can be run from the start up folder in the start menu, or simply be executed with a shortcut on your desktop. As far as I know, this will only work on the Windows platform.
Enjoy.
I've gleaned so much information from these posts, that I thought it's time for me to contribute something, as well. So, here we go:
I have created a little vbscript, which can be run from the start up folder in the start menu, or simply be executed with a shortcut on your desktop. As far as I know, this will only work on the Windows platform.
strLocalDrive = "N:" '<<< Change this to fit your needs.
strRemoteShare = "\\nas-server\Data" '<<< Change this to fit your needs. nas-server could also be an IP address.
Set objNetwork = WScript.CreateObject("WScript.Network")
on error resume next
objNetwork.RemoveNetworkDrive strLocalDrive
on error goto 0
EFlg="set"
While EFlg="set"
strPer = "FALSE"
strUsr = InputBox("Please enter your NAS User Name", "User Name")
strPas = InputBox("Please enter your NAS Password", "Password")
On Error Resume Next
If strUsr="" or strPas="" Then
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer
Else
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
End If
If Err.Number<>0 Then
EFlg="set"
' MsgBox Err.Description
Else
MsgBox "Connected " & strRemoteShare & " successfully to " & strLocalDrive '& ":"
EFlg=""
End If
Wend
Enjoy.
18 Replies
- bbaraniecLuminaryJust a question, why would you need a script to map network drive in windows?
- dbott67GuideI think it's because Windows does not always connect mapped network drives on bootup (mine frequently say "Disconnected" after a reboot). The script will force the mapped drive to be in a connected state (I think).
-Dave - THNAspirantDave is correct. This is supposed to be used as a logon script. If user A logs in, he maps folder 1 to drive N, while user B would map folder 2 to Dive N.
- Zaphod1AspirantI just use a batch file to do this.
- jamesd11AspirantI encountered the same problem that many users have reported about Windows not reconnecting a network drive at login. I have Windows XP Home edition, and mapped two network drives to two shares on my ReadyNAS NV+. The shares have a username that's different from the usernames on the XP box. Even though I checked the "Reconnect at logon" box, Windows would not reconnect the drives when I logged in later. According to this posting on an outside forum:
http://techrepublic.com.com/5208-6230-0.html?forumID=102&threadID=208564&messageID=2152515
XP Home edition does not cache user credentials for network resources. I confirmed this by checking the help for the "net use" command:
C:\>net help use
The syntax of this command is:
NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
[/USER:[domainname\]username]
[/USER:[dotted domain name\]username]
[/USER:[username@dotted domain name]
[/SMARTCARD]
[/SAVECRED]
[[/DELETE] | [/PERSISTENT:{YES | NO}]]
NET USE {devicename | *} [password | *] /HOME
NET USE [/PERSISTENT:{YES | NO}]
NET USE connects a computer to a shared resource or disconnects a
computer from a shared resource. When used without options, it lists
the computer's connections.
...
/SAVECRED Specifies that the username and password are to be saved.
This switch is ignored unless the command prompts for username
and password. This option is not available on Windows XP
Home Edition and will be ignored.
Apparently, this applies to other Windows editions as well. For example, the FAQ for Windows XP Media Center Edition 2005 states:Can I connect a new PC running Windows XP Media Center Edition 2005 to a work network or domain?
While you can access network resources on a work network or a domain, you cannot join a Windows XP Media Center Edition 2005 PC to the domain. PCs running Windows XP Media Center Edition 2005 are designed specifically for home use. Windows XP Professional features, specifically Domain Join and Cached Credentials (Credentials Manager for logons) are not included. As a result, you will be prompted for your logon user name and password to access network resources after you reboot or log back on to the PC. ...
I didn't try the VBS script that THN provided above (but thanks for posting it). Instead, as a workaround, I followed Zaphod's example and created a command script:
C:\Documents and Settings\All Users\Start Menu\Programs\Startup>type NAS-shares.cmd
@echo off
set NASname=...
set NASuser=...
set NASpass=...
echo Setting persistence option for network drives ...
net use /persistent:no
echo Connecting network drives Z: ...
net use z: \\%NASname%\backup /user:%NASuser% "%NASpass%"
echo Connecting network drive U: ...
net use u: \\%NASname%\users /user:%NASuser% "%NASpass%"
I placed the script in All User's Startup folder so that it runs for everyone who uses the computer. - sponderAspirantcan't help myself but stating the obvious here:
for the ones with a windows Domain:
You can set logon scripts in the active directory, so you won't have to manage the scripts on the clients. (handy for when you have a lot of clients..) - lordoflardAspirantJust to add my two penn'orth...
If you're using a batch file like jamesd and you have a number of shares to map, you can issue the command:net use \\%NASname% /user:%NASuser% "%NASpass%" /persistent:no
then each share is connected using something of the form:net use Z: \\%NASname%\ShareName
which will save, ooh, a second or so of typing or copy & pasting. I've found this method of connecting as the user before attempting to map drives to be slightly more reliable in an office of mixed Windows versions.
Of course, if you don't want to include the user's password in a plaintext script, omit the "%NASpass%" and a password prompt will appear in the command window.
The Lord of Lard - daztrueAspirantI've had this thread referred to me, which may be of help (and I do want to map shares etc.), but I just wondered if any of you have come across (or can solve :lol: ) the following symptoms:
Typically(!), the icon for my NAS (as a device), along with icons for add-ons all appear, along with the blue icons for my wireless laptop and (if on) my main PC. However, the blue icon for my NAS hasn't displayed for ages. It's usually fine on my wired PC (although there's been the odd moment), and I've tried so many options. I've even had long phone consultations with Netgear, whose engineers have tried to resolve the issue.
I can easily make the blue icon appear (and thus access the NAS) by entering the IP, but it won't automatically appear with its hostname. :evil:
Batch file:
@lordoflard (or whoever wants to add another two penn'orth!) Does your post mean the batch file would look like this:net use \\%NASname% /user:%NASuser% "%NASpass%" /persistent:no
net use Z: \\%NASname%\ShareName
...with the second line used for each share/folder mapped? And that would be it?
And not to appear thick (just safe!), :roll: do I take it that batch files would be stored in the following as relevant?
C:\Users\<user>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
VBScript:
@THN @dbott67 I did a 'bit' of VB once and so am able to fumble-read the script, but want to confirm: would separate .vbs files still be necessary for each Windows account as well as each mapped share? If so, how does this differ from the batch file option? - dbott67GuideCan you post a screen shot of which icons you're referring to and where you expect to see them (desktop, network neighbourhood, etc.). For example, this is what appears in my "Network" in Windows 7 Pro:
I've also got shortcuts on the Desktop for my Pro (Prometheus), NVX (Envious) and Duo (Devious): - daztrueAspirantNot sure how I can printscreen an icon that isn't there! :o
But to answer: just like the icons at the top of your screenshot, I expect to see one of my NAS there (Network) in Vista Ultimate x64.
Like yourself I have 2 media icons: Skifta and Orb.
1 icon for my NAS as a device (bottom of screenshot).
As for the Desktop: currently nothing setup but I previously attempted regular shortcuts to shares, only to find they were deleted each time I logged onto that Windows account, or whenever doing maintenance on PC.
From what I've read (as well as your screenshot), I realise it'll have to be one or more of the following: mapped drive, batch or VBScript file.
Related Content
NETGEAR Academy

Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology!
Join Us!