Solved

how can i exec a programme in dephi..

Posted on 2002-07-09
11
251 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
Comment Utility
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
Comment Utility
can you explain me how i can reg it as a sevice?
0
 
LVL 5

Expert Comment

by:alanwhincup
Comment Utility
0
 

Author Comment

by:krydea
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:alanwhincup
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
i use delphi 5 so that doens't work with xp...
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
Comment Utility
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now