AutoIt Forums: Removing printers and drivers from windows xp - AutoIt Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Removing printers and drivers from windows xp

#1 User is offline   5t0n3r 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 39
  • Joined: 30-December 08
  • Gender:Male

Post icon  Posted 30 December 2008 - 09:11 PM

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.

[ code='text' ]    ( ExpandCollapse - Popup )
strComputer = "." 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


#2 User is offline   PsaltyDS 

  • Most Venerable Penguin
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 11,855
  • Joined: 12-December 05
  • Gender:Male
  • Location:Broke down in Troy crater; AAA won't return my calls...

Posted 30 December 2008 - 09:46 PM

View Post5t0n3r, on Dec 30 2008, 03:11 PM, said:

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.

[ code='text' ]    ( ExpandCollapse - Popup )
strComputer = "." 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.

:)

#3 User is offline   5t0n3r 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 39
  • Joined: 30-December 08
  • Gender:Male

Posted 31 December 2008 - 06:38 PM

View PostPsaltyDS, on Dec 30 2008, 01:46 PM, said:

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.

#4 User is offline   PsaltyDS 

  • Most Venerable Penguin
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 11,855
  • Joined: 12-December 05
  • Gender:Male
  • Location:Broke down in Troy crater; AAA won't return my calls...

Posted 31 December 2008 - 07:16 PM

View Post5t0n3r, on Dec 31 2008, 12:38 PM, said:

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.

;)

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users