SalemGrafix
IS-IT--Management
Hi all, was wondering if someone here might be able to help with this script. I'm recieving the error:
Object Required: "WshShell"
In the logon script. If I run the script from my machine, it works without a problem (already logged into the network). When I implement it as a script for a user to logon, that's when I recieve the error. Originally, I was recieving the error when I was using WshShell.PopUp prior to Set WshShell = WScript.CreateObject("WScript.Shell"), but now I have the Set WshShell line setup prior to the popup. Any help is greatly appreciated:
Again, thanks for any help, it's greatly appreciated.
Object Required: "WshShell"
In the logon script. If I run the script from my machine, it works without a problem (already logged into the network). When I implement it as a script for a user to logon, that's when I recieve the error. Originally, I was recieving the error when I was using WshShell.PopUp prior to Set WshShell = WScript.CreateObject("WScript.Shell"), but now I have the Set WshShell line setup prior to the popup. Any help is greatly appreciated:
Code:
' ########################################################################
' Written in VBScript.
' Paul DeBrino .:. [URL unfurl="true"]www.infinity-rd.com[/URL] .:. March 2004.
' Establishes map drives.
' Assigned to OU Group Policy as User Logon Script.
'
' This script will:
' (1) check if the drive is already connected and, if so, disconnect it.
' (2) map the drive.
'
' Command parameters are as follows:
' MAPIT DRIVE-LETTER as string, PATH as string, USER as string, PASSWORD as string
' (1) Do not specify colon in drive letter.
' (2) Do not end path with a forward slash.
' (3) If user and password are not required to establish map, then specify null as follows: vbNull
'
' Reference Microsoft info at:
' [URL unfurl="true"]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthmapnetworkdrive.asp[/URL]
' ########################################################################
' Modified for SCC by Eddie D. Shelton Jr. December 2004.
' MAPIT DRIVE-LETTER now does not try to log in using a username/password if vbNull is specified
' ########################################################################
' ====================================
' DEFINE WHO TO CONTACT for pop-up messages:
' ====================================
strContactMessage = "If you require assistance, please contact IT Support."
' ==================
' DISPLAY MESSAGE THAT IT'S STARTED
' ==================
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.PopUp " *** SCC Logon Script " & vbcrlf & " *** Mapping Drives "
' ==================
' DEFINE DRIVES TO MAP:
' ==================
Mapit "M", "\\sccsrv-app02\apps", vbNull, vbNull
Mapit "U", "\\sccsrv-pdc02\divisional documents$", vbNull, vbNull
' ==================
' DISPLAY MESSAGE THAT IT'S DONE
' ==================
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.PopUp " *** SCC Logon Script " & vbcrlf & " *** Script Complete! "
' ##################################
' DO NOT MODIFY ANYTHING BELOW THIS POINT...
' unless you are familiar with the proper settings.
' ##################################
Sub Mapit(strLetter, strPath, strUser, strPass)
' Slight pause to ensure each pass has time to commit:
wscript.sleep 200
' Pop-up Notices (set to False to disable notices, otherwise set to True):
bPopReminder = True
' Define remembered map drive error number:
intErrRemembered = -2147023694
' Define whether the map information should be removed from the current user's profile:
bForceRemoveFromProfile = True
bRemoveFromProfile = True
' Define whether the map information should be stored in the current user's profile:
bStoreInProfile = False
' Create the Shell or environment for the commands:
Set WshShell = WScript.CreateObject("WScript.Shell")
' Define objects:
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives()
' Define the DriveLetter:
DriveLetter = strLetter & ":"
' Define the remote path:
RemotePath = strPath
' Check if already connected:
AlreadyConnected = False
For i = 0 To oDrives.Count - 1 Step 2
If LCase(oDrives.Item(i)) = LCase(DriveLetter) Then AlreadyConnected = True
Next
' Attempt to map the drive. If already mapped, first attempt disconnect:
If AlreadyConnected = True then
WshNetwork.RemoveNetworkDrive DriveLetter, bForceRemoveFromProfile, bRemoveFromProfile
If strUser <> vbNull then
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile, strUser, strPass
else
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
end if
If bPopReminder Then nomsg = ""
Else
On Error Resume Next
if strUser <> vbNull then
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile, strUser, strPass
else
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
end if
If Err.Number <> 0 Then
If Err.Number = intErrRemembered Then
WshShell.PopUp "WARNING!! WARNING!! WARNING!! WARNING!!" & vbCrLf & vbCrLf _
& "Unable to map drive " & DriveLetter & " to " & RemotePath _
& " due to a previously defined remembered map with the same letter." _
& vbCrLf & vbCrLf & "Please MANUALLY disconnect map drive " & DriveLetter _
& ", then Log Out and Log back in." _
& vbCrLf & vbCrLf & strContactMessage
' Display the Disconnect Network Drives window:
Set objWSH = Wscript.CreateObject("WScript.Shell")
objWSH.Run "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL Disconnect", 1, true
Else
WshShell.PopUp "WARNING!! WARNING!! WARNING!! WARNING!!" & vbCrLf & vbCrLf _
& Err.Description & " (error " & Err.Number & ")" & vbCrLf & vbCrLf _
& "Unable to map drive " & DriveLetter & " to " & RemotePath _
& " due to above reason." _
& vbCrLf & vbCrLf & strContactMessage
End If
Else
End If
End If
' Release resources:
Set objWSH = Nothing
Set WshShell = Nothing
Set WshNetwork = Nothing
Set oDrives = Nothing
End Sub
Again, thanks for any help, it's greatly appreciated.