5t0n3r Posted December 30, 2008 Share Posted December 30, 2008 Hello, I am in need of an AutoIT script that will remove all printers an the unused printer drivers except for Adobe PDF. I have a VBS script that does this, but it's a pain to always have to log out the user and log in as the administrator to accomplish this task. I have tried converting the VBS script into AU3 scriping, but it didn't work. below is the VBS Script I have. Any help would be appreciated. Thanks in advance. expandcollapse popupstrComputer = "." intSleep = 3000 strService = " 'Spooler' " Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colListOfServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where Name ="_ & strService & " ") For Each objService in colListOfServices objService.StopService() WSCript.Sleep intSleep Next Set WSHShell = WScript.CreateObject("WScript.Shell") strRegKey="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\DefaultSpoolDirectory" DeleteFile WSHShell.RegRead(strRegKey) & "\*.SPL" DeleteFile WSHShell.RegRead(strRegKey) & "\*.SHD" Set colListOfServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where Name ="_ & strService & " ") For Each objService in colListOfServices objService.StartService() WSCript.Sleep intSleep Next function DeleteFile(WhatFile) on Error Resume Next set fso=createobject("Scripting.Filesystemobject") fso.DeleteFile(WhatFile) End Function on Error Resume Next Set objDictionary = CreateObject("Scripting.Dictionary") Set colPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") '***delete all Printers from the computer For Each objPrinter in colPrinters If Not objPrinter.Name="Adobe PDF" Then If Not objPrinter.Name="Acrobat Distiller" Then ObjPrinter.Delete_ End If End If Next '***delete the TCPIP-printer-ports For Each objPrinter in colPrinters objDictionary.Add objPrinter.PortName, objPrinter.PortName Next Set colPorts = objWMIService.ExecQuery _ ("Select * from Win32_TCPIPPrinterPort") For Each objPort in colPorts If objDictionary.Exists(objPort.Name) Then Else ObjPort.Delete_ End If Next '***un-install the printer drivers Set WSHShell = CreateObject("WScript.Shell") WSHShell.Run "Cscript.exe %windir%\system32\prndrvr.vbs -x -s %computername%", 0, False Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 30, 2008 Share Posted December 30, 2008 Hello, I am in need of an AutoIT script that will remove all printers an the unused printer drivers except for Adobe PDF. I have a VBS script that does this, but it's a pain to always have to log out the user and log in as the administrator to accomplish this task. I have tried converting the VBS script into AU3 scriping, but it didn't work. below is the VBS Script I have. Any help would be appreciated. Thanks in advance. expandcollapse popupstrComputer = "." intSleep = 3000 strService = " 'Spooler' " Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colListOfServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where Name ="_ & strService & " ") For Each objService in colListOfServices objService.StopService() WSCript.Sleep intSleep Next Set WSHShell = WScript.CreateObject("WScript.Shell") strRegKey="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\DefaultSpoolDirectory" DeleteFile WSHShell.RegRead(strRegKey) & "\*.SPL" DeleteFile WSHShell.RegRead(strRegKey) & "\*.SHD" Set colListOfServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where Name ="_ & strService & " ") For Each objService in colListOfServices objService.StartService() WSCript.Sleep intSleep Next function DeleteFile(WhatFile) on Error Resume Next set fso=createobject("Scripting.Filesystemobject") fso.DeleteFile(WhatFile) End Function on Error Resume Next Set objDictionary = CreateObject("Scripting.Dictionary") Set colPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") '***delete all Printers from the computer For Each objPrinter in colPrinters If Not objPrinter.Name="Adobe PDF" Then If Not objPrinter.Name="Acrobat Distiller" Then ObjPrinter.Delete_ End If End If Next '***delete the TCPIP-printer-ports For Each objPrinter in colPrinters objDictionary.Add objPrinter.PortName, objPrinter.PortName Next Set colPorts = objWMIService.ExecQuery _ ("Select * from Win32_TCPIPPrinterPort") For Each objPort in colPorts If objDictionary.Exists(objPort.Name) Then Else ObjPort.Delete_ End If Next '***un-install the printer drivers Set WSHShell = CreateObject("WScript.Shell") WSHShell.Run "Cscript.exe %windir%\system32\prndrvr.vbs -x -s %computername%", 0, False Well, you can convert it to AutoIt, but will still have to run it as a local admin to change the global printers. So you will RunAs() either the VBS or AutoIt script. Look up RunAs() in the help file and run either 'cscript "C:\Dir\MyVBScript.vbs"' or the compiled AutoIt version. If you need help converting the VBS to AutoIt, post what you got in AutoIt so we can work on that. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
5t0n3r Posted December 31, 2008 Author Share Posted December 31, 2008 Well, you can convert it to AutoIt, but will still have to run it as a local admin to change the global printers. So you will RunAs() either the VBS or AutoIt script.Look up RunAs() in the help file and run either 'cscript "C:\Dir\MyVBScript.vbs"' or the compiled AutoIt version.If you need help converting the VBS to AutoIt, post what you got in AutoIt so we can work on that. That's my issue, getting it converted into an AutoIT script. I have tried a few VBS to EXE converters and even tried the VBS to AutoIT converter on this site. However the latter didn't convert the VBS as I am sure it was newer code than it knows what to do with.I'm looking for some AutoIT coding that will remove the local printers without touching the Adobe PDF printer and then run the command in the the above script to remove the unused printer drivers.The above script works fine when used with the Windows XP runas, but I'm looking for an all-in-one solution to add to a login script. Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 31, 2008 Share Posted December 31, 2008 That's my issue, getting it converted into an AutoIT script. I have tried a few VBS to EXE converters and even tried the VBS to AutoIT converter on this site. However the latter didn't convert the VBS as I am sure it was newer code than it knows what to do with.I'm looking for some AutoIT coding that will remove the local printers without touching the Adobe PDF printer and then run the command in the the above script to remove the unused printer drivers.The above script works fine when used with the Windows XP runas, but I'm looking for an all-in-one solution to add to a login script.OK, what have you done so far? Add "$" to the variable names, remove "set", etc. Post what you did so far to convert that VBS to AutoIt.This forum is here to help you do it, but probably no one will just do it for you. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now