G
Guest
Hi
I am new to vbscripting and have put together a printer script - using
examples from the web - what I want to do is map a printer based on AD group
membership. The script runs, but will not map the printers, script below -
Any ideas?
Option Explicit
'On Error Resume Next
'==========================================================================
' Declaring Global variables.
'==========================================================================
Dim objNet, objStatusWindow, ObjUser, objShell, objfso, objlog
Dim strUser, strComputer, strUserDN, strStatus,strPrinter
Dim strMappedDefPrinter,strMappedPrinter, strMappedDrives,
strDefaultPrinterName
Dim strErrorMessages, intErrorCount, strGroupName
dim blIsCitrixServer, ErrorCount
'==========================================================================
' Declaring Constants
'==========================================================================
Const LOG_FILE = "c:\printers.log"
Const FORCE_TRUE = True
'==========================================================================
' Main Function
'==========================================================================
call GetUserName()
Call MapDefPrinter(strPrinter, FORCE_TRUE)
Call MapAddPrinter(strPrinter)
Call MapRCIDefaultPrinter()
Call MapRCIAddtionalPrinters()
'==========================================================================
' Getting User Name
'==========================================================================
Sub GetUserName()
Set objNet = WScript.CreateObject("WScript.Network")
If Err.Number Then Call BuildErrorMessage(Err.Description, Err.Source) :
Exit Sub
strUser = ""
While strUser = ""
strUser = objNet.UserName
Wend
End Sub
'==========================================================================
' Map Default Printer Drive
'==========================================================================
Sub MapDefPrinter(strPrinter, FORCE_TRUE)
Dim arrPrinterNameParts,strPrinterFullPath
On Error Resume Next
objNet.AddWindowsPrinterConnection strPrinter
objNet.SetDefaultPrinter strPrinter
If Err.Number Then
objNet.RemovePrinterConnection strPrinter, FORCE_TRUE
objNet.AddWindowsPrinterConnection strPrinterFullPath
arrPrinterNameParts = Split(strPrinter, "\")
strDefaultPrinterName = arrPrinterNameParts(UBound(arrPrinterNameParts)-1)
If Err.Number Then Call BuildErrorMessage(Err.Description, Err.Source) :
Exit Sub
objNet.SetDefaultPrinter strPrinter
If Err.Number Then Call BuildErrorMessage(Err.Description, Err.Source)
End If
End Sub
'==========================================================================
' Map Additional Printer Sub
'==========================================================================
Sub MapAddPrinter(strPrinter)
On Error Resume Next
objNet.AddWindowsPrinterConnection strPrinter
If Err.Number Then
objNet.RemovePrinterConnection strPrinter
objNet.AddWindowsPrinterConnection strPrinter
If Err.Number Then Call BuildErrorMessage(Err.Description, Err.Source)
End If
End Sub
'==========================================================================
' RCIEurope Default Printer Mapping
'==========================================================================
Sub MapRCIDefaultPrinter()
' Create WSHNetwork object
Set objNet = Wscript.CreateObject("Wscript.Network")
Set objUser = GetObject("WinNT://RCIEurope/" & strUser & ",user")
' Mapping Printers based on group membership
'Wscript.Echo "Mapping printers based on group membership"
For Each strGroupName In objUser.Groups
select case strGroupName.Name
case "Printer CORK_EUROQA1_HP9000"
MapDefPrinter "\\corkpddsc01\CORK_EUROQA1_HP9000","true"
end select
Next
End Sub
'==========================================================================
' RCIEurope Additional Printer Mapping
'==========================================================================
Sub MapRCIAddtionalPrinters()
' Create WSHNetwork object
Set objNet = Wscript.CreateObject("Wscript.Network")
Set objUser = GetObject("WinNT://RCIEurope/" & strUser & ",user")
' Mapping drives based on group membership
'Wscript.Echo "Mapping printers based on group membership"
For Each strGroupName In objUser.Groups
select case strGroupName.Name
case "PRINTER CORK_UKCUSTSERV_HP9050"
MapAddPrinter "\\corkpddsc01\CORK_UKCUSTSERV_HP9050"
end select
Next
End Sub
*********************************************************
Thanks
I am new to vbscripting and have put together a printer script - using
examples from the web - what I want to do is map a printer based on AD group
membership. The script runs, but will not map the printers, script below -
Any ideas?
Option Explicit
'On Error Resume Next
'==========================================================================
' Declaring Global variables.
'==========================================================================
Dim objNet, objStatusWindow, ObjUser, objShell, objfso, objlog
Dim strUser, strComputer, strUserDN, strStatus,strPrinter
Dim strMappedDefPrinter,strMappedPrinter, strMappedDrives,
strDefaultPrinterName
Dim strErrorMessages, intErrorCount, strGroupName
dim blIsCitrixServer, ErrorCount
'==========================================================================
' Declaring Constants
'==========================================================================
Const LOG_FILE = "c:\printers.log"
Const FORCE_TRUE = True
'==========================================================================
' Main Function
'==========================================================================
call GetUserName()
Call MapDefPrinter(strPrinter, FORCE_TRUE)
Call MapAddPrinter(strPrinter)
Call MapRCIDefaultPrinter()
Call MapRCIAddtionalPrinters()
'==========================================================================
' Getting User Name
'==========================================================================
Sub GetUserName()
Set objNet = WScript.CreateObject("WScript.Network")
If Err.Number Then Call BuildErrorMessage(Err.Description, Err.Source) :
Exit Sub
strUser = ""
While strUser = ""
strUser = objNet.UserName
Wend
End Sub
'==========================================================================
' Map Default Printer Drive
'==========================================================================
Sub MapDefPrinter(strPrinter, FORCE_TRUE)
Dim arrPrinterNameParts,strPrinterFullPath
On Error Resume Next
objNet.AddWindowsPrinterConnection strPrinter
objNet.SetDefaultPrinter strPrinter
If Err.Number Then
objNet.RemovePrinterConnection strPrinter, FORCE_TRUE
objNet.AddWindowsPrinterConnection strPrinterFullPath
arrPrinterNameParts = Split(strPrinter, "\")
strDefaultPrinterName = arrPrinterNameParts(UBound(arrPrinterNameParts)-1)
If Err.Number Then Call BuildErrorMessage(Err.Description, Err.Source) :
Exit Sub
objNet.SetDefaultPrinter strPrinter
If Err.Number Then Call BuildErrorMessage(Err.Description, Err.Source)
End If
End Sub
'==========================================================================
' Map Additional Printer Sub
'==========================================================================
Sub MapAddPrinter(strPrinter)
On Error Resume Next
objNet.AddWindowsPrinterConnection strPrinter
If Err.Number Then
objNet.RemovePrinterConnection strPrinter
objNet.AddWindowsPrinterConnection strPrinter
If Err.Number Then Call BuildErrorMessage(Err.Description, Err.Source)
End If
End Sub
'==========================================================================
' RCIEurope Default Printer Mapping
'==========================================================================
Sub MapRCIDefaultPrinter()
' Create WSHNetwork object
Set objNet = Wscript.CreateObject("Wscript.Network")
Set objUser = GetObject("WinNT://RCIEurope/" & strUser & ",user")
' Mapping Printers based on group membership
'Wscript.Echo "Mapping printers based on group membership"
For Each strGroupName In objUser.Groups
select case strGroupName.Name
case "Printer CORK_EUROQA1_HP9000"
MapDefPrinter "\\corkpddsc01\CORK_EUROQA1_HP9000","true"
end select
Next
End Sub
'==========================================================================
' RCIEurope Additional Printer Mapping
'==========================================================================
Sub MapRCIAddtionalPrinters()
' Create WSHNetwork object
Set objNet = Wscript.CreateObject("Wscript.Network")
Set objUser = GetObject("WinNT://RCIEurope/" & strUser & ",user")
' Mapping drives based on group membership
'Wscript.Echo "Mapping printers based on group membership"
For Each strGroupName In objUser.Groups
select case strGroupName.Name
case "PRINTER CORK_UKCUSTSERV_HP9050"
MapAddPrinter "\\corkpddsc01\CORK_UKCUSTSERV_HP9050"
end select
Next
End Sub
*********************************************************
Thanks