Prev Previous Post   Next Post Next
Old 15th September 2011, 18:26   #1
Junior Member
Join Date: Sep 2011
Posts: 12
Writing HKCU entries - UAC?


I'm trying to make Evernote portable with NSIS. I wrote a small script for this purpose.

When Evernote is started it wants to create HKEY_CURRENT_USER\Software\Evernote (with it's settings stored there) but UAC kicks in and asks if the user wants to allow this program to make changes to the system. I don't know why this happens because the current logged in user should always be able to write to his own user registry path.

If I add RequestExecutionLevel user to the script, UAC isn't used but the script seems not be able to import the necessary regfile (Settings [Install].reg) because Evernote thinks it has never been started before (and the regfile contains all necessary entries for it's key).

What am I doing wrong?

The script (atm it contains some lines that I could delete (e.g. for the x64 / x86 stuff, Evernote is only a true 32 bit application):


!define SNAME "Evernote"


!include "LogicLib.nsh"
!include "Registry.nsh"

;-----Runtime switches----
CRCCheck off
AutoCloseWindow True
SilentInstall silent
WindowIcon off
RequestExecutionLevel user

;-----Set basic information-----

Name "${SNAME}"
Icon "${SNAME}.ico"
Caption "${SNAME} Launcher"
OutFile "..\${SNAME}.exe"

;-----Version Information------

LoadLanguageFile "${NSISDIR}\Contrib\Language files\English.nlf"

VIProductVersion ""
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "Evernote Launcher"
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "©2011"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "Evernote"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "1.0"

Section "Main"

;---Initialize variables
Var /GLOBAL WindowClass
Var /GLOBAL AppNameX64
Var /GLOBAL AppNameX86
Var /GLOBAL BackgroundProcessName
Var /GLOBAL OSArchitecture
Var /GLOBAL UserName

;---Populate variables
StrCpy $WindowClass "ENMainFrame"
StrCpy $AppNameX64 "EvernoteTray.exe"
StrCpy $AppNameX86 "EvernoteTray.exe"
StrCpy $BackgroundProcessName "EvernoteClipper.exe"

System::Call "advapi32::GetUserName(t .r0, *i ${NSIS_MAX_STRLEN} r1) i.r2"
StrCpy $UserName "$0"

IfFileExists "$WINDIR\SysWoW64\*.*" "" +3
StrCpy $OSArchitecture "x64"
Goto +2
StrCpy $OSArchitecture "x86"

FindWindow $R0 "$WindowClass" ""
IntCmp $R0 1 "" +3
MessageBox MB_OK|MB_ICONEXCLAMATION "${SNAME} is already running, aborted!"

;-----Saving Local Registration Data------

${registry::KeyExists} "HKEY_CURRENT_USER\Software\Evernote" $R0
${if} $R0 == "0"
${registry::SaveKey} "HKEY_CURRENT_USER\Software\Evernote" "$EXEDIR\Data\.LocalSettings.reg" "/G=1" $R0
Sleep 250

;-----Importing Regkeys------

${registry::KeyExists} "HKEY_CURRENT_USER\Software\Evernote" $R0
${if} $R0 == "0"
DeleteRegKey HKEY_CURRENT_USER "Software\Evernote"
Sleep 100

IfFileExists "$EXEDIR\Data\Settings [Install].reg" "" +3
${registry::RestoreKey} "$EXEDIR\Data\Settings [Install].reg" $R0
Sleep 250

${registry::KeyExists} "HKEY_CURRENT_USER\Software\Evernote" $R0
${if} $R0 == "0"
WriteRegStr HKEY_CURRENT_USER "Software\Evernote\Evernote" "EvernotePath" "$EXEDIR\Data"
WriteRegStr HKEY_CURRENT_USER "Software\Evernote\Evernote\AutoUpdate" "AutoUpdateCacheCurrentRN" "$EXEDIR\Data\AutoUpdate\CurrentReleaseNotes.html"
WriteRegStr HKEY_CURRENT_USER "Software\Evernote\Evernote\AutoUpdate" "AutoUpdateCacheCurrentXML" "$EXEDIR\Data\AutoUpdate\current.xml"
Sleep 100

;-----Launching Application------

${if} $OSArchitecture == "x64"
ExecWait '"$EXEDIR\App\$AppNameX64"'
${elseif} $OSArchitecture == "x86"
ExecWait '"$EXEDIR\App\$AppNameX86"'

;-----Cleaning up------

KillProcDLL::KillProc "$BackgroundProcessName"
Sleep 100

${registry::KeyExists} "HKEY_CURRENT_USER\Software\Evernote" $R0
${if} $R0 == "0"
${registry::SaveKey} "HKEY_CURRENT_USER\Software\Evernote" "$EXEDIR\Data\Settings [Install].reg" "/G=1" $R0
Sleep 250

IfFileExists "$EXEDIR\Data\Settings [Remove].reg" "" +3
${registry::RestoreKey} "$EXEDIR\Data\Settings [Remove].reg" $R0
Sleep 250

;-----Restoring Local Registration Data------

IfFileExists "$EXEDIR\Data\.LocalSettings.reg" "" +4
${registry::RestoreKey} "$EXEDIR\Data\.LocalSettings.reg" $R0
Sleep 250
Delete "$EXEDIR\Data\.LocalSettings.reg"


highend is offline   Reply With Quote
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

permissions, uac

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump