Don't take offense to my heading I was just playing. Anyway I have gathered some scripts from around (maybe all from here I can't remember) I've left the authors names in the script to give credit where credit is due. Mark provided the bulk of this script. I added other things as I found them to try to make a logon script that maps printers, drives and does a couple of other cool things. Problem is when i click it while it sits on my desktop it works fine (I'm in the domain admins group) When i put it as a logon script through AD and logon as testuser (in LA_Test Group) i get a message saying undefined error quitting. What does that mean? Did i just set the DC on fire? anyway here's my monstrosity. Hopefully someone can help me get this working. thanks in advance guys and again I was only having fun with the post title.
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
' Maps and disconnects drives and printers
'
'==========================================================================
'Option Explicit
Dim WSHShell, WSHNetwork, objDomain, DomainString, GroupObj
Dim UserString, UserObj, Path, strComputer, oDrives
' 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()
'==========================================================================
'Automatically find the domain name
'==========================================================================
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
'==========================================================================
'Grab the user name
'==========================================================================
UserString = WSHNetwork.UserName
'==========================================================================
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
'==========================================================================
'==========================================================================
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
'==========================================================================
'==========================================================================
' Map drives needed by all
'==========================================================================
Mapit "U", "\\netapp1\users", "", ""
'==========================================================================
'Now check for group memberships and map appropriate drives and printers
'==========================================================================
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
Case "Domain Admins"
Mapit "M", "\\misadmin\root", "", ""
Mapit "P", "\\mgashare1\Product Development", "", ""
Call AddPrinter ("mgae", "rscprint", "misprint")
call AddPrinter ("mgae", "", "test")
Case "LA_Test"
Mapit "P", "\\mgashare1\Product Development", "", ""
Call AddPrinter ("mgae", "rscprint", "pdclr")
End Select
Next
'Add On Code goes below this line
'==========================================================================
'==========================================================================
'Configure the PC to show the Windows Version and Service Pack
'as an overlay to the desktop above the System Tray
'==========================================================================
HKEY_CURRENT_USER = &H80000001
strComputer = WSHNetwork.Computername
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Control Panel\Desktop"
objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
ValueName = "PaintDesktopVersion"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue
'==========================================================================
'Change My Computer Icon to the name of the computer
'==========================================================================
Const MY_COMPUTER = &H11&
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
objFolderItem.Name = strComputer
'==========================================================================
'Change My Computer Icon from the name of the computer
'back to the default My Computer
'==========================================================================
'Const MY_COMPUTER = &H11&
'Set objShell = CreateObject("Shell.Application")
'Set objFolder = objShell.Namespace(MY_COMPUTER)
'Set objFolderItem = objFolder.Self
'objFolderItem.Name = "My Computer"
'==========================================================================
'
' Sub: AddPrinter
'
' Purpose: Connect to shared network printer
'
' Input:
' strPrtServerDomain Domain in which print server is a member
' strPrtServer Name of print server
' strPrtShare Share name of printer
'
' Output:
'
' Usage:
' Call AddPrinter ("Mydomain2", "MyPrtSvr2", "Bld1Rm101-HP4050")
'
'==========================================================================
Private Sub AddPrinter(strPrtServerDomain, strPrtServer, strPrtShare)
On Error Resume Next
Dim strPrtPath 'Full path to printer share
Dim objPrinter 'Object reference to printer
Dim strMsg 'Message output to user
Dim blnError 'True / False error condition
blnError = False
'==========================================================================
'Build path to printer share
strPrtPath = "\\" & strPrtServer & "\" & strPrtShare
'==========================================================================
'Test to see if shared printer exists.
'Proceed if yes, set error condition msg if no.
'==========================================================================
Set objPrinter = GetObject("WinNT://" & strPrtServerDomain & "/" & strPrtServer & "/" & strPrtShare)
If IsObject( objPrinter ) AND (objPrinter.Name <> "" AND objPrinter.Class = "PrintQueue") Then
'==========================================================================
'Different mapping techniques depending on OS version
'==========================================================================
If WSHShell.ExpandEnvironmentStrings( "%OS%" ) = "Windows_NT" Then
Err.Clear
'==========================================================================
'Map printer
'==========================================================================
WSHNetwork.AddWindowsPrinterConnection strPrtPath
Else
'==========================================================================
'Mapping printers for Win9x & ME is a pain and unreliable.
'==========================================================================
End If
Else
blnError = True
End If
'==========================================================================
'Check error condition and output appropriate user message
'I modified this code to not show a Print Server in the
'error message if on did not exsist.
'==========================================================================
If strPrtServer <> "" Then
If Err <> 0 OR blnError = True Then
strMsg = "Unable to connect to network printer. " & vbCrLf & _
"Please contact MIS and ask them to check the " & vbCrLf & _
"" & strPrtServer & " server." & _
vbCrLf & "================================" & vbCrLf & _
"Let them know that this message box appeared" & vbCrLf &_
"and you are unable to connect to the '" _
& strPrtShare & "' printer" & vbCrLf &_
"Thank You "
WScript.Echo strMsg
Else
WScript.Echo ("Successfully added printer connection to " & strPrtPath)
End If
Else
If Err <> 0 OR blnError = True Then
strMsg = "Unable to connect to network printer. " & vbCrLf & _
"Please contact MIS." & vbCrLf & _
vbCrLf & "================================" & vbCrLf & _
"Let them know that this message box appeared" & vbCrLf &_
"and you are unable to connect to the '" _
& strPrtShare & "' printer" & vbCrLf &_
"Thank You "
WScript.Echo strMsg
Else
WScript.Echo ("Successfully added printer connection to " & strPrtPath)
End If
End If
Set objPrinter = Nothing
End Sub
'==========================================================================
' Written in VBScript.
' Paul DeBrino .:. .:. March 2004.
' Establishes map drives.
' Assign to OU Group Policy under USER CONFIG, WINDOWS SETTINGS, SCRIPTS, LOGON SCRIPT.
'
' This script will:
' (1) check if the drive is already connected and, if so, disconnect it.
' (2) map the drive.
'
' Arguments 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 a zero-length string as follows: ""
'
' Reference Microsoft info at:
' '==========================================================================
'==========================================================================
' Create the Shell or environment for the commands:
'==========================================================================
'Set oDrives = WSHNetwork.EnumNetworkDrives()
'==========================================================================
' DEFINE WHO TO CONTACT for pop-up messages:
'==========================================================================
strContactMessage = "If you require assistance, please send an email to MIS Support."
'==========================================================================
' DO NOT MODIFY ANYTHING BELOW THIS POINT...
' unless you are familiar with the proper settings.
'==========================================================================
Sub Mapit(strLetter, strPath, strUser, strPass)
'==========================================================================
' Define the DriveLetter:
Dim DriveLetter, RemotePath, bPopReminder, bForceRemoveFromProfile
Dim bRemoveFromProfile, bStoreInProfile, AlreadyConnected, i, objWSH
DriveLetter = strLetter & ":"
'==========================================================================
'==========================================================================
' Define the remote path:
'==========================================================================
RemotePath = strPath
'==========================================================================
' Pop-up Notices (set to False to disable notices, otherwise set to True):
'==========================================================================
bPopReminder = True
'==========================================================================
' Define known errors to trap:
'==========================================================================
Dim arrErrCode(1)
Dim arrErrDesc(1)
arrErrCode(0) = -2147023694
arrErrCode(1) = -2147024811
arrErrDesc(0) = "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."
arrErrDesc(1) = "Unable to map drive " & DriveLetter & " to " & RemotePath _
& " since " & DriveLetter & ": was previously reserved by your computer." _
& vbCrLf & vbCrLf & "(Refer to Management, Shared Folders, Shares)"
'==========================================================================
' 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
'==========================================================================
' 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 Not strUser = "" Then
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile, strUser, strPass
Else
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
End If
If bPopReminder Then WshShell.PopUp "Drive " & DriveLetter & " disconnected, then connected successfully to " & RemotePath
Else
On Error Resume Next
If Not strUser = "" Then
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile, strUser, strPass
Else
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
End If
If Err.Number <> 0 Then
bKnownError = False
For I = LBound(arrErrCode) To UBound(arrErrCode)
If Err.Number = arrErrCode(I) Then
bKnownError = True
strPopMessage = arrErrDesc(I)
' Display the Disconnect Network Drives window:
If Err.Number = arrErrCode(0) Then
Set objWSH = Wscript.CreateObject("WScript.Shell")
objWSH.Run "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL Disconnect", 1, true
End If
Exit For
End If
Next
If Not bKnownError Then
strPopMessage = "Unable to map drive " & DriveLetter & " to " & RemotePath _
End If
'==========================================================================
' Display warning message:
'==========================================================================
strPopMessage = "WARNING!! WARNING!! WARNING!! WARNING!!" _
& VbCrLf &"================================"_
& vbCrLf & VbCrLf & strPopMessage & vbCrLf & VbCrLf & strContactMessage
WshShell.PopUp strPopMessage
'==========================================================================
Else
If bPopReminder Then WshShell.PopUp "Drive " & DriveLetter & " connected successfully to " & RemotePath
End If
End If
'==========================================================================
' Release resources:
'==========================================================================
Set objWSH = Nothing
'==========================================================================
' Slight pause to ensure each pass has time to commit:
'==========================================================================
wscript.sleep 200
End Sub
'==========================================================================
'Add On Code goes above this line
'==========================================================================
'==========================================================================
'Clean Up Memory We Used
'==========================================================================
Set oDrives = Nothing
Set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
'==========================================================================
'Quit the Script
'==========================================================================
wscript.quit
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
' Maps and disconnects drives and printers
'
'==========================================================================
'Option Explicit
Dim WSHShell, WSHNetwork, objDomain, DomainString, GroupObj
Dim UserString, UserObj, Path, strComputer, oDrives
' 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()
'==========================================================================
'Automatically find the domain name
'==========================================================================
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
'==========================================================================
'Grab the user name
'==========================================================================
UserString = WSHNetwork.UserName
'==========================================================================
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
'==========================================================================
'==========================================================================
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
'==========================================================================
'==========================================================================
' Map drives needed by all
'==========================================================================
Mapit "U", "\\netapp1\users", "", ""
'==========================================================================
'Now check for group memberships and map appropriate drives and printers
'==========================================================================
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
Case "Domain Admins"
Mapit "M", "\\misadmin\root", "", ""
Mapit "P", "\\mgashare1\Product Development", "", ""
Call AddPrinter ("mgae", "rscprint", "misprint")
call AddPrinter ("mgae", "", "test")
Case "LA_Test"
Mapit "P", "\\mgashare1\Product Development", "", ""
Call AddPrinter ("mgae", "rscprint", "pdclr")
End Select
Next
'Add On Code goes below this line
'==========================================================================
'==========================================================================
'Configure the PC to show the Windows Version and Service Pack
'as an overlay to the desktop above the System Tray
'==========================================================================
HKEY_CURRENT_USER = &H80000001
strComputer = WSHNetwork.Computername
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Control Panel\Desktop"
objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
ValueName = "PaintDesktopVersion"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue
'==========================================================================
'Change My Computer Icon to the name of the computer
'==========================================================================
Const MY_COMPUTER = &H11&
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
objFolderItem.Name = strComputer
'==========================================================================
'Change My Computer Icon from the name of the computer
'back to the default My Computer
'==========================================================================
'Const MY_COMPUTER = &H11&
'Set objShell = CreateObject("Shell.Application")
'Set objFolder = objShell.Namespace(MY_COMPUTER)
'Set objFolderItem = objFolder.Self
'objFolderItem.Name = "My Computer"
'==========================================================================
'
' Sub: AddPrinter
'
' Purpose: Connect to shared network printer
'
' Input:
' strPrtServerDomain Domain in which print server is a member
' strPrtServer Name of print server
' strPrtShare Share name of printer
'
' Output:
'
' Usage:
' Call AddPrinter ("Mydomain2", "MyPrtSvr2", "Bld1Rm101-HP4050")
'
'==========================================================================
Private Sub AddPrinter(strPrtServerDomain, strPrtServer, strPrtShare)
On Error Resume Next
Dim strPrtPath 'Full path to printer share
Dim objPrinter 'Object reference to printer
Dim strMsg 'Message output to user
Dim blnError 'True / False error condition
blnError = False
'==========================================================================
'Build path to printer share
strPrtPath = "\\" & strPrtServer & "\" & strPrtShare
'==========================================================================
'Test to see if shared printer exists.
'Proceed if yes, set error condition msg if no.
'==========================================================================
Set objPrinter = GetObject("WinNT://" & strPrtServerDomain & "/" & strPrtServer & "/" & strPrtShare)
If IsObject( objPrinter ) AND (objPrinter.Name <> "" AND objPrinter.Class = "PrintQueue") Then
'==========================================================================
'Different mapping techniques depending on OS version
'==========================================================================
If WSHShell.ExpandEnvironmentStrings( "%OS%" ) = "Windows_NT" Then
Err.Clear
'==========================================================================
'Map printer
'==========================================================================
WSHNetwork.AddWindowsPrinterConnection strPrtPath
Else
'==========================================================================
'Mapping printers for Win9x & ME is a pain and unreliable.
'==========================================================================
End If
Else
blnError = True
End If
'==========================================================================
'Check error condition and output appropriate user message
'I modified this code to not show a Print Server in the
'error message if on did not exsist.
'==========================================================================
If strPrtServer <> "" Then
If Err <> 0 OR blnError = True Then
strMsg = "Unable to connect to network printer. " & vbCrLf & _
"Please contact MIS and ask them to check the " & vbCrLf & _
"" & strPrtServer & " server." & _
vbCrLf & "================================" & vbCrLf & _
"Let them know that this message box appeared" & vbCrLf &_
"and you are unable to connect to the '" _
& strPrtShare & "' printer" & vbCrLf &_
"Thank You "
WScript.Echo strMsg
Else
WScript.Echo ("Successfully added printer connection to " & strPrtPath)
End If
Else
If Err <> 0 OR blnError = True Then
strMsg = "Unable to connect to network printer. " & vbCrLf & _
"Please contact MIS." & vbCrLf & _
vbCrLf & "================================" & vbCrLf & _
"Let them know that this message box appeared" & vbCrLf &_
"and you are unable to connect to the '" _
& strPrtShare & "' printer" & vbCrLf &_
"Thank You "
WScript.Echo strMsg
Else
WScript.Echo ("Successfully added printer connection to " & strPrtPath)
End If
End If
Set objPrinter = Nothing
End Sub
'==========================================================================
' Written in VBScript.
' Paul DeBrino .:. .:. March 2004.
' Establishes map drives.
' Assign to OU Group Policy under USER CONFIG, WINDOWS SETTINGS, SCRIPTS, LOGON SCRIPT.
'
' This script will:
' (1) check if the drive is already connected and, if so, disconnect it.
' (2) map the drive.
'
' Arguments 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 a zero-length string as follows: ""
'
' Reference Microsoft info at:
' '==========================================================================
'==========================================================================
' Create the Shell or environment for the commands:
'==========================================================================
'Set oDrives = WSHNetwork.EnumNetworkDrives()
'==========================================================================
' DEFINE WHO TO CONTACT for pop-up messages:
'==========================================================================
strContactMessage = "If you require assistance, please send an email to MIS Support."
'==========================================================================
' DO NOT MODIFY ANYTHING BELOW THIS POINT...
' unless you are familiar with the proper settings.
'==========================================================================
Sub Mapit(strLetter, strPath, strUser, strPass)
'==========================================================================
' Define the DriveLetter:
Dim DriveLetter, RemotePath, bPopReminder, bForceRemoveFromProfile
Dim bRemoveFromProfile, bStoreInProfile, AlreadyConnected, i, objWSH
DriveLetter = strLetter & ":"
'==========================================================================
'==========================================================================
' Define the remote path:
'==========================================================================
RemotePath = strPath
'==========================================================================
' Pop-up Notices (set to False to disable notices, otherwise set to True):
'==========================================================================
bPopReminder = True
'==========================================================================
' Define known errors to trap:
'==========================================================================
Dim arrErrCode(1)
Dim arrErrDesc(1)
arrErrCode(0) = -2147023694
arrErrCode(1) = -2147024811
arrErrDesc(0) = "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."
arrErrDesc(1) = "Unable to map drive " & DriveLetter & " to " & RemotePath _
& " since " & DriveLetter & ": was previously reserved by your computer." _
& vbCrLf & vbCrLf & "(Refer to Management, Shared Folders, Shares)"
'==========================================================================
' 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
'==========================================================================
' 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 Not strUser = "" Then
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile, strUser, strPass
Else
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
End If
If bPopReminder Then WshShell.PopUp "Drive " & DriveLetter & " disconnected, then connected successfully to " & RemotePath
Else
On Error Resume Next
If Not strUser = "" Then
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile, strUser, strPass
Else
WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
End If
If Err.Number <> 0 Then
bKnownError = False
For I = LBound(arrErrCode) To UBound(arrErrCode)
If Err.Number = arrErrCode(I) Then
bKnownError = True
strPopMessage = arrErrDesc(I)
' Display the Disconnect Network Drives window:
If Err.Number = arrErrCode(0) Then
Set objWSH = Wscript.CreateObject("WScript.Shell")
objWSH.Run "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL Disconnect", 1, true
End If
Exit For
End If
Next
If Not bKnownError Then
strPopMessage = "Unable to map drive " & DriveLetter & " to " & RemotePath _
End If
'==========================================================================
' Display warning message:
'==========================================================================
strPopMessage = "WARNING!! WARNING!! WARNING!! WARNING!!" _
& VbCrLf &"================================"_
& vbCrLf & VbCrLf & strPopMessage & vbCrLf & VbCrLf & strContactMessage
WshShell.PopUp strPopMessage
'==========================================================================
Else
If bPopReminder Then WshShell.PopUp "Drive " & DriveLetter & " connected successfully to " & RemotePath
End If
End If
'==========================================================================
' Release resources:
'==========================================================================
Set objWSH = Nothing
'==========================================================================
' Slight pause to ensure each pass has time to commit:
'==========================================================================
wscript.sleep 200
End Sub
'==========================================================================
'Add On Code goes above this line
'==========================================================================
'==========================================================================
'Clean Up Memory We Used
'==========================================================================
Set oDrives = Nothing
Set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
'==========================================================================
'Quit the Script
'==========================================================================
wscript.quit