• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

how can i exec a programme in dephi..

can someone plz tellme what the option is in winexec("bla.exe",ws_??);
or maybe a other funtion.. that hide the programme like not shown and can someone plz tellme how i can hide a programme from the thask and the progress list in windows xp..
maybe someone can plz give me some code for this or explain how.
if it's posible..

Carlos Smith
  • 4
  • 4
1 Solution
The last parameter of WinExec() is to say how you want the new program displayed (Kind of like a window style parameter). It will except the following values:

SW_FORCEMINIMIZE - Windows 2000/XP: Minimizes a window, even if the thread that owns the window is hung. This flag should only be used when minimizing windows from a different thread.
SW_HIDE - Hides the window and activates another window.
SW_MAXIMIZE - Maximizes the specified window.
SW_MINIMIZE - Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE - Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW - Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT - Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
SW_SHOWMAXIMIZED - Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED - Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE - Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated.
SW_SHOWNA - Displays the window in its current size and position. This value is similar to SW_SHOW, except the window is not activated.
SW_SHOWNOACTIVATE - Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except the window is not actived.
SW_SHOWNORMAL - Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

To hide your program from the task and process list in Windows XP then you would have to install your prog as a service. In Windows 9x its alot easier to do than on the NT platform.


krydeaAuthor Commented:
can you explain me how i can reg it as a sevice?
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

krydeaAuthor Commented:
i mean that you reg a app it self.. like you just all a the registerprogress in win 9x..
and the winexec doens't wait util the job is done? is there a funtion for with hide?
Heres how to run an app and wait for its termination:

function WinExecAndWait32(FileName: string; Visibility: Integer): Longword;
  zAppName: array[0..512] of Char;
  zCurDir: array[0..255] of Char;
  WorkDir: string;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  StrPCopy(zAppName, FileName);
  GetDir(0, WorkDir);
  StrPCopy(zCurDir, WorkDir);
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb          := SizeOf(StartupInfo);
  StartupInfo.dwFlags     := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    zAppName, // pointer to command line string
    nil, // pointer to process security attributes
    nil, // pointer to thread security attributes
    False, // handle inheritance flag
    CREATE_NEW_CONSOLE or // creation flags
    nil, //pointer to new environment block
    nil, // pointer to current directory name
    StartupInfo, // pointer to STARTUPINFO
    ProcessInfo) // pointer to PROCESS_INF
    then Result := WAIT_FAILED
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);

procedure TForm1.Button1Click(Sender: TObject);
  WinExecAndWait32('notepad.exe', SW_HIDE);

As for to create a service all I can really tell you is to find out about the CreateService() and OpenService() functions. If you would like to just hide your app from the Applications list then you could do this:

procedure TForm1.FormShow(Sender: TObject);
  Owner : HWnd;
  Owner := GetWindow(Handle, GW_OWNER);
  ShowWindow(Owner, SW_HIDE);
krydeaAuthor Commented:
i know and the start service i fond it ad delphipages..
but i realy need to find out how to start my programme as a service...
To create a service application just goto: File->New->ServiceApplication in Delphi and then you just have to add your code to that.
krydeaAuthor Commented:
i use delphi 5 so that doens't work with xp...
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now