Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9121849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:57:18+00:00 2026-06-17T05:57:18+00:00

Sometimes there is need to open new program (e.g. Windows Powerpoint presentation as slideshow

  • 0

Sometimes there is need to open new program (e.g. Windows Powerpoint presentation as slideshow can be opened by command line “powerpnt.exe /s“) from commandline, maximize this program and bring it in front of desktop as the first program the user can see and use. This happens by default if user directly enters command in the command prompt, because the command prompt is the active window.

But the question is – how to do this, if command line is executed from background process – e.g. from custom Windows service application of from the Windows Task Scehduler – in both cases the new windows is not brought as the first window.

At present I can imagine only quite hard solutions (whose drawback is that they required coding and they can not be used from Task Scheduler):

  1. one can try to get handle of the main window of the opened program and the manipulate this window – e.g. maximize and so on;
  2. one can try to abandon command line at all and instead manipulate Windows Office applications as COM objects.

Maybe there is easier way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:57:20+00:00Added an answer on June 17, 2026 at 5:57 am

    You can create a small (non-gui) launcher application that will call the new program for you (I know, that’s what you’ve called the hard solution) and then schedule this launcher on the task scheduler.

    This launcher application would have to create de process (CreateProcess function), and then get the Window Handle from the pID… with the window handle you can use SetForegroundWindow to do what you need, or call other functions for things like maximize, etc.

    Since you tagged delphi, I’m posting a possible delphi implementation of that.

    function WindowFromPID(pID: Cardinal; VisibleWindow: Boolean): Cardinal;
    type
      TProcData = record
        pID: Cardinal;
        pHandle: Cardinal;
    
        VisibleWindow: Boolean;
      end;
    
    var 
      wPData: TProcData;
    
      function EnumProc(Handle: HWND; var pProcData: TProcData): Bool; stdcall;
      var pID: DWORD;
      begin
        Result := True;
        if pProcData.VisibleWindow then
          if not IsWindowVisible(Handle) then
            Exit;
    
        GetWindowThreadProcessId(Handle, @pID);
        if pID = pProcData.pID then begin
          if GetWindow(Handle, GW_OWNER) = 0 then begin
            pProcData.pHandle := Handle;
            Result := false;
          end;
        end;
      end;
    begin
      wPData.pHandle := 0;
      wPData.pID := pID;
      wPData.VisibleWindow := VisibleWindow;
    
      EnumWindows(@EnumProc, Integer(@wPData));
      while (wPData.pHandle = 0) do begin
        Sleep(50);
        EnumWindows(@EnumProc, Integer(@wPData));
      end;
    
      Result := wPData.pHandle;
    end;
    
    procedure RunAndGetWindowHandle(const FileName, Params: String; const WindowState: Word): Cardinal;
    var 
      SUInfo: TStartupInfo;
      CmdLine: String;
      ProcInfo: TProcessInformation
    begin
      CmdLine := '"' + Filename + '"' + Params;
      FillChar(SUInfo, SizeOf(SUInfo), #0);
      with SUInfo do begin
        cb := SizeOf(SUInfo);
        dwFlags := StartF_UseShowWindow;
        wShowWindow := WindowState;
      end;
    
      if not CreateProcess(Nil, PChar(CmdLine), nil, nil, False, Create_New_Console Or Normal_Priority_Class, nil, PChar(ExtractFilePath(Filename)), SUInfo, ProcInfo) then
        raise Exception.Create('Error running process');
    
      if WaitForSingleObject(ProcInfo.hProcess, 50) <> WAIT_TIMEOUT then
        raise Exception.Create('Error running process!');
    
      CloseHandle(ProcInfo.hThread);
      while Result = 0 do begin
        Sleep(50);
        Result := WindowFromPID(ProcInfo.dwProcessId, true);
      end;
    end;
    
    ...
    
    var WindowHandle: Cardinal;
    begin
      WindowHandle := RunAndGetWindowHandle("powerpnt.exe", " /s", SW_SHOWNORMAL);
      SetForegroundWindow(WindowHandle);
    end;
    

    Hope that’s what you need.. sorry if it’s not.

    Best Regards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I open up a notepad from my program using Process.Start() but the new opened
I program in C++. Sometimes there are 1000 ways to do something, and depending
I am writing a application which need to open a new mail dialog, upon
I am importing data from csv file, sometimes there are column headers and some
my Page has many hover images, sometimes there are backgrounds from div-elements or src
I download a png file from link. But sometimes there is no file. And
I have a column called post_tags where there is sometimes one tag entry and
Is there any way with TextMate to hide comments when editing code? Sometimes I
ActiveRecord's query interface seems for me sometimes very complex and not intuitive. Is there
I am writing a parser for csv-files, and sometimes I get NumberFormatException. Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.