Jump to content

Recommended Posts

Posted

Hello everyone!

 

I have been having a problem with one laptop running a .VBS script when a user logs off it. The script below is set to run at log off via GPO and it works great on all the other laptops/PCs we have here. Unfortunately theres always one...

_________________________

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer &

"\root\cimv2")

 

Set colInstalledPrinters = objWMIService.ExecQuery _

("Select * from Win32_Printer Where Network = TRUE")

 

For Each objPrinter in colInstalledPrinters

objPrinter.Delete_

Next

_________________________

 

Has anyone got any ideas as to how I can add a form of try/catch statement to this so it just quits if it errors? At the moment its just sitting there running scripts until it reaches 10mins and times out!

 

Any help would be greatly appreciated

 

regards

 

Gareth

Posted

Well if it runs on everything else, then there's clearly something up with that laptop. You could try re-imaging, it might be quicker than trying to work out the problem?

 

The script looks absolutely fine from my point of view :)

Posted

_________________________

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer &

"\root\cimv2")

 

Set colInstalledPrinters = objWMIService.ExecQuery _

("Select * from Win32_Printer Where Network = TRUE")

 

For Each objPrinter in colInstalledPrinters

objPrinter.Delete_

Next

_________________________

Gareth

 

WMI can cause this problem as there is no 'time out' as such; it just sits there for ages until it gives up. You could try restarting WMI services (and Windows Firewall/ICS) before setting objWMIService?

Posted

Plan B might be to do it differently; presumably, you just want to make sure that you have a "clean" start at each logon in terms of network printers?

 

I use the code below to get the list of network printers and remove them:

set oNetwork=createobject("wscript.network")
 Set oPrinters = oNetwork.EnumPrinterConnections
 For i = 0 to oPrinters.Count - 1 Step 2
  if left(oPrinters.Item(i+1),2)="\\" then
    onetwork.removeprinterconnection oPrinters.Item(i+1)
  end if
 Next

 

This doesn't use WMI so might help.

 

A problem with WMI is that the repository can get messed up - Reseting WMI has a section "Resetting WMI" which shows you how to fix it.

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...