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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server specific login script for network drives

Status
Not open for further replies.

cpaunescu

Technical User
Jul 24, 2013
10
Hello,

Im trying to put together a script that would allow our users to execute it, IF, they login to a specific server, otherwise, do not run.
Example:

User A logon to P-Web-Server01
DO NOT run script
User A logon to P-RDS-Sessionshostfarm
Run script and map network drive.

I have this so far, and will not work:
strDriveLetter = "X:"
strRemotePath = "serverA"

set objNetwork=CreateObject("wscript.network")
if objNetwork.computername="P-RDS-sessionhostfarm" then
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, false, gt, pass
end if

Where is my script wrong? What am I doing wrong?

Thanks...
 
Thru Remote Session. Remote Desktop Connection.

What I want is for the users to be able to map the drive when they remote into the server, but when they logon to their desktops, not to map those drives.
Hope I explained it good.
 
- Are you sure the script is being run?
- When mapping a network drive strRemotePath should be in the format of "\\server_name\share$", not just "server_name".
- Where are [tt]gt[/tt] and [tt]pass[/tt] defined?
- What does [tt]msgbox objNetwork.ComputerName[/tt] display?
- Do you have [tt]on error resume next[/tt] in your script above the code you posted? It suppresses any errors and wouldn't alert you to the problem.

-Geates

 
If I run this, it works, it maps X drive, but its not server specific.

strDriveLetter = "X:"
strRemotePath = "server"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, false, gt, pass

But when I run my original script, that calls for a specific server, it wont work. It will not map the drive.

My script consists of what you see above, (and the original thread). I do not have any gt or msgbox. Just what you see. Im not a programmer, just trying to fix an issue we having.
What would you suggest I could use? OR how can I change that script to give me what I need?

Thanks....
 
You might be seeing an old mapping - a drive cannot be mapped to just a computer, it has to be mapped to a share (folder or drive) on that computer. For instance, if you wanted to map X: to the C:\ drive pon "serverA", you code would look like this "\\serverA\c$".

-Geates


 
To repeat what Geates asked, what does msgbox objNetwork.ComputerName display? Or better yet, add some debug code so you know what is going on:

Code:
if objNetwork.computername="P-RDS-sessionhostfarm" then
   objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, false, gt, pass
   msgbox "Drive was mapped"
else
   msgbox "Drive not mapped for computer " & objNetwork.computername
end if
 
Just an additional thought, why not just write a genaric script that mapps the x: drive regardless and apply it via a gpo or local policy on that server. Just eliminate the conditional statement. Just an idea...

Windows Haiku:

Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
 
In my experience, GPOs are a little unreliable and it doesn't make sense to make a policy for single computer. However, a local policy or a constant mapping is a good idea.

-Geates

P.S. I like the haiku in your signature, w33mhz (33Mhz was the speed of *my* first computer. I accidentally and permanently UNDERclocked it to 3.3Mhz [banghead])

 
Have to disagree, a GPO would be perfect for this scenario, but I don't know if that's an option for the OP
 
>GPOs are a little unreliable

Have to say I'm with guitarzan here. The only problems I've ever had with Group Policy is if a policy is misconfigured (or misunderstood ... Administrative Templates, the old NT4 way of doing group policies, can sometimes catch people out because of the way that they work and exactly when they get applied and, often more importantly, removed... - but again, that isn't unreliability, just understanding ...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top