Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently use a batch script to mount my network shares each morning:

NET USE Z: \\<IP>\<SHARE> <AUTHENTICATION> /persistent:no

Which is fine when I'm on the network, but doesn't work off-site. We have a domain which points to our public IP, and then port forwarding kicks in, so in theory, I can

NET USE Z: \\\<SHARE> <AUTHENTICATION> /persistent:no

Except that doesnt work in the batch script or windows UI.

I'm thinking there'd be a way to get the IP of (which is conveniently also stored at but there's well outside my experience of batching.

Any input much appreciated.

share|improve this question
Um, why not just change the end part to /persistent:yes? and not map your drives every day. – Spencer5051 Jul 25 '13 at 1:31
You're allowing SMB in from the internet?! That's brave. – afrazier Jul 29 '13 at 17:01
up vote 1 down vote accepted

The task is a little bit easier by using PowerShell since you have the full power of the .Net framework at your disposal. There is a class called System.Net.WebClient that can be used to download a file and get its contents. You can use a PowerShell script similar to the one below to retrieve the contents of the ip.txt file and then execute your cmd.exe commands.

$fqdn = "fqdn domain name goes here"
$url  = "http://$fqdn/ip.txt"

$fqdnIp = (new-object System.Net.WebClient).DownloadString($url)

Write-Host -ForegroundColor Green "Retrieved contents of ${url}: $fqdnIp"

$cmd = "`"NET USE * /DELETE /Y`""
&cmd.exe /c $cmd

$cmd = "`"NET USE Z: \\$fqdnIp\<SHARE> <AUTHENTICATION> /persistent:no`""
&cmd.exe /c $cmd
share|improve this answer
PERFECT! Thank you for actually answering my question! – LuckySpoon Jul 30 '13 at 8:50

Just because you can go to the website at, that does not give you access to your internal network or internal domain. Port 80 is the standard port for HTTP (websites) which is being forwarded from the public IP to your internal web server. However, with maybe a few other exceptions, that's all that's allowed through.

To access your internal network and resources, you need a virtual private network (VPN). A VPN is a secure (encrypted) connection from the Internet to your internal network. VPNing allows a computer outside your internal network to "feel" as if it is inside.

Once you have established a VPN connection, your batch script will work. You can access internal network drives and printers, and do anything you could do while in the office.

Microsoft offers a free VPN server with all versions of Windows Server and the client is built into all version of Windows. There are other VPN solutions out there as well, both hardware and software, both free and paid.

Talk to your Windows/network administrator, there may be a VPN already in place.

share|improve this answer
I think I may have not made my question clear - ports are all forwarded etc. My point is - if I can get the IP address that resolves to inside my batch script, all is fine. – LuckySpoon Jul 24 '13 at 9:08

your scripts should work, except that you should check 4 things

  1. Is DNS working? try to verify it on your offsite machine by ping.
  2. try to disable WINS on your off-site client.
  3. Did you forward all the required ports ? try to put the server at DMZ host and see if that works.

    if the public ip does not change, then simple hard code it into your systems32\etc\hosts.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.