Passing Arguments to Procedure (WMI, FSWbemLocator.ConnectServer, 0x800706BA) lazarus / 34-Windows ---------------------------------------------------------------------- devers000 · 2017-03-13 20:41 Hi All! I'm trying to write application to automate remote information gathering. I use Lazarus v. 1.6.4 (fpc 3.0.2) and wmi-delphi-code-creator v. 1.9.9.350 Here is the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program GetWMI_Info; {$mode objfpc} {$H+} uses  SysUtils,  ActiveX,  ComObj,  Variants;                procedure  GetWin32_BaseBoardInfo(WbemComputer, WbemUser, WbemPassword: string);const  wbemFlagForwardOnly = $00000020;var  FSWbemLocator : OLEVariant;  FWMIService   : OLEVariant;  FWbemObjectSet: OLEVariant;  FWbemObject   : OLEVariant;  oEnum         : IEnumvariant;  sValue      : string;  i             : LongWord;   begin;  i := 0;  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_BaseBoard','WQL',wbemFlagForwardOnly);  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;  while oEnum.Next(1, FWbemObject, i) = 0 do  begin    sValue:= FWbemObject.Properties_.Item('Manufacturer').Value;    Writeln(Format('Manufacturer    %s',[sValue]));    FWbemObject:=Unassigned;  end;end; begin try    GetWin32_BaseBoardInfo('PCNAME','user','password'); except    on E:EOleException do        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));              on E:Exception do        Writeln(E.Classname, ':', E.Message); end; Writeln('Press Enter to exit'); Readln;    end. When I run application using this code I have the following error: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i EOleException RPC server is unavailable.  800706BA But if I change code like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FWMIService   := FSWbemLocator.ConnectServer('PCNAME', 'root\CIMV2', 'user', 'password');Application works without error... I think that passing arguments to procedure is wrong but I don't understand why... Please, help to solve this problem. Any help is appreciated! Thanks ---------------------------------------------------------------------- Thaddy · 2017-03-13 20:45 Try Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure  GetWin32_BaseBoardInfo(WbemComputer, WbemUser, WbemPassword: widestring);WMI is a widestring API, so pass it widestring or unicodestring - which is a refcounted 16bit widestring -. sValue should also be widestring or unicodestring. I see you have a console program. In that case you can change the mode to {$MODE DELPHIUNICODE} instead of objfpc. Then all strings are 16bit unicode by default. Don't do this is in a Lazarus GUI app. There you should specify the strings as widestring or unicode string when calling a 16bit string API like WMI. So my guess is that your console program works if you change it just a little:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program GetWMI_Info; {$mode delphiunicode} {$H+} wmi-delphi-code-creator is broken for current Lazarus versions because of the "enlightened" UTF8 string type. Until Lazarus (and fpc rtl) supports UTF16 fully, you should specify a 16bit string type when doing Windows API calls, or use mode delphiunicode for console apps like your example. ---------------------------------------------------------------------- devers000 · 2017-03-14 21:03 Thank you, Thaddy!  I develop GUI and you're right! I need to use WideString. Now it's working like a charm! ---------------------------------------------------------------------- JuhaManninen · 2017-03-14 21:41 Quote from: devers000 on March 14, 2017, 10:03:02 pmThank you, Thaddy!  I develop GUI and you're right! I need to use WideString. Actually you should use UnicodeString instead. A nice bonus with the Lazarus UTF-8 system is that your code is compatible with Delphi at source level when using UnicodeString for the API calls despite the encoding differences. Another thing to remember: you must assign string constants only to type "string" variables which is also Delphi compatible.