Open Shared Folder according to IP Address?

November 23, 2010 at 07:14:42
Specs: Windows XP
I'm trying to write a script to open a shared folder on a workstation that has the same first two octets of the IP address. This way users in different locations find a workstation with the first two octets the same as their own. (The last two octets --0.100-- are fixed on the local workstation.) This is because, for us, the first two octets (or really just the second) indicates the physical location. The idea is that we can load large files to this folder overnight, and then users could quickly open these files during business hours from the local folder.

I've put together the script below, but for some reason, it only works on the computer I wrote it on. On other computers it fails at the last command, doing nothing. I've also tried this with the command iexplore.exe instead of explorer.exe, and it just opens a web browswer to the homepage. However, even this works on the original computer.

This will need to work on different computers, including XP, Win7, and Vista. Any help in finding out what I can fix would be greatly appreciated.

ipconfig | find "IP Address" > ~ip1.txt
for /f "tokens=1-2 delims=:" %%i in (~ip1.txt) do echo %%j > ~ip2.txt
for /f "tokens=1-3 delims=." %%i in (~ip2.txt) do echo %%i.%%j.0.100 > ~ip3.txt

setLocal EnableDelayedExpansion
set /p var=<~ip3.txt
set var=!var:~1,12!

start explorer.exe \\!var!\open

See More: Open Shared Folder according to IP Address?

Report •

November 23, 2010 at 08:52:19
Nevermind. In case anyone needs it, here's the solution.

@ echo off
for /f "tokens= 1-10 delims=[]." %%a in (
'ping -n 1 "%computername%" -4 ^|find "[" ') do (
echo trying %%d.%%e.0.100
start \\%%d.%%e.0.100\open

Report •
Related Solutions

Ask Question