Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mapping drives based on remote server location

Status
Not open for further replies.
Jan 11, 2008
67
US
hello all,

I am tring to figure out the best way to dynamically map drives to my machine based on which remote server I'm connected to.

Example:
*I'm at my desk. I would like to create a logon script to automatically create a mapped drive "Y:" for me to the local servers shared folder.
*If I remote to server X. I would like to have the logon script automatically replace my currently mapped Y: drive and replace it with a mapped drive on the remote server using the same Letter Y:
*When I log out the remote server X. The mapped drive should revert back to a local server mapped drive I had before I logged into the remote server.

would this work or is there a better way...thank you!

IF LOGONSERVER=local server GOTO A

GOTO B

:A
NET USE Y \\localserver\sharedFoler

GOTO END

:B
NET USE Y \\%LOGONSERVER%\SharedFolder

GOTO END

:END

Thanks again all help is appreciated!!!




 
Something like this. (No guarantee for other complications.) Uncomment the echo to discover the trouble spots.
[tt]
dim ssharename, slogonserver
'given
ssharename="sharefolder"

slogonserver=createobject("wscript.shell").environment("process")("logonserver")

set wshnetwork=createobject("wscript.network")
on error resume next
wshnetwork.removenetworkdrive "y:", true, false
if err.number<>0 then
'wscript.echo "[1] " & hex(err.number) & vbcrlf & err.description
err.clear
end if
wshnetwork.mapnetworkdrive "y:", slogonserver & "\" & ssharename, false
if err.number<>0 then
'wscript.echo "[2] " & hex(err.number) & vbcrlf & err.description
err.clear
end if
on error goto 0

set wshnetwork=nothing[/tt]
 
Thanks Tsuji! I'm very new to scripting so this is nothing like I thought.

how would I set this up to run each time I login to a server? I know for logon scripts their placed in GPO but what about this one?

Thanks.
 
Also consider using DFS. Might be easier to have a simple login script that connects you to the DFS share and let DFS connect you to the local server.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Refer to my FAQs on the subject.
faq329-5908
faq329-5798

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top