Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how can i exec a programme in dephi..

Posted on 2002-07-09
11
253 Views
Last Modified: 2010-04-04
hello,
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
0
Comment
Question by:krydea
  • 4
  • 4
11 Comments
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7140299
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.

Cheers,

Alan
0
 

Author Comment

by:krydea
ID: 7140317
can you explain me how i can reg it as a sevice?
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7140700
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:krydea
ID: 7141132
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?
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7142956
Heres how to run an app and wait for its termination:


function WinExecAndWait32(FileName: string; Visibility: Integer): Longword;
var
  zAppName: array[0..512] of Char;
  zCurDir: array[0..255] of Char;
  WorkDir: string;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  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
    NORMAL_PRIORITY_CLASS,
    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
  else
  begin
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
  end;
end;

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

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);
var
  Owner : HWnd;
begin
  Owner := GetWindow(Handle, GW_OWNER);
  ShowWindow(Owner, SW_HIDE);
end;
0
 

Author Comment

by:krydea
ID: 7143066
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...
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7144859
To create a service application just goto: File->New->ServiceApplication in Delphi and then you just have to add your code to that.
0
 

Author Comment

by:krydea
ID: 7145409
i use delphi 5 so that doens't work with xp...
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 7258769
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 317
Delphi : could not find program, '...exe' 2 192
Downloading email attachments 2 79
URL for downloading Google Chrome for Win XP 2 187
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question