182 anonyme User
77156 Mitglieder freuen sich auf Dich!
Top-Aktivitäten
Sehen Sie hier, wer zu den aktivsten Mitgliedern der aktuellen Woche zählt:
182 anonyme User

' CHANGE Printers for Users ' ' Karo, 08.09.2010 ' With this script you can change the mapping from Printernames ' OLDNAME to NENAME in a Textfile ' Syntax in TXT = \\SERVER\PRINTERNAMEOLD;\\SERVER\PRINTERNAMENEW ' ' 20100908 Initial ' 20100909 Set Default Printer ' 20100910 Added Loop for check if Printer connected after renaming ' Set printers ' ****************************** Const HKEY_CURRENT_USER = &H80000001 Const HKEY_LOCAL_MACHINE = &H80000002 On Error Resume Next Dim objNetwork, fs, fsFILE Dim Counter, CounterU, aryPrinter(999), aryPrinterU(100), strComputer, strUsername Dim splPrinter, x, y, fstemp, DefPrinter Set objNetwork = CreateObject("WScript.Network") Set fs = CreateObject("Scripting.FileSystemObject") Set fstemp = fs.GetSpecialFolder(2) wscript.echo ("The path to your TEMP folder is '" & fstemp & "'." ) 'COPY FILE TO TEMP 'wscript.echo ("\\MYSERVER\MYSHARE\printers.txt") Set fsFILE = fs.GetFile("\\MYSERVER\MYSHARE\printers.txt") fsFILE.copy (fstemp & "\printers.txt") 'READ FILE Set fsFILE = fs.OpenTextFile(fstemp & "\printers.txt") Counter = 0 Do Until fsFILE.AtEndOfStream Counter = Counter + 1 aryPrinter(Counter) = fsFILE.Readline 'wscript.echo Counter & " ---- " & aryPrinter(Counter) Loop strComputer = "." 'Read User Printer Connections Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") CounterU = 0 strKeyPath = "Printers\Connections" oReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys For Each subkey In arrSubKeys CounterU = CounterU + 1 aryPrinterU(CounterU) = UCase(Replace(subkey,",","\")) Next 'Get Current Username strUsername = objNetwork.UserName wscript.echo strUsername & " - Mapped Printers: " & CounterU 'READ MAPPED PRINTERS FROM USER strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") Y = 0 DefPrinter = "FALSE" For Each objPrinter in colInstalledPrinters For y = 1 to CounterU If InStr(1,UCase(aryPrinterU(Y)),UCase(objPrinter.Name),1) > 0 Then wscript.echo "##################################################" WScript.echo "SEARCH: " & aryPrinterU(Y) For x = 1 to Counter splPrinter=Split(aryPrinter(x),";") 'COMPARE MAPPED PRINTERS WITH PRINTERS IN FILE If InStr(1,aryPrinterU(Y),splPrinter(0),1) > 0 Then WScript.echo aryPrinterU(Y) & " - " & splPrinter(0) wscript.echo "-YES-" 'Is Printer Default 'DefPrinter = "FALSE" If objPrinter.Default = "True" Then DefPrinter = splPrinter(1) wscript.echo "Default Printer Flag is set on " & splPrinter(0) & "" ' Else ' DefPrinter = "FALSE" ' Exit For End If 'DELETE OLD MAPPING wscript.echo "-Delete Old Mapping-" objNetwork.RemovePrinterConnection splPrinter(0) wscript.echo splPrinter(0) 'NEW MAPPING wscript.echo "-New Mapping-" objNetwork.AddWindowsPrinterConnection splPrinter(1) wscript.echo splPrinter(1) wscript.echo "######END " & splPrinter(1) & "#####" Else End If Next End If Next Next Y = 0 wscript.echo "##################################################" wscript.echo "" wscript.echo "" wscript.echo "##################################################" If DefPrinter = "FALSE" Then wscript.echo "No Default Printer in Remapped Printers" Else wscript.echo "Check for Connection: " & DefPrinter & " " For counter = 0 to 2 Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter in colInstalledPrinters 'wscript.echo UCase(objPrinter.Name)& " -> " & UCase(DefPrinter) If InStr(1,UCase(objPrinter.Name),UCase(DefPrinter),1) > 0 Then wscript.echo "-Bingo!" counter = 3 Exit For Else counter = 1 End If Next Next 'IF PRINTER IS DEFAULT (True) SET NEW DEFAULT If DefPrinter = "FALSE" Then Else wscript.echo "-Set as Default" 'objNetwork.SetDefaultPrinter splPrinter(1) 'wscript.echo splPrinter(1) objNetwork.SetDefaultPrinter DefPrinter wscript.echo DefPrinter End If End If wscript.echo "##################################################" wscript.echo "" wscript.echo "#######################" wscript.echo "###### END OF ALL " & "#####" wscript.echo "#######################" WScript.sleep 20000