Thread View: borland.public.delphi.nativeapi.win32
10 messages
10 total messages
Started by Ruediger Kabbasch
Thu, 24 Jul 2008 15:53
Problem with executing services.msc
Author: Ruediger Kabbasch
Date: Thu, 24 Jul 2008 15:53
Date: Thu, 24 Jul 2008 15:53
44 lines
2248 bytes
2248 bytes
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
Re: Problem with executing services.msc
Author: Marc Rohloff [TeamB]
Date: Thu, 24 Jul 2008 16:04
Date: Thu, 24 Jul 2008 16:04
9 lines
1475 bytes
1475 bytes
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
Re: Problem with executing services.msc
Author: Ruediger Kabbasch
Date: Thu, 24 Jul 2008 16:47
Date: Thu, 24 Jul 2008 16:47
9 lines
1300 bytes
1300 bytes
> 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. With kind regards, Ruediger Kabbasch
Re: Problem with executing services.msc
Author: Marc Rohloff [TeamB]
Date: Thu, 24 Jul 2008 17:23
Date: Thu, 24 Jul 2008 17:23
18 lines
1815 bytes
1815 bytes
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; -- Marc Rohloff [TeamB] marc -at- marc rohloff -dot- com
Re: Problem with executing services.msc
Author: Remy Lebeau (TeamB)
Date: Thu, 24 Jul 2008 17:26
Date: Thu, 24 Jul 2008 17:26
27 lines
1808 bytes
1808 bytes
"Ruediger Kabbasch" <ruediger.kabbasch@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
Re: Problem with executing services.msc
Author: Remy Lebeau (TeamB)
Date: Thu, 24 Jul 2008 18:00
Date: Thu, 24 Jul 2008 18:00
32 lines
1996 bytes
1996 bytes
"Ruediger Kabbasch" <ruediger.kabbasch@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
Re: Problem with executing services.msc
Author: Marc Rohloff [TeamB]
Date: Thu, 24 Jul 2008 18:09
Date: Thu, 24 Jul 2008 18:09
10 lines
1586 bytes
1586 bytes
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. -- Marc Rohloff [TeamB] marc -at- marc rohloff -dot- com
Re: Problem with executing services.msc
Author: Ruediger Kabbasch
Date: Fri, 25 Jul 2008 09:48
Date: Fri, 25 Jul 2008 09:48
35 lines
1952 bytes
1952 bytes
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;
Re: Problem with executing services.msc
Author: Marc Rohloff [TeamB]
Date: Fri, 25 Jul 2008 13:19
Date: Fri, 25 Jul 2008 13:19
10 lines
1452 bytes
1452 bytes
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. -- Marc Rohloff [TeamB] marc -at- marc rohloff -dot- com
Re: Problem with executing services.msc
Author: Ruediger Kabbasch
Date: Fri, 25 Jul 2008 14:47
Date: Fri, 25 Jul 2008 14:47
8 lines
1489 bytes
1489 bytes
> 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. With kind regards, Ruediger Kabbasch
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads