PDA

View Full Version : Map a Drive for 1 user only (WXP-Pro)



badge
03-17-2006, 06:53 AM
Hello,

Im as new to vbs scripting as one can be but I have gotten this script almost finished. With some help I admit :-) I need to map a drive from XP to Solaris and I have this so far and it works.

Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile


' Values of variables set
strDriveLetter = "X:"
strRemotePath = "\\server\share"
strUser = "name"
strPassword = "whatever"
strProfile = "false"

Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword

set objNetwork= nothing
WScript.Quit

It has to be so the usernames and passwords dont need to be typed in. I put the script into the local group policy logon but the problem is any user who logs on executes the script. I need to have the script run only for the user in strUser = "name"

Hope this makes sense. Thanks in advance for any help.

Mike

Brf
03-17-2006, 07:37 AM
Is this a domain? If so, put that login script into the individual user's profile.

badge
03-17-2006, 07:52 AM
Sorry forgot to mention that. No this is not a domain. I just put the script into

C:\WINDOWS\SYSTEM32 \GroupPolicy\User\Scripts\Logon

and then add it in GP of the local PC

jdharm
03-18-2006, 09:51 AM
What about adding the conditional in bold below:


Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile


' Values of variables set
strDriveLetter = "X:"
strRemotePath = "\\server\share"
strUser = "name"
strPassword = "whatever"
strProfile = "false"

Set objNetwork = WScript.CreateObject("WScript.Network")
If WshNetwork.UserName > strUser Or_
WshNetwork.UserName < strUser Then wScript.Quit

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword

set objNetwork= nothing
WScript.Quit

Josh
<a target="_blank" href=http://www.jdharm.com>www.jdharm.com</a>

badge
03-20-2006, 09:31 AM
I am getting an error relating to 'Then" and code 800A03F9.

I am looking around to see what I can find. I know why the errors coming up, but now I hope I can fix it. Thanks

jdharm
03-21-2006, 04:44 AM
My bad. Tested this on my setup and it worked OK. The difference from your original is in bold.




Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile


' Values of variables set
strDriveLetter = "X:"
strRemotePath = "\\server\share"
strUser = "name"
strPassword = "whatever"
strProfile = "false"

Set objNetwork = WScript.CreateObject("WScript.Network")
Set WshNetwork=WScript.CreateObject("WScript.Network")
If WshNetwork.UserName &gt; strUser Or _
WshNetwork.UserName &lt; strUser Then wScript.Quit

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword

set objNetwork= nothing
WScript.Quit

Josh
<a target="_blank" href=http://www.jdharm.com>www.jdharm.com</a>

badge
03-21-2006, 08:39 AM
Thanks so much. That seems to do exactly what I want it too.

I really appreciate it.

jdharm
03-21-2006, 09:20 AM
No problem.



Josh
<a target="_blank" href=http://www.jdharm.com>www.jdharm.com</a>