Why is this script not mapping my W drive?

Why is this script not mapping my W drive?
Set objNetwork = CreateObject("WScript.Network")
If ucase(objNetwork.ComputerName) = "acsms02" Then
   objNetwork.MapNetworkDrive "F:", "\\acsms01\Tools\Software"
   objNetwork.MapNetworkDrive "w:", "\\acsms02\users\" & objnetwork.UserName
Else
   objNetwork.MapNetworkDrive "F:", "\\acsms01\Data\ds4"
End If

Open in new window

LVL 1
ipcipherAsked:
Who is Participating?
 
tuttlepcConnect With a Mentor Commented:
try that maybe?
1:
2:
3:
4:
5:
6:
7:
8:
 
	
 
Set objNetwork = CreateObject("WScript.Network")
If ucase(objNetwork.ComputerName) = "ACSMS02" Then
strUser = objNetwork.UserName
   objNetwork.MapNetworkDrive "F:", "\\acsms01\Tools\Software"
   objNetwork.MapNetworkDrive "W:", "\\acsms02\users\" & strUser
Else
   objNetwork.MapNetworkDrive "F:", "\\acsms01\Data\ds4"
End If

Open in new window

0
 
tuttlepcCommented:
i would try declaring objnetwork.UserName as a variable and using the variable instead of objnetwork.UserName where you have>> objNetwork.MapNetworkDrive "w:", "\\acsms02\users\" & objnetwork.UserName
0
 
Shift-3Commented:
The problem is that you specified ucase on Line 2 but entered the name in lowercase.  This condition will never be true.

Try changing it to LCase.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
tuttlepcCommented:
doh! i totally missed that one...
0
 
ipcipherAuthor Commented:
So how can i get it to work? I am new to vbscript.
0
 
Shift-3Commented:
On Line 2, "ucase(objNetwork.ComputerName)" takes the computername and converts it to all uppercase letters.  To correct the problem, either change this to "LCase(objNetwork.ComputerName)" or change "acsms02" to "ACSMS02".
0
 
ipcipherAuthor Commented:
I am using this code and i still cant get the W drive mapped when i login to acsms02. Any ideas?
Set objNetwork = CreateObject("WScript.Network")
If ucase(objNetwork.ComputerName) = "ACSMS02" Then
   objNetwork.MapNetworkDrive "F:", "\\acsms01\Tools\Software"
   objNetwork.MapNetworkDrive "w:", "\\acsms02\users\" & objnetwork.UserName
Else
   objNetwork.MapNetworkDrive "F:", "\\acsms01\Data\ds4"
End If

Open in new window

0
 
tuttlepcCommented:
open up my computer
and in the top type in
if you type in \\acsdm02\users\yourusername  

does it work? do you see your files?
0
 
ipcipherAuthor Commented:
Yes i can see my files.
0
 
tuttlepcCommented:
ok, like i was saying b4... you need to do something like this....

Set objNetwork = CreateObject("Wscript.Network")
strUser = objNetwork.UserName
strPath = "C:\Documents and Settings\" & strUser
0
 
tuttlepcCommented:
you're declaring objNetwork.UserName as a variable and using that variable in the path of where you're trying map the drive....

vs trying to obtain the value after the fact... there's a term for it...

so yours would look something like this
strUser = objNetwork.UserName
objNetwork.MapNetworkDrive "w:", "\\acsms02\users\" & strUser

give that a try and let me know if works?


0
 
ipcipherAuthor Commented:
Ok i have modified the code, and doesn't map the w: drive.  I get an error on line 4 char 4 error no network provider accepted the given network path.
Set objNetwork = CreateObject("WScript.Network")
strUser = objNetwork.UserName
If ucase(objNetwork.ComputerName) = "ACSMS02" Then
   objNetwork.MapNetworkDrive "F:", "\\acsms01\Tools\Software"
   objNetwork.MapNetworkDrive "W:", "\\acsms02\users\" & strUser
Else
   objNetwork.MapNetworkDrive "F:", "\\acsms01\Data\ds4"
End If

Open in new window

0
 
tuttlepcCommented:
no, it won't see it unless you put the strUser inside the if statement... i think
0
 
tuttlepcCommented:
why are you using an if statement anyway? take that out... for the time being simplify it...

then go put it back in...
0
All Courses

From novice to tech pro — start learning today.