WMI Conversion

  • Thread starter MildManoredJanitor
  • Start date
M

MildManoredJanitor

Hello Group

Can anyone tell me what the script below is in VB.NET WMI format?

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")

For Each objPrinter in colInstalledPrinters
objPrinter.CancelAllJobs()
Next

------------------------------------------

If I try to convert this then I make 'objPrinter' a ManagementObject, but
then I have 'Delete' & not 'CancelAllJobs'.

Any suggestions?
 
K

Ken Tucker [MVP]

Hi,

Add a reference to system.management to your application.

Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Printer")
moReturn = moSearch.Get

For Each mo In moReturn
mo.InvokeMethod("CancelAllJobs", Nothing)
Trace.WriteLine(mo("Name").ToString)
Next

Ken
 
M

MildManoredJanitor

Thanks Ken

Basically, my code was the same as yours with one exception:

mo.InvokeMethod("CancelAllJobs", Nothing)

Much Appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top