Skip to content
⌘ NSIS Forum Archive

Shortcuts on Vista

119 posts

Anders#
* Check wiki for new version with basic language support. (See readme.txt and UAC_RealWorldExample.nsi)

Yes, on < Vista you can send messages to any window. I know I can use ChangeWindowMessageFilter to allow messages from the outer instance, but that would add possible security issues.

You can read the HKCU part of the registry from the inner instance unless the permissions on that key has done something to block admins (You would probably never see this in practice) You can probably do something with the access control plugin to make sure the inner instance can read from the outer instance's $pluginsdir.

I'm not sure if I want to add support for any kind of message passing from outer to inner, but you are free to fork the code ofcourse. The UAC plugin is all about support for all users type installers so why would you read user specific values?
RichZ#
Anders,

I've been playing around with your plug-in and my installer now works perfectly under a limited Vista account.

I did however notice a problem with the uninstaller; When I start the uninstaller the Vista elevation dialog pops up as expected, when I enter the correct info and click OK my uninstaller UI however doesn't pop up.
When I check the task manager I do see 2 uninstaller processes running, 1 as a normal user and 1 as an administrator.

After some investigation I noticed that this problem only occurs when my uninstaller uses the Modern UI. When I do not use the modern UI the uninstaller works as expected. Do you have any idea what's going on?
If you need any more info from me please let me know.
stb#
I noticed a similar issue with Vista (which seems to be a Vista bug) and solved the problem by calling

ShowWindow $HWNDPARENT "${SW_SHOW}"

in the show callback function of the first visible GUI page (welcome page).
RichZ#
Originally posted by stb
I noticed a similar issue with Vista (which seems to be a Vista bug) and solved the problem by calling

ShowWindow $HWNDPARENT "${SW_SHOW}"

in the show callback function of the first visible GUI page (welcome page).
Thanks, I have added a custom callback function to the uninstaller as you described and this fixed it. For me the problem only occurs for the uninstaller and not for the installer which to me seems kind of strange (what's the difference between installing and uninstalling for the OS?).
If anybody is interested I have added the following code to my script:


!define MUI_CUSTOMFUNCTION_UNGUIINIT un.GUIInit

Function un.GUIInit
ShowWindow $HWNDPARENT "${SW_SHOW}"
FunctionEnd
stb#
I noticed this in the installer with UAC disabled in Vista when self-executing the installer (copy in TEMP). This inner process (outer is finished because it doesn't wait) did not show any GUI Window (style was invisible). With XP SP2 this window was always visible.

Thanks for the hint to GUIINIT, I think that location is better.
RichZ#
Originally posted by stb
I noticed this in the installer with UAC disabled in Vista when self-executing the installer (copy in TEMP). This inner process (outer is finished because it doesn't wait) did not show any GUI Window (style was invisible). With XP SP2 this window was always visible.

Thanks for the hint to GUIINIT, I think that location is better.
I cannot reproduce what you describe above, what do you mean by "self-executing the installer (copy in TEMP)"?

Also for Anders I noticed another glitch.
On one of my test machines (actually a VMware machine) I have an administrator account without a password (I know this is unsafe 😉). With UAC disabled I get a nice run as dialog, I am however not able to use my administrator account because of the blank password.
Anders#edited
First off, I am able to reproduce the invisible uninstaller window on XP Pro SP2. Will try to look into this at some point. For now, use the showwindow hack

Edit: I think i fixed it, please try with the latest version on the wiki


RichZ: Could you take a screenshot of the dialog? Do you get a error message?
RichZ#
Originally posted by Anders
First off, I am able to reproduce the invisible uninstaller window on XP Pro SP2. Will try to look into this at some point. For now, use the showwindow hack

Edit: I think i fixed it, please try with the latest version on the wiki


RichZ: Could you take a screenshot of the dialog? Do you get a error message?
I have attached a screenshot, it states that a possible reason can be because of a blank password, but I have not enforced such a policy.
Anders#
I wanted a screenshot of the runas dialog and not the error but it doesnt really matter.

There is nothing i can do about this, CreateProcessWithLogonW fails with blank passwords by default. You can set limitblankpassworduse=0 in HKLM\SYSTEM\CurrentControlSet\Control\Lsa to override this
RichZ#
Originally posted by Anders
I wanted a screenshot of the runas dialog and not the error but it doesnt really matter.

There is nothing i can do about this, CreateProcessWithLogonW fails with blank passwords by default. You can set limitblankpassworduse=0 in HKLM\SYSTEM\CurrentControlSet\Control\Lsa to override this
Alright, thanks for the solution, not a big problem because a blank administrator password is not what you want anyway 😉

I will test your solution for the invisible dialog later on.
RichZ#
Anders, I have checked the latest build (v0.0.6b) and the problem with the invisible dialogs is indeed fixed, thanks for the quick response. 👍
RichZ#
Originally posted by Anders
If you turn UAC on, will it elevate even if the admin password is blank?
Yes with UAC on there is no problem, it will elevate with an empty admin password.
helix400#
Oh good, the UAC plugin is still improving. 🙂

Just to let you know Anders, we've deployed an installer containing it to several hundreds people so far. There haven't been any issues found by anyone yet.
introspect#
source for UAC plugin not compiling

I am sure I am just being stupid here but I can't get the uac plugin source to compile (found here: http://nsis.sourceforge.net/UAC_plug-in)

TokenOrigin is not defined. Where is TokenOrigin defined?

Anyways TokenOrigin is being used in the UAC.h header file in this enum definition:
enum _TOKEN_INFORMATION_CLASS___VISTA {
TokenElevationType = (TokenOrigin+1),
TokenLinkedToken,
TokenElevation,
TokenHasRestrictions,
TokenAccessInformation,
TokenVirtualizationAllowed,
TokenVirtualizationEnabled,
TokenIntegrityLevel,
TokenUIAccess,
TokenMandatoryPolicy,
TokenLogonSid,
};

Thanks in advance for any help you can provide, and my apologies if this is the wrong place to post this.
Anders#
in WinNT.h (You need a somewhat recent Platform sdk, mine is from 2003)

_TOKEN_INFORMATION_CLASS___VISTA is my fake enum since I don't have the latest Platform SDK installed
RobertStrong#
Anders, would you consider adding a method that created a process using CreateProcessWithTokenW using the desktop's token? This would allow an uninstaller to create a process that isn't elevated. I can provide the code to accomplish this and it seems that this would be a good plugin to add this to vs. creating a plugin that just did this.
Anders#
Yeah, I would consider it (Depending on how you get this token, remember, the user could use a shell that is not explorer.exe etc.)
RobertStrong#
Something like this?

extern "C"
void __declspec(dllexport) LaunchWithTopMostWinToken(HWND hWndParent, int string_size,
char *variables, stack_t **stacktop,
extra_parameters *extra)
{
EXDLL_INIT();
{
char szCmdLine[MAX_PATH];

if (popstring(szCmdLine) == 0)
{
if (!pCreateProcessWithTokenW)
{
// CreateProcessWithTokenW is not present on WinXP or earlier
*(FARPROC *)&pCreateProcessWithTokenW =
GetProcAddress(GetModuleHandle("advapi32.dll"),
"CreateProcessWithTokenW");
if (!pCreateProcessWithTokenW)
{
pushstring(OUT_ERR);
return;
}
}
// use the token from the topmost window (highest in the z-order) to drop the privilege
HWND hwndTopMostWin = GetWindow(hWndParent, GW_HWNDFIRST);

DWORD dwProcessId;
GetWindowThreadProcessId(hwndTopMostWin, &dwProcessId);

HANDLE hProcessTopMostWin = OpenProcess(MAXIMUM_ALLOWED, FALSE, dwProcessId);
if (!hProcessTopMostWin)
{
pushstring(OUT_ERR);
return;
}

HANDLE hTokenTopMostWin;
BOOL ok = OpenProcessToken(hProcessTopMostWin, MAXIMUM_ALLOWED, &hTokenTopMostWin);
CloseHandle(hProcessTopMostWin);
if (!ok)
{
pushstring(OUT_ERR);
return;
}

HANDLE hNewToken;
ok = DuplicateTokenEx(hTokenTopMostWin,
MAXIMUM_ALLOWED,
NULL,
SecurityDelegation,
TokenPrimary,
&hNewToken);
CloseHandle(hTokenTopMostWin);
if (!ok)
{
pushstring(OUT_ERR);
return;
}

STARTUPINFOW si = {sizeof(si), 0};
PROCESS_INFORMATION pi = {0};

WCHAR wszCmdLine[MAX_PATH * 2];
MultiByteToWideChar(CP_ACP, 0, szCmdLine, lstrlen(szCmdLine) + 1,
wszCmdLine, sizeof(wszCmdLine) / sizeof(wszCmdLine[0]));

if (wszCmdLine)
{
ok = pCreateProcessWithTokenW(hNewToken,
0, // profile is already loaded
NULL,
wszCmdLine,
0, // No special process creation flags
NULL, // inherit my environment
NULL, // use my current directory
&si,
&pi);
}
CloseHandle(hNewToken);
if (ok)
{
pushstring(OUT_SUCCESS);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return;
}

}
pushstring(OUT_ERR);
}
}
RobertStrong#
Forgot pCreateProcessWithTokenW

BOOL (WINAPI *pCreateProcessWithTokenW)(HANDLE,
DWORD,
LPCWSTR,
LPWSTR,
DWORD,
LPVOID,
LPCWSTR,
LPSTARTUPINFOW,
LPPROCESS_INFORMATION);
Anders#
I'm sorry, but that is horrible, you just use some random window token. Can you get the token for GetDesktopWindow() or is that restricted somehow?

What about Win2000/XP ?
RobertStrong#
GetDesktopWindow didn't work and I didn't spend any time trying to figure out what was up with this. I'll look into what's going on.

Regarding Win2K/XP the comment:
// CreateProcessWithTokenW is not present on WinXP or earlier
so it returns an error allowing fallback to Exec, ExecShell, etc.
RobertStrong#
I understand a solution for the runas on systems without UAC or UAC is turned off would be a wonderful thing but that is highly unlikely from what I have read of other people's struggles with this (e.g. using task scheduler... I mean damn!). 😉

On the other hand being able to launch an app at the end of uninstall (e.g. option to open a web page) which is typically not elevated through runas (e.g. ARP or Programs and Features) though on Vista with UAC turned on is elevated would be a good thing. If a 100% solution were possible I'd certainly go for it but without that I am willing to settle for good vs. perfect since perfect isn't an option from what I have read on this scenario.

I'll probably just provide the option when the progman window is available to avoid using a random window and throw together a simple plugin to provide this when the target is Vista with UAC turned on.
Anders#
ExecShell should open a http:// style URL without elevation no?

There is another problem, ARP is disabled untill all subprocesses finish, I created a hacky workaround for that @http://nsis.sourceforge.net/Escape_A...th_New_Process (Not tested on vista)
RobertStrong#
No, it regretfully inherits from the process that calls ShellExecute.

Thanks for the pointer on the workaround using JOB_OBJECT_LIMIT_BREAKAWAY_OK. That has been an annoyance for a long time.
M-Force#
UAC-Plugin - Multiple security warnings on Vista

Hi,

i have a problem with the UAC-plugin on vista.

After i clicked the button on my web page to download my installer, vista is poping up first a "File Download - Security Warning" with information about Name, Type and From. I think this i normal behavior.

After i confirm with clicking the "Run" button another security warning is poping up. This "Internet Explorer - Security warning" is asking if the software of a certain Name and Publisher is allowed to run. I think this is normal as well.
After i confirm "Run" i get a third security popup "Open File - Security Warning" which is asking if i want to run a file which is described with Name, Publisher, Type and where from. This file has the same name as my Installer except the installer name got a number suffix like Installer[2].exe and moreover it is stored under "c:\user\<account>\AppData\Microsoft\Wind...". Thats all what i can read from that path.
After i confirm the third installer and click on "Run" finally my installer window is coming up.

I dont think the third security warning should come up. It would only confuse the user.
Can you confirm such behavior? Is that normal?

Thank you for your help.

M.
Anders#
This is probably not related to the UAC plugin

See http://forums.winamp.com/showthread....hreadid=278784
M-Force#
UAC-plugin security popups

Hi Anders,

before I included the UAC plugin in my script i only got the popup windows "File Download - Security Warning" for allowing to download and the "User Account Control" for running the installer. The disadvatage was that the installer window was not in focus after I confirmed the "User Account Control" window.

So by using the UAC-plugin my installer window is now in focus when it got started, but i have all the security warnings inbetween. ( "Internet Explorer - Security warning" and "Open File - Security Warning"). Havent had these security warnings without the UAC.

Therefore i was assuming the UAC raises such warnings.

M.
Anders#
The UAC plugin will start the SAME exe one more time, so you might get another IE warning dialog, I don't know. Make sure you are have "RequestExecutionLevel user" in your script. If you can post a minimal sample script with this problem I might be able to look into it and see if I can come up with a fix