Old 15th September 2011, 17:26   #1
highend
Junior Member
 
Join Date: Sep 2011
Posts: 12
Writing HKCU entries - UAC?

Hi,

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):

code:
;---Definitions----

!define SNAME "Evernote"

;----Includes----

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

;-----Runtime switches----
CRCCheck off
AutoCloseWindow True
SilentInstall silent
WindowIcon off
XPSTYLE on
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 "0.1.0.0"
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"

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

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

;-----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
${EndIf}

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

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

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
${EndIf}

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

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

;-----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
${EndIf}

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"

SectionEnd

highend is offline   Reply With Quote
Old 16th September 2011, 00:19   #2
highend
Junior Member
 
Join Date: Sep 2011
Posts: 12
Mh, can't find a way to edit my first post

It's solved, the original registry plugin isn't able to use restorekey without elevation...
highend is offline   Reply With Quote
Old 16th September 2011, 04:42   #3
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
(Next time, please use pastebin or an attachment to share large amounts of code.)
MSG is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
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