Jump to content
alogrep

WMIService (PrintJobInfo) spanws to the CPU window , ot trigger exceptio.

Recommended Posts

THI.

I have the piece of code show below. 

when it gets to the line

   FWMIService   := FSWbemLocator.ConnectServer

it simply opwns the CPU window and does never get tot except section.

Running Delphi 12.1 on win 64bit.

(The second piece of code shows how the procedure is called).

Any idea anybody?

procedure  GetWin32_PrintJobInfo;
const
  WbemUser            ='';
  WbemPassword        ='';
  WbemComputer     =   'localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService   : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject   : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
  str:String;
begin;
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
try
  FWMIService   := FSWbemLocator.ConnectServer('192.168.1.70', 'root\CIMV2', WbemUser, WbemPassword);
except
 on E:EOleException do
   writeln(e.message);
  on E:sysutils.Exception do
   writeln(e.message);
end;
begin
 try
    CoInitialize(nil);
    try
      GetWin32_PrintJobInfo;
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;

 

Share this post


Link to post

WMI is about LAN computers with NetBIOS, you don't usually use IP addresses to connect to remote servers, but computer names.   For the local computer, use a blank name and credentials, but you might need admin rights for some WMI classes. 

 

The ICS component library has a WMI unit that does all this for you, and an EXE sample, it displays the Win32_printer class, but I suspect getting the queue is complicated.

 

Angus

 

Share this post


Link to post

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

×