Link to home
Start Free TrialLog in
Avatar of aclaus225
aclaus225

asked on

Script is being strange

I have this script:
Set objNetwork = CreateObject("WScript.Network")
 Set objUser = CreateObject("ADSystemInfo")
 Set objCurrentUser = GetObject("LDAP://" & objUser.UserName)
Set objFSO = CreateObject("Scripting.FileSystemObject")
 If IsArray(objCurrentUser.MemberOf) Then
  strGroup = LCase(Join(objCurrentUser.MemberOf))
Else
  strGroup = LCase(objCurrentUser.MemberOf)
End If

If InStr(strGroup, lcase("CN=Users")) Then
If objFSO.DriveExists("O:") = False Then objNetwork.MapNetworkDrive "O:", "\\wscalfs\Company"
End If

 If InStr(strGroup, lcase("CN=Development")) Then
 If objFSO.DriveExists("W:") = False Then objNetwork.MapNetworkDrive "W:", "\\wscalfs\Development"
End If

 If InStr(strGroup, lcase("CN=Admissions")) Then
If objFSO.DriveExists("R:") = False Then objNetwork.MapNetworkDrive "R:", "\\wscalfs\Admissions"
End If

 If InStr(strGroup, lcase("CN=Recruitment")) Then
If objFSO.DriveExists("W:") = False Then objNetwork.MapNetworkDrive "W:", "\\wscalfs\Recruitment"
End If  

 If InStr(strGroup, lcase("CN=Financial Aid")) Then
If objFSO.DriveExists("M:") = False Then objNetwork.MapNetworkDrive "M:", "\\wscalfs\FinancialAid"
End If

 If InStr(strGroup, lcase("CN=Quickbooks")) Then
If objFSO.DriveExists("Q:") = False Then objNetwork.MapNetworkDrive "Q:", "\\wscalfs\Quickbooks"
End If  

 If InStr(strGroup, lcase("CN=Business Office")) Then
If objFSO.DriveExists("R:") = False Then objNetwork.MapNetworkDrive "R:", "\\wscalfs\BusinessOffice"
End If  

 If InStr(strGroup, lcase("CN=Administration")) Then
 If objFSO.DriveExists("M:") = False Then objNetwork.MapNetworkDrive "M:", "\\wscalfs\Administration"
End If

 If InStr(strGroup, lcase("CN=Registrar")) Then
If objFSO.DriveExists("T:") = False Then objNetwork.MapNetworkDrive "T:", "\\wscalfs\Registrar"
End If  

 If InStr(strGroup, lcase("CN=Users")) Then
If objFSO.DriveExists("S:") = False Then objNetwork.MapNetworkDrive "S:", "\\wscalfs\scans"
End If

I have a user who has the correct permissions but it is throwing an error on line 28 character 42 of "The network path was not found".  I am not sure what line that is, if it deals with Business Office or Recruitment, but there is no difference in the code at that point than there is prior to that.  I ran the script on myself with the same permissions and it completes successfully.
Avatar of Jeff Darling
Jeff Darling
Flag of United States of America image

This kind of odd behavior is often due to not declaring variables.

Turn on OPTION EXPLICIT and declare all variables.
ASKER CERTIFIED SOLUTION
Avatar of Jeff Darling
Jeff Darling
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aclaus225
aclaus225

ASKER

I tried the script recommended by Jeff and it errors at the same place again.
And mine?
try the NET USE command from a DOS box to display current mapped network drives.

Do it on a good machine and on a bad machine and compare the differences.

You may need to manually NET USE /DELETE one or more of the drives in order for the script to work, or it could be some weird Active Directory permissions inheritance that is unique to your location.
At logout every day there is also a script that runs:
net use G: /delete
net use H: /delete
net use I: /delete
net use J: /delete
net use K: /delete
net use L: /delete
net use M: /delete
net use N: /delete
net use O: /delete
net use P: /delete
net use Q: /delete
net use R: /delete
net use S: /delete
net use T: /delete
net use U: /delete
net use V: /delete
net use W: /delete
net use X: /delete
net use Y: /delete
net use Z: /delete

Open in new window


Therefore, the computers are starting fresh at start up every day.  

As for your script Sirbounty,
that script works on my machine just fine.  On the registrar's computer I get an error, which I have attached.
anothererror.png
I ended up just doing custom scripts for each department using a Batch file which seems to be working for everyone.