procedure TfProzesse.WMIStartProcesses(Computer, User, Password,exeName:
string);
function GetCompName:
string;
var
Buf :
array[0..MAX_COMPUTERNAME_LENGTH]
of Char;
Size : DWORD;
begin
Size := SizeOf(Buf);
if GetComputerName(Buf, Size)
then
Result := Buf
else
Result := '
';
end;
var
FComputer:
String;
FUser:
String;
FPassword:
String;
Services : ISWbemServices;
ObjectDefinition: ISWbemObject;
ObjectSet : SWbemObjectSet;
ObjectInstances: IEnumVariant;
WMIObject : ISWbemObject;
PropertySet : ISWbemPropertySet;
WMIProperty : ISWbemProperty;
FProcess: ISWbemObject;
FMethod: ISWbemMethod;
FInParam: ISWbemObject;
FOutParam: ISWbemObject;
FProperty: ISWbemProperty;
FPropValue: OleVariant;
TempObj : OleVariant;
ObjValue : Cardinal;
i : Integer;
resourcestring
rsWMIError = '
WMI-Fehler';
begin
if AnsiUpperCase(GetCompName) = AnsiUpperCase(Computer)
then
begin
FComputer := '
';
FUser := '
';
FPassword := '
';
end
else
begin
FComputer := Computer;
FUser := user;
FPassword := Password;
end;
i := 0;
//Locator := TSWbemLocator.Create(Nil);
try
try
Services := Locator.ConnectServer(FComputer, '
root\cimv2',FUser, FPassword, '
', '
', 0,
nil);
if Services <>
nil then
begin
Services.Security_.Set_ImpersonationLevel(wbemImpersonationLevelImpersonate);
FProcess := Services.Get('
Win32_Process', 0,
nil);
FMethod := FProcess.Methods_.Item('
Create', 0);
FInParam := FMethod.InParameters.SpawnInstance_(0);
FProperty := FInParam.Properties_.Add('
CommandLine', wbemCimtypeString, false, 0);
FPropValue := exeName;
FProperty.Set_Value(FPropValue);
FOutParam := FProcess.ExecMethod_('
Create', FInParam, 0,
nil);
end;
finally
Services :=
nil;
end;
except
on e:
Exception do
raise e.Create(e.
message);
end;
end;