Archive for June 18th, 2008

18
Jun
08

Execute Processes from your application on Vista

When developing applications for Windows Vista, one of the problems that often arises is how to programmatically control the execution level of a process. When the user starts an application, its elevation level is determined by the value of the requestedExecutionLevel attribute in its manifest, and Vista’s User Account Control (UAC) takes appropriate actions depending on it (such as displaying the elevation prompt when needed, etc.) However, what if the application needs to start a new process with a different execution level than that of the application itself? For example:

  • An application that runs at the standard level determines that an updated version of it is available for download. To be able to update itself, it needs to start a separate process that needs to be elevated in order to perform the upgrade properly. In this case a non-elevated process needs to start a new, elevated process.

If this is your case, then I have the answer for you.

By specifying the "runas" verb when calling the ShellExecuteEx API you can “tell” UAC that open this application and not just to blockit.

The code is fairly simple, i am using C++ here,

#include <windows.h>
ShellExecute(NULL,(LPCSTR)"runas",(LPCSTR)"yourprocess.exe",NULL,NULL,SW_SHOWNORMAL);

This is the ShellExecute API

HINSTANCE ShellExecute(
    HWND hwnd,
    LPCTSTR lpOperation,
    LPCTSTR lpFile,
    LPCTSTR lpParameters,
    LPCTSTR lpDirectory,
    INT nShowCmd
);
Parameter     Description
----------------------------------------------------------------------------
hwnd          Identifies the parent window. This window receives any
              message boxes an application produces (for example, for error
              reporting).

lpszOp        Points to a null-terminated string specifying the operation
              to perform. This string can be "open" or "print." If this
              parameter is NULL, "open" is the default value.

lpszFile      Points to a null-terminated string specifying the file
              to open.

lpszParams    Points to a null-terminated string specifying parameters
              passed to the application when the lpszFile parameter
              specifies an executable file. If lpszFile points to a string
              specifying a document file, this parameter is NULL.

LpszDir       Points to a null-terminated string specifying the default
              directory.

FsShowCmd     Specifies whether the application window is to be shown when
              the application is opened.



 

June 2008
M T W T F S S
« May   Jul »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Flickr Photos

Archana7

Detonate

Almost

Night - The Ice Maiden!

Thank You, all of you !

~Lovely Cuppa~

The Agora and the new Calatrava's bridge: Blue and Magenta series

skip's

Hat tip to friday

baby it's cold outside

More Photos

Leave your comment

Blog Stats

  • 119,562 hits