JoinDomainOrWorkgroup - 无效的方法参数8004102F

时间:2017-03-06 19:13:44

标签: delphi wmi ole lazarus freepascal


我正在尝试编写应用程序来自动加入域名 我使用Lazarus v.6.6.2(Free Pascal)和wmi-delphi-code-creator v.1.9.9.350
这是代码:

function WMI_JoinDomainOrWorkgroup(const DomainName, Password, UserName, AccountOU, FJoinOptions :WideString):String;
const
  WbemServer        ='localhost';
  WbemNamespace     ='root\CIMV2';
  WbemUser          ='';
  WbemPassword      ='';
  WmiPath           ='Win32_ComputerSystem';
var
  FSWbemLocator   : OLEVariant;
  FWMIService     : OLEVariant;
  FWbemObjectSet  : OLEVariant;
  FOutParams      : OLEVariant;
  sValue          : string;
begin
  try
    FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  except
    on E:EOleException do
        ShowMessage(Format('EOleException(CreateOleObject) %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        ShowMessage('Exception(CreateOleObject) ' + E.Classname + ':' + E.Message);
  end;

  try
    FWMIService := FSWbemLocator.ConnectServer(WbemServer, WbemNamespace, WbemUser, WbemPassword);
  except
    on E:EOleException do
        ShowMessage(Format('EOleException(ConnectServer) %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        ShowMessage('Exception(ConnectServer) ' + E.Classname + ':' + E.Message);
  end;

  try
    FWbemObjectSet := FWMIService.Get(WmiPath);
  except
    on E:EOleException do
        ShowMessage(Format('EOleException(FWMIService.Get) %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        ShowMessage('Exception(FWMIService.Get) ' + E.Classname + ':' + E.Message);
  end;
  //####################################
  //#I have EOLEEXception in this Place#
  //####################################
  try
    FOutParams := FWbemObjectSet.JoinDomainOrWorkgroup(DomainName, Password, UserName, AccountOU, FJoinOptions); //<- I have EOLEEXception in this Place
  except
    on E:EOleException do
        ShowMessage(Format('EOleException(JoinDomainOrWorkgroup) %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        ShowMessage('Exception(JoinDomainOrWorkgroup) ' + E.Classname + ':' + E.Message);
  end;

  sValue:=FOutParams;
  Result := Format('ReturnValue %s',[sValue]);
end;

procedure TForm1.JoinPCToNewDomain;
var
  str_result: string;
begin
  str_result:='';

  try
    str_result := WMI_JoinDomainOrWorkgroup(WideString(edt_NewDomainName.Text),
                                            WideString(edt_PassNewDomain.Text),
                                            WideString(edt_NewDomainUser.Text),
                                            WideString(edt_NewDomainOU.Text), '3');
    Logger(str_result);
  except
    on E:EOleException do
        Logger(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Logger(E.Classname + ':' + E.Message);
  end;
end;


当我使用此代码运行应用程序时,出现以下错误:

Invalid method Parameter(s) 8004102F

请帮助解决这个问题。 任何帮助表示赞赏!感谢

0 个答案:

没有答案