Launch application - c++

I want to launch an application using win32 ...
Please let me know your ideas to achieve this

In (approximately) ascending order of control and complexity: WinExec, ShellExecute, ShellExecuteEx, CreateProcess.

Your best option is ShellExecute (It can launch any filetype and will handle elevation) If you need more control of the new process, use CreateProcess

You need to call CreateProcess.

Related

How to run Windows commands in a C++ program?

Is there a way to put windows commands in C++ program.
I am a newbie so your help will be very much appreciated.
Thank You
You can try system function from cstdlib.
http://www.kev.pulo.com.au/pp/RESOURCES/cplusplus/ref/cstdlib/system.html
You should be able to use the system() function from <cstdlib>7. Although be aware that it will probably create a cmd.exe window. If you don't want that then you can use the windows specific CreateProcess() function.

CreateProcess and ShellExecute differences

What are the main differences between the two? I'm willing to run only another EXE from my (C++) application. Are there any differences when inheriting environments, security features etc?
The main difference between CreateProcess and ShellExecute is the following: CreateProcess is more oriented on low level and ShellExec on the high user lever which see the user in explorer.
For example using of CreateProcess one can use command line which length is more as MAX_PATH. It has 32,768 characters restriction. You can also use CreateProcess to start program (if you have enough permissions) on another windows desktop like on the Logon Screen.
Another example. You can use ShellExecute to start Control Panel or open any program which existed on the computer for editing of JPG filed for example. So you works with ShellExecute close to the corresponding actions in the Windows Explorer.
The main difference is in flexibility. ShellExecute is easier to use, but doesn't have a lot of flexibility. CreateProcess is a pain to use, but lets you do anything.
Just for example, with CreateProcess, you can specify handles (pipes or files) to use for the standard input/output/error streams in the child. ShellExecute doesn't give you want way to do that.
It's probably also worth noting that although ShellExecute can be used to start an executable directly, its primary intent is to "execute" document files -- for example, tell it to "execute" a "whatever.html", and it starts up your default web browser and loads the specified HTML file into it. You can do that using CreateProcess as well, but to do it, you (normally) start by calling FindExecutable to find the program associated with the data file in question, then execute that passing your data file as a parameter.
CreateProcess returns the handle and id for the started process and it's main thread in the PROCESS_INFORMATION structure

How Do I Run an .exe From My Program and Obtain a Handle

How do I open a process and obtain a handle too it in C++. I know that there is system() and numerous methods to obtain a handle, but I'm sure there is a neater/alternative way to doing this. Or is system() the only way to open a .exe from inside your own?
A common way to do this is to use the Win32 API CreateProcess. The last parameter of this function is an out parameter to a structure (PROCESS_INFORMATION) containing the handle to the process (HANDLE hProcess).
Use ShellExecute

How to launch an external application on BN_CLICKED?

I'm fairly new to Windows programming. I'm doing a simple launcher app for WinCE using VC++ (not MFC). So far I've created the basic interface and buttons and stuff. I just wanted to know the best way to launch an external application when the user clicks the button (on BN_CLICKED).
I found some methods such as ShellExecute, CreateProcess and others. But I couldn't get it to work (yet?). Any suitable reference or simple example on this?
The question don't matter that it happens inside the event of a button click, but...
ShellExecute is a good way to start programs (and the default program for any other type of files) in Windows, but use CreateProcess if you need a return code, or if you need the ability to wait for the program to finish.
Nevermind. I found a working example on MSDN - a comment by a user.
For anyone interested, you can go to this CreateProcess() article and scroll down to a comment entitled "Working code for creating two processes "p1.exe" and "p2.exe" using CreateProcess() Method"
Thanks!

Is it possible to UAC elevate a process without starting another process

I was wondering if it is possible for a program to prompt the user with a UAC prompt to raise it's own privileges without starting another process.
All the examples I can find on the internet seem to ShellExecute "runas" which creates a new process with elevated privileges.
If this is not possible then my best solution I guess would be create a named pipe, ShellExecute my own program with a special argument, and then shove all the data that it will need to perform the operation down the pipe. If there are any better suggestions then this I would be glad to hear them.
Thanks for any input.
No, you can't elevate an existing process. You're right - you have start a new elevated process and get that to do the work for you.
One other possible answer (which ends up being essentially the same answer) is to have a service which runs as LocalSystem that does the elevated work for you.