Re: Launching an app under Vista with UAP enabled



Hi Ivan,

Thanks for the quick response. If I understand correctly, the Consent-UI
prompts the user for permission before running th e app. That would be
rather unpleasant for our users. For every print job they submit with the
preview feature turned on, or every manual duplexed job, they must accept
the launch of the preview application (or manual duplex animation) before
anything would happen.

Is there another option? We really need a way to launch an app without user
consent. The only backup plan on the table is to launch all our
applications at system start and leave them running (hidden in the
background until they are needed.) I'm sure most users wouldn't appreciate
that since it eats up their system resources.

If this is more of a general problem launching applications (not specific to
launching from a print component,) can you recommend a more appropriate
newsgroup?

Thanks,
Dan


"Ivan Brugiolo [MSFT]" <Ivan.Brugiolo@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23AH8fogbGHA.3632@xxxxxxxxxxxxxxxxxxxxxxx
The proper way would be to create a manifest for your application
where you describe the elevation requirements, and, then,
let ShellExecuteEx to inspect the manifest, evaluate the
elevation requirements, fire-up the Consent-UI prompt,
and, eventually, run the application.
While you could re-label the token to upgrade it the proper
integrity or desktop-integrity level from a service with the proper
privileges,
that code already exisit for your convenience in the system.

This is kind of Out-Of-Topic for driver development, though

--
--
This posting is provided "AS IS" with no warranties, and confers no
rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Dan Updegraff" <daniel.updegraff@xxxxxxxxxxxxxxxx> wrote in message
news:eRwenEfbGHA.3364@xxxxxxxxxxxxxxxxxxxxxxx
Is it possible to launch an application from a print component under
Windows Vista while UAP (User Account Protection) is enabled?

We are developing a printer driver, print processor, and language monitor
for XP and Vista. Each component launches an executable at some point
(e.g. the driver launches an app for manual duplexing animations, the
print processor launches and app for previewing the job, the language
monitor launches an app for showing job status.)

The following "execute" function is used to launch an app using the
active user account's security level. It works perfectly under XP, even
when Fast User Switched to a Guest account with limited permissions.
However, it won't work under Windows Vista as long as UAP is enabled.

FYI - Input Parameters:
inCmdLine = the full path name of the app to launch
inOptions.bHideWindow = false
inOptions.bImpersonateActiveUser = true
inOptions.bWaitForStart = true
inOptions.bWaitForFinish = false
inOptions.bShowWaitCursor = false

bool execute(LPCTSTR inCmdLine, ExecuteOptions inOptions)
{
BOOL bSuccess = FALSE;
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInfo;
SECURITY_ATTRIBUTES attribs;
SECURITY_DESCRIPTOR sd;

// Init.
memset(&startupInfo, 0, sizeof(startupInfo));
memset(&processInfo, 0, sizeof(processInfo));
memset(&attribs, 0, sizeof(attribs));
memset(&sd, 0, sizeof(sd));

startupInfo.cb = sizeof(startupInfo);

if (inOptions.bHideWindow)
{
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = SW_HIDE;
}

// Need a security descriptor with a NULL DACL to allow launching
// applications without running into security problems.
attribs.nLength = sizeof(SECURITY_ATTRIBUTES);
attribs.lpSecurityDescriptor = &sd;
attribs.bInheritHandle = FALSE;

if (InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
{
// Add a NULL DACL to the security descriptor.
if (SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE))
{
// Execute the supplied command line either normally, or
// while impersonating the active user.
if (inOptions.bImpersonateActiveUser)
{
// Impersonate active user, then execute the command line.
SECURITY_IMPERSONATION_LEVEL impersonationLevel =
SecurityImpersonation;
HANDLE hThreadToken = 0;
HANDLE hToken = 0;

BOOL bTmp = ImpersonateSelf(impersonationLevel);
bSuccess = OpenThreadToken(
GetCurrentThread(), // ThreadHandle
TOKEN_ALL_ACCESS, // DesiredAccess
TRUE, // OpenAsSelf
&hThreadToken); // TokenHandle
bTmp = RevertToSelf();

if (bSuccess)
bSuccess = DuplicateTokenEx(
hThreadToken, // hExistingToken
MAXIMUM_ALLOWED, // dwDesiredAccess
&attribs, //
lpTokenAttributes
impersonationLevel, //
ImpersonationLevel
TokenPrimary, // TokenType
&hToken); // phNewToken

if (hThreadToken)
CloseHandle(hThreadToken);

if (bSuccess)
bSuccess = CreateProcessAsUser(
hToken, // hToken
0, //
lpApplicationName
(LPTSTR) inCmdLine, // lpCommandLine
&attribs, //
lpProcessAttributes
&attribs, //
lpThreadAttributes
FALSE, // bInheritHandles
DETACHED_PROCESS, // dwCreationFlags
0, // lpEnvironment
0, //
lpCurrentDirectory
&startupInfo, // lpStartupInfo
&processInfo); //
lpProcessInformation

if (hToken)
CloseHandle(hToken);
}
else
{
// Execute the command line without any impersonation.
bSuccess = CreateProcess(
0, //
lpApplicationName
(LPTSTR) inCmdLine, // lpCommandLine
&attribs, //
lpProcessAttributes
&attribs, //
lpThreadAttributes
FALSE, // bInheritHandles
DETACHED_PROCESS, // dwCreationFlags
0, // lpEnvironment
0, //
lpCurrentDirectory
&startupInfo, // lpStartupInfo
&processInfo); //
lpProcessInformation
}

// If necessary, wait for the process to start/finish.
if (inOptions.bWaitForStart || inOptions.bWaitForFinish)
{
HCURSOR hWaitCursor = ::LoadCursor(NULL,
MAKEINTRESOURCE(IDC_WAIT));
HCURSOR hOldCursor = 0;

if (inOptions.bShowWaitCursor)
hOldCursor = SetCursor(hWaitCursor);

// Wait for the process to start running.
DWORD result = WaitForInputIdle(processInfo.hProcess,
30000);
if (result == WAIT_FAILED)
Sleep(100); // If WaitForInputIdle() fails, this sleep
gives the app a chance to launch.
else if (result == 0 && inOptions.bWaitForFinish)
{
// Wait for the process to terminate.
DWORD exitCode = 0;
MSG msg;

while (GetExitCodeThread(processInfo.hThread,
&exitCode)
&& exitCode == STILL_ACTIVE)
{
if (inOptions.bShowWaitCursor)
SetCursor(hWaitCursor); // Restores the wait
cursor.
Sleep(500);

// Pump Window's messages while we wait.
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}

if (inOptions.bShowWaitCursor)
SetCursor(hOldCursor);
}
}
}

// Clean up.
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
return (bSuccess ? true : false);
} // execute

Regards,
Dan





.



Relevant Pages

  • Launching an app under Vista with UAP enabled
    ... Is it possible to launch an application from a print component under Windows ... The following "execute" function is used to launch an app using the active ... SECURITY_IMPERSONATION_LEVEL impersonationLevel = ... bSuccess = OpenThreadToken( ...
    (microsoft.public.development.device.drivers)
  • Re: sp_start_job : Launching external apps
    ... All I'm doing is running a app that creates a flat file. ... Jobs are execute by SQL Server agent. ... > I'm trying to launch a VB application from a job I created. ...
    (microsoft.public.sqlserver.programming)
  • Java App CD Deployment...
    ... I am developing a simple Java Stand Alone App that shall be deployed on a CD ... The App will have a few menu selections that shall launch System Apps like ... the CD and execute the App from the CD. ...
    (comp.lang.java.programmer)
  • sp_start_job : Launching external apps
    ... I'm trying to launch a VB application from a job I created. ... When I execute the job, I'm informed that the job is processed successfully, but my app isn't launched. ... TIA ...
    (microsoft.public.sqlserver.programming)
  • Re: Windows CE Splash and Shell
    ... for each Launch key windows CE checks signal started ... dependencies before launching the App. ... Windows Embedded Manager ... have a Windows CE image with standard shell working ...
    (microsoft.public.windowsce.embedded)