If I run the following command from the console (or the Run command from
windows) ...
c:\windows\system32\services.msc /s /Computer=dedre-itdvm-test
... the services window opens with the services from the remote computer
(Windows XP).
But with Delphi I did not get it running:
I try this ...
ShellExecute(0, 'open', 'c:\windows\system32\services.msc', '/s
/Computername=dedre-itdvm-test', NIL, SW_SHOW);
... and this ...
procedure TForm2.Button4Click(Sender: TObject);
var
SEI : TShellExecuteInfo;
begin
FillChar(SEI, SizeOf(SEI), 0);
SEI.cbSize := SizeOf(SEI);
SEI.lpFile := 'c:\windows\system32\services.msc';
SEI.lpVerb := 'open';
SEI.lpParameters := '/s /Computername=dedre-itdvm-test';
SEI.fMask := 0;
SEI.Wnd := Handle;
ShellExecuteEx(@SEI);
end;
In both cases the services dialog will be started, but not with the services
from the remote host but with the service from the local host. It seems that
the parameter will be ignored.
Does anybody knows what I'm making wrong here?
Thanks in advance for any hint.
With kind regards,
Ruediger Kabbasch
> Does anybody knows what I'm making wrong here?
Have you tried using CreateProcess instead?
--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com
Yes, I did.
But if I try to use CreateProcess I get the error message 193, %1 is not a
valid Win32 application.
> In both cases the services dialog will be started, but not with the services
> from the remote host but with the service from the local host. It seems that
> the parameter will be ignored.
From the help for lpParameters under ShellExecute and SHELLEXECUTEINFO
"If lpFile specifies a document file, lpParameters should be NULL."
What happens if you do
SEI.lpFile := 'c:\windows\system32\services.msc /s
/Computer=dedre-itdvm-test
';
SEI.lpParameters := nil;
> But with Delphi I did not get it running:
Use CreateProcess() instead of ShellExecute/Ex() to run executables, ie:
var
SI: STARTUPINFO;
PI: PROCESS_INFORMATION;
begin
ZeroMemory(@SI, SizeOf(SI));
ZeroMemory(@PI, SizeOf(PI));
SI.cb := SizeOf(SI);
SI.dwFlags := STARTF_USESHOWWINDOW;
SI.wShowWindow := SW_SHOW;
if CreateProcess(nil, 'c:\windows\system32\services.msc /s
/Computer=dedre-itdvm-test', nil, nil, False, 0, nil, nil, SI, PI) then
begin
CloseHandle(PI.hThread);
CloseHandle(PI.hProcess);
end;
end;
Gambit
> Yes, I did.
>
> But if I try to use CreateProcess I get the error message 193,
> %1 is not a valid Win32 application.
Try calling 'mmc.exe' instead of 'services.msc' directly, ie:
var
SysDir: String;
function GetSysDir: String;
var
Buf: array[0..MAX_PATH] of Char;
begin
SetString(Result, Buf, GetSystemDirectory(Buf, MAX_PATH));
if Result <> '' then Result :=
IncludeTrailingPathDelimiter(Result);
end;
begin
SysDir := GetSysDir;
if CreateProcess(..., PChar(SysDir + 'mmc.exe "' + SysDir +
'services.msc" /s /Computer=dedre-itdvm-test'), ...) then
...
end;
Gambit
> But if I try to use CreateProcess I get the error message 193, %1 is not a
> valid Win32 application.
Sorry, my bad, I forgot that a .msc file isn't an executable.
thanks for all your help!!
It runs with the following code:
procedure TForm2.Button10Click(Sender: TObject);
const
errStartingAppl2 = 'Error while trying to start' + #13
+ 'Error code: %d' + #13
+ '%s';
var
SI: STARTUPINFO;
PI: PROCESS_INFORMATION;
ErrorCode : Integer; // Helpvar.
begin
ZeroMemory(@SI, SizeOf(SI));
ZeroMemory(@PI, SizeOf(PI));
SI.cb := SizeOf(SI);
SI.dwFlags := STARTF_USESHOWWINDOW;
SI.wShowWindow := SW_SHOW;
if CreateProcess(nil, 'c:\windows\system32\mmc.exe
c:\windows\system32\services.msc /s /Computer=remote_host_name', nil, nil,
False, 0, nil, nil, SI, PI) then
begin
CloseHandle(PI.hThread);
CloseHandle(PI.hProcess);
end
else begin
ErrorCode := GetLastError;
Showmessage(Format(errStartingAppl2, [ErrorCode,
SysErrorMessage(ErrorCode)]));
end;
end;
> It runs with the following code:
It would be more reliable if you use the GetSystemDirectory windows
API instead of hard-coding the paths.
Thanks for the tip, but this is just a test routine. The final version uses
the GetSystemDirectory API, of course.