1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| Function CreateRemoteProcess(ServerName, wmiPath, wmiUser, wmiPasswod,Processus : String): Hwnd;
var
WmiService: SWbemServices;
ProcessID: OleVariant;
WMILocator: TSWbemLocator;
Process,
NewProcess,
Instance_inParameters:SWbemObject;
WmiProperty: SWbemProperty;
ProcessMethod: ISWbemMethod;
PropertyCommandLine,
PropertyReturnValue: OleVariant;
begin
WMILocator:= TSWbemLocator.Create(nil);
try
try
Result:=0;
if wmiPath = cstEmpty then wmiPath := WMI_PATH;
if wmiUser = cstEmpty then wmiUser := WMI_USER;
if wmiPasswod = cstEmpty then wmiPasswod := WMI_PASSWORD;
WmiService:= WMILocator.ConnectServer(ServerName, wmiPath, wmiUser, wmiPasswod, cstEmpty, cstEmpty, wbemConnectFlagUseMaxWait, nil);
Process:=WmiService.Get('Win32_Process',0,Nil);
ProcessMethod:=Process.Methods_.Item('Create', 0);
Instance_inParameters:= ProcessMethod.InParameters.SpawnInstance_(0);
WmiProperty:= Instance_inParameters.Properties_.Item('CommandLine',0);
PropertyCommandLine:= Processus;
WmiProperty.Set_Value(PropertyCommandLine);
NewProcess:= Process.ExecMethod_('Create', Instance_inParameters, wbemFlagReturnWhenComplete, nil);
PropertyReturnValue:= NewProcess.Properties_.Item('ReturnValue', 0);
if PropertyReturnValue.Value = 0 then
begin
PropertyReturnValue:= NewProcess.Properties_.Item('ProcessId', 0);
ProcessID:=PropertyReturnValue.Value;
Result:=ProcessID;
end
else LogEvenement('!!!Erreur '+inttostr(PropertyReturnValue.Value)+' lors de la création du process.');
Except
LogEvenement('!!!Exception déclenchée lors de la création du process.');
end;
finally
WMILocator.Disconnect;
WMILocator.Free;
end;
end; |
Partager