NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.

Forum Discussion

THN's avatar
THN
Aspirant
Dec 29, 2008

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.



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

Replies have been turned off for this discussion
  • Many 'hostname' resolution issues can be resolved by setting the NAS to be the WINS server. I've got my Pro set as the primary WINS server for all devices on my home network and never have issues connecting to any of my NASes. Have a look at this how-to:

    http://home.bott.ca/webserver/?p=217

    I don't have any scripts or batch files on my Windows 7 computer... it's just using the above mechanism for WINS name resolution and all shortcuts in "network" automatically appear. The desktop shortcuts were just created by right-clicking the device in "network" and selecting "Create Shortcut".
  • Wow, can't wait to try this, but from reading your link, combined with my checking my settings and thinking about my setup, my head began to buzz with questions! :idea: :idea:

    1) Just as I have DHCP set up on my router (ProSafe SRXN3205), rather than NAS, I wondered if the same was possible for WINS. The Primary DNS Server is the router's LAN IP, so is the same possible for WINS? The SRNXN3205 manual states:

    By default, the VPN firewall [SRXN3205] will function as a DHCP (Dynamic Host Configuration Protocol) server, allowing it to assign IP, DNS server, WINS Server, and default gateway addresses to all computers connected to the LAN.

    Also...
    The VPN firewall will deliver the following settings to any LAN device that requests DHCP:...
    • WINS server (if you entered a WINS server address in the DHCP section of the LAN Setup screen).


    2) In Network Connections > Properties my DNS tab (like the WINS tab) shows no addresses, yet Network Connection Details shows the router LAN IP for IPv4 DNS Server. Does this sound right, and if so, could putting the LAN IP in the DNS tab have the same effect as your page?

    3) Network Connection Details already shows NBT as enabled, so could simply following your purge instructions alone rectify resolution problems (even though I'll still set up WINS for shortcuts!)?
  • daztrue wrote:
    1) Just as I have DHCP set up on my router (ProSafe SRXN3205), rather than NAS, I wondered if the same was possible for WINS. The Primary DNS Server is the router's LAN IP, so is the same possible for WINS? The SRNXN3205 manual states:

    By default, the VPN firewall [SRXN3205] will function as a DHCP (Dynamic Host Configuration Protocol) server, allowing it to assign IP, DNS server, WINS Server, and default gateway addresses to all computers connected to the LAN.


    No problem having the firewall/router/whatever acting as DHCP server, DNS, etc. If the firewall allows for setting WINS server, just use the IP address of the NAS and when a client requests an IP from the DHCP server, all appropriate options (IP, subnet, gateway, DNS, WINS, etc.) will automatically get configured.

    All you need to do is:

    1. Enable WINS on the NAS (step #1 on my how-to. you can skip step #2 on my how-to, as your firewall can assign WINS automagically).
    2. Configure firewall's DHCP server to assign WINS server for each client (using IP of NAS). No need to change anything else. DNS will remain IP of firewall.
    3. Release & renew IP address on each client, followed buy purge:

    ipconfig /release

    ipconfig /renew

    nbtstat -R
  • dbott67 wrote:
    3. Release & renew IP address on each client, followed buy purge:

    Thanks for syntax tips! :thumbsup: But why is the release and renew necessary when it wasn't at client level, and why isn't this dealt with at LAN level? I'm specifically thinking about how I've currently got some IPs reserved within DHCP pool, being used by clients.

    dbott67 wrote:
    1. Enable WINS on the NAS (step #1 on my how-to. you can skip step #2 on my how-to, as your firewall can assign WINS automagically).

    Even easier. Great! :) But I was actually wondering whether it was possible for the router itself to be the WINS server, rather than the NAS. If not, no problem; I'm just curious as ideally the router is obviously the centre of the LAN, and the Primary DNS Server uses the router/LAN IP, so I wondered if the WINS Server could do the same. :?:
  • daztrue wrote:
    But I was actually wondering whether it was possible for the router itself to be the WINS server,


    The router likely does not have the capability to perform WINS built-in (most do not). In fact, most don't even have DNS capabilities --- they merely forward the DNS request to the upstream (ISP) DNS server.

    daztrue wrote:
    If not, no problem; I'm just curious as ideally the router is obviously the centre of the LAN, and the Primary DNS Server uses the router/LAN IP, so I wondered if the WINS Server could do the same.


    The router is acting as the central point, however, it forwards WINS requests to the NAS to perform the lookup.

    daztrue wrote:
    But why is the release and renew necessary when it wasn't at client level,


    The DHCP settings are sent to the client during boot. The renew & release is required merely to update the computer's DHCP-assigned settings (specifically, the addition of the WINS server). You could also just reboot the PC, but the release/renew/purge is quicker.

    daztrue wrote:
    I've currently got some IPs reserved within DHCP pool, being used by clients.


    If they are "static" reservations (i.e. the IP addressed is reserved in the DHCP by MAC address of client), then the same release/renew commands will update the DHCP settings to include the WINS server address. The purge (nbtstat -R)will flush any cached addresses and force the client to request new ones from the WINS server.
  • PS - I mistyped the switch in the nbtstat command. It should be:

    nbtstat -R


    (I had originally type /R)
  • Followed how-to 1; set up WINS on router with NAS IP; released, renewed, purged; rebooted, but no change.

    net view only displayed PC in use (NAS & router only other devices on).

    I even checked some other settings (new router) and enabled UPnP, successfully pinged the NAS, but it made no difference. And the reserved IP settings in the DHCP pool for the devices are the same. Could this be the reason? These settings are in LAN Groups, so (I think) if I delete them from there would it help? If so, should I still leave the NAS listed (see below)?

    dbott67 wrote:
    If they are "static" reservations (i.e. the IP addressed is reserved in the DHCP by MAC address of client), then the same release/renew commands will update the DHCP settings to include the WINS server address. The purge (nbtstat -R)will flush any cached addresses and force the client to request new ones from the WINS server.

    The NAS was/is set up with a static IP, and configured on the router/firewall as static. Its IP is outside of DHCP server pool.
  • I was having this same problem with my previous router (although not originally), and I'm not convinced that it's a router issue. For example, in addition to not being able to view the NAS on my wireless laptop (without entering IP, although since WINS, I can now enter \\hostname), I'm also unable to access the laptop from my wired PC, even though the laptop can access the PC! :?

    After a lot of attempts with a Netgear engineer on the phone with my previous router we discovered that when I connect my laptop to the router by Ethernet it recognises the NAS with no problems.

    :evil: :evil: :evil: :evil:

    Can you think of any other possible reasons for these symptoms? And could the fact that the NAS IP is outside of the DHCP pool be anything to do with WINS not appearing to resolve the symptoms?

    I also mentioned previously that the laptop's Network Connection Details updated according to router settings, yet DNS and WINS settings (especially IP) don't display in their respective tabs in Network Connection Properties. Is this right?

    Network Connection Details (NCD) showed the LAN IP as the Primary DNS Server, obviously as a default as there isn't actually anything entered in that field on the router. I entered the IP (hoping it would resolve issues), only to find NCD showing the same IP twice - so I reversed the setting. :cry:

NETGEAR Academy

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

Join Us!

ProSupport for Business

Comprehensive support plans for maximum network uptime and business peace of mind.

 

Learn More