| Author | Messages | |
adriaoramos
Posts:13
 | | 04/28/2008 4:04 PM |
| Hi all. I have a problem running a printer script in my desktops I tested this script in a Windows XP based machine, and it worked fine. But in my Vista workstations, it is failing. sometimes works, and other no. I would like to know if there is anything I can do to make it run, if there is something different to run in Windows Vista. Can you Help me? This is my script. The user are in the correct groups in my domain
On Error Resume Next Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D Const ADS_SCOPE_SUBTREE = 2 Const ADS_UF_ACCOUNTDISABLE = 2 Const ForReading = 1, ForWriting = 2, ForAppending = 8 DIM aLst(2) strComputer = "." xDefault = "Padrão" Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem") For Each objComputer in colComputer xUser = objComputer.UserName xUserB = Right(xUser,Len(xUser)-InStr(xUser,"\")) Next Set objFSO = CreateObject("Scripting.FileSystemObject") Set objDC = GetObject("GC://dc=sabesp,dc=com,dc=br") Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False ' '-- Monta o comando SQL da consulta ' xAdm_Gab = False xAssessores = False xApoio = False xSecretarias = False For each objsubRefs in objDC.subRefs ' '--- Efetua a Consulta de disponibilidade do LOGON no AD --- ' objCommand.CommandText = _ "<GC://" & objsubRefs & ">;" & _ "(sAMAccountName=" & xUserB & ");" & _ "Name, cn, sAMAccountName, distinguishedName;" & _ "subtree" Set objRecordSet = objCommand.Execute If not objRecordSet.EOF Then xDN = "LDAP://" & objRecordSet.Fields("distinguishedName").Value objRecordSet.MoveFirst Set objUserB = GetObject(xDN) objMemberOf = objUserB.GetEx("MemberOf") ' '-- Listas os Grupos associados a um dado usuário ' For Each xGrupo in objMemberOf If xGrupo = "CN=Administrativo_Gabinete,OU=Gabinete da Presidencia,OU=Hold,OU=Costa,DC=spo,DC=sabesp,DC=com,DC=br" Then xAdm_Gab = True ElseIf xGrupo = "CN=Presidencia_Apoio,OU=Gabinete da Presidencia,OU=Hold,OU=Costa,DC=spo,DC=sabesp,DC=com,DC=br" Then xApoio = True ElseIf xGrupo = "CN=Assessores da Presidência,OU=Gabinete da Presidencia,OU=Hold,OU=Costa,DC=spo,DC=sabesp,DC=com,DC=br" Then xAssessores = True ElseIf xGrupo = "CN=Secretarias_Presidencia,OU=Gabinete da Presidencia,OU=Hold,OU=Costa,DC=spo,DC=sabesp,DC=com,DC=br" Then xSecretarias = True End If Next End If Next
If xAdm_Gab Then ' -- Lista de impressoras do Grupo "Administrativo_Gabinete" da Presidencia. aPrinterPath = Array("\\spo-info213\PPD_M",_ "\\spo-info213\PPD_C-1",_ "\\spo-info213\PPD_C-2") aPrinterDriver = Array("RICOH Aficio MP 2000 PCL 6",_ "HP Color LaserJet 3600",_ "HP Color LaserJet 3600") ' ElseIf xApoio Then ' -- Lista de impressoras do Grupo "Presidencia_Apoio" da Presidencia. aPrinterPath = Array("\\spo-info213\HP_Color_P-1") aPrinterDriver = Array("HP Color LaserJet 3600") ' ElseIf xAssessores Then ' -- Lista de impressoras do Grupo "Assessores da Presidência" da Presidencia. aPrinterPath = Array("\\spo-info213\AFICIO_COLOR_P",_ "\\spo-info213\HP_Color_P-2") aPrinterDriver = Array("RICOH Aficio MP C2500 PCL 6",_ "HP Color LaserJet 3600") ' ElseIf xSecretarias Then ' -- Lista de impressoras do Grupo "Secretarias_Presidencia" da Presidencia. aPrinterPath = Array("\\spo-info213\RICOH_Mono_PPS",_ "\\spo-info213\HP_Color_PPS") aPrinterDriver = Array("RICOH Aficio MP 2000 PCL 6",_ "HP Color LaserJet 3600") End If ' ' -- Registra qual é a impressoras padrão. Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer") Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") W2K = false For Each objOperatingSystem in colOperatingSystems If Instr(objOperatingSystem.Caption, "2000") > 0 Then W2K = True End If Next If W2K Then Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists("c:\Impr_Pdr.txt") Then Set objFile = objFSO.OpenTextFile("c:\Impr_Pdr.txt", ForReading) xDefault = objFile.ReadLine Else Set objFile = objFSO.OpenTextFile("c:\Impr_Pdr.txt", ForWriting, True) For Each xDefault in aPrinterPath If MsgBox("É esta sua Impressora Padrão?" & vbCrLf & xDefault, vbYesNo, "Seleção de Impressora Padrão") = vbYes Then Exit For End If Next objFile.Write xDefault End If objFile.Close Else For Each objPrinter in colInstalledPrinters If objPrinter.Default Then xDefault = objPrinter.Name End If Next End If ' ' -- Desconecta as impressoras de rede. Set WshNetwork = WScript.CreateObject("WScript.Network") For Each objPrinter in colInstalledPrinters If Instr(objPrinter.Name,"spo-info213")>0 Then WshNetwork.RemovePrinterConnection objPrinter.Name End If Next ' ' -- Conecta as impressoras de rede. Set WshNetwork = CreateObject("WScript.Network") For i = 0 To UBound(aPrinterPath) Step 1 WshNetwork.AddWindowsPrinterConnection aPrinterPath(i), aPrinterDriver(i) If UCase(xDefault) = UCase(aPrinterPath(i)) Then WshNetwork.SetDefaultPrinter aPrinterPath(i) End If Next
List info : http://www.activedir.org/List.aspx List FAQ : http://www.activedir.org/ListFAQ.aspx List archive: http://www.activedir.org/ma/default.aspx
| | | |
|
|