Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with executing services.msc

281 views
Skip to first unread message

Ruediger Kabbasch

unread,
Jul 24, 2008, 11:53:45 AM7/24/08
to
Hi everybody.

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


Marc Rohloff [TeamB]

unread,
Jul 24, 2008, 12:04:01 PM7/24/08
to
On Thu, 24 Jul 2008 17:53:45 +0200, Ruediger Kabbasch wrote:

> Does anybody knows what I'm making wrong here?

Have you tried using CreateProcess instead?

--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com

Ruediger Kabbasch

unread,
Jul 24, 2008, 12:47:36 PM7/24/08
to
> Have you tried using CreateProcess instead?

Yes, I did.

But if I try to use CreateProcess I get the error message 193, %1 is not a
valid Win32 application.

Marc Rohloff [TeamB]

unread,
Jul 24, 2008, 1:23:01 PM7/24/08
to
On Thu, 24 Jul 2008 17:53:45 +0200, Ruediger Kabbasch wrote:

> 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;

Remy Lebeau (TeamB)

unread,
Jul 24, 2008, 1:26:54 PM7/24/08
to

"Ruediger Kabbasch" <ruediger...@thermo.com> wrote in message
news:4888a589$1...@newsgroups.borland.com...

> 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


Remy Lebeau (TeamB)

unread,
Jul 24, 2008, 2:00:50 PM7/24/08
to

"Ruediger Kabbasch" <ruediger...@thermo.com> wrote in message
news:4888b229$1...@newsgroups.borland.com...

> 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


Marc Rohloff [TeamB]

unread,
Jul 24, 2008, 2:09:19 PM7/24/08
to
On Thu, 24 Jul 2008 18:47:36 +0200, Ruediger Kabbasch wrote:

> 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.

Ruediger Kabbasch

unread,
Jul 25, 2008, 5:48:08 AM7/25/08
to
Hi,

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;

Marc Rohloff [TeamB]

unread,
Jul 25, 2008, 9:19:13 AM7/25/08
to
On Fri, 25 Jul 2008 11:48:08 +0200, Ruediger Kabbasch wrote:

> It runs with the following code:

It would be more reliable if you use the GetSystemDirectory windows
API instead of hard-coding the paths.

Ruediger Kabbasch

unread,
Jul 25, 2008, 10:47:42 AM7/25/08
to
> 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.

0 new messages