VB Logon Script pushed via GP

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Cross-posting to the Scripting groups - sorry, don't have time to read all
that :-(

--
Paul Williams
Microsoft MVP - Windows Server - Directory Services
http://www.msresource.net | http://forums.msresource.net


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
 
OK.
There is a script available that do the job; map printers depeding on the
group a user belongs to.
The script act on the configuration of the currently logged on user, (good
for logon script...;-))

There are some comments that show you how to configure the script (closely
nothing to configure).

The script may be downloaded at:
http://www.ictsolutions.it/scriptforum/mapprinters.vbs

You wil be asked to provide the credentials to access. Please use:
username: scripter
password: scripter

Let me know if the script works for you or you need more.

I hope this can help.
Bye,
SubnetJO


"Paul Williams [MVP]" ha scritto:
 
Back
Top