Home All Groups Group Topic Archive Search About
Author
4 Mar 2006 11:20 AM
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?

Author
4 Mar 2006 12:10 PM
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
-----------------
Show quoteHide quote
"MildManoredJanitor" <hongk***@phoey.fun> wrote in message
news:uJfP423PGHA.1688@TK2MSFTNGP11.phx.gbl...
> 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?
>
>
Author
4 Mar 2006 1:29 PM
MildManoredJanitor
Thanks Ken

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

mo.InvokeMethod("CancelAllJobs", Nothing)

Much Appreciated


Show quoteHide quote
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%23$mkpS4PGHA.2912@tk2msftngp13.phx.gbl...
> 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
> -----------------
> "MildManoredJanitor" <hongk***@phoey.fun> wrote in message
> news:uJfP423PGHA.1688@TK2MSFTNGP11.phx.gbl...
> > 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?
> >
> >
>
>