我想将我的应用程序存储在当前用户的AppData
目录中,以避免自动更新我们的应用程序(当它存储在Program Files中时)所具有的权限问题。 我们不给用户select在哪里安装应用程序。 我们有非pipe理员用户的抱怨,安装程序将应用程序存储在pipe理员的AppData
目录(当然是UAC之后),而不是当前用户的AppData
目录,这会阻止应用程序在未来运行。
首先,我有DefaultDirName={userappdata}\{#MyAppName}
。 然后我试着DefaultDirName={commonappdata}\{#MyAppName}
。 然后,我试着与PrivilegesRequired=lowest
,甚至作为PrivilegesRequired=none
作为创buildInnoSetup安装程序请求权限提升只有当需要问题build议。
这是我现在的脚本,以防万一我失去了一些显而易见的东西:
; Script generated by the Inno Setup Script Wizard. ;SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "Teamwork Chat" #define MyAppVersion "0.10.0" #define MyAppPublisher "Digital Crew, Ltd." #define MyAppURL "http://www.teamwork.com/" #define MyAppExeName "TeamworkChat.exe" [Setup] ; NOTE: The value of AppId uniquely identifies this application. ; Do not use the same AppId value in installers for other applications. ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) AppId={{0F063485-F5AF-4ADE-A9F9-661AB3BAA661} AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} DefaultDirName={userappdata}\{#MyAppName} DisableDirPage=yes DefaultGroupName={#MyAppName} OutputDir=E:\chat-client\dist OutputBaseFilename={#MyAppName}_for_Windows32_Installer-{#MyAppVersion} SetupIconFile=E:\chat-client\icons\teamwork_chat.ico WizardImageFile=E:\chat-client\icons\chatWizardImageFile.bmp Compression=lzma SolidCompression=yes PrivilegesRequired=none [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files] Source: "E:\chat-client\dist\TeamworkChat\win32\TeamworkChat.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "E:\chat-client\dist\TeamworkChat\win32\ffmpegsumo.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "E:\chat-client\dist\TeamworkChat\win32\icudtl.dat"; DestDir: "{app}"; Flags: ignoreversion Source: "E:\chat-client\dist\TeamworkChat\win32\libEGL.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "E:\chat-client\dist\TeamworkChat\win32\libGLESv2.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "E:\chat-client\dist\TeamworkChat\win32\nw.pak"; DestDir: "{app}"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon [Run] Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
我改变了两个select,但仍然没有运气;
PrivilegesRequired=lowest ... [Icons] ... Name: "{userdesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
我已经添加runasoriginaluser
标志,并生成一个新的AppId
(GUID),但仍然没有运气;
[Run] Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent runasoriginaluser
我用源文件和Inno脚本创build了一个简单的GitHub仓库 。
我一直在Windows 8.1上testing。 它似乎在Windows 7上编译时运行,并在Windows 8上运行,但在8上编译和8上运行时不起作用。
现在已经解决了,但要清除关于编辑4的事情,它不能只在我的机器上工作。 它在其他Windows 8机器上工作。 一定是一些奇怪的caching或什么(即使我改变了AppId
)。
从你的问题的措辞,如果我正确地理解你,这听起来像这是因为你是“验证管理员帐户的安装运行”。 如果是这种情况,并且您在UAC提示符处输入了与您登录的帐户不同的帐户,那么当前用户实际上将成为您在UAC提示符处输入的管理员帐户,而不是您记录的帐户与…一起。 因此,只要您被要求使用UAC提升安装,它就不会在登录用户的AppData目录中结束。
您可能需要做的是使用runasoriginaluser
函数,该函数将使用登录的用户凭证而不是在UAC提示符处输入的帐户,或者查找导致UAC提升提示的内容。
另请参阅Inno安装程序为登录用户(不是管理员用户)创建注册表项 。
安装上下文的MSDN文档也可能是有用的。
它应该与PrivilegesRequired=lowest
。 这是正确的方法。 如果没有,我们希望看到一个日志文件。
lowest
会使安装程序在当前非特权用户的上下文中运行。 因此,像{userappdata}
, {userdesktop}
等所有常量将引用当前用户。
无论如何,要回答你的问题,你可以使用下面的代码。
但是,这只是在特殊情况下,当安装程序确实需要管理员权限(例如注册某些系统DLL),但仍然需要为原始用户部署文件。 像这样: Inno Setup – 以管理员身份注册组件 。
[Files] Source: "MyProg.exe"; DestDir: "{code:GetAppData}" [Code] var AppDataPath: string; function GetAppData(Param: string): string; begin Result := AppDataPath; end; function InitializeSetup(): Boolean; var Uniq: string; TempFileName: string; Cmd: string; Params: string; ResultCode: Integer; Buf: AnsiString; begin AppDataPath := ExpandConstant('{userappdata}'); Log(Format('Default/Fallback application data path is %s', [AppDataPath])); Uniq := ExtractFileName(ExpandConstant('{tmp}')); TempFileName := ExpandConstant(Format('{commondocs}\appdata-%s.txt', [Uniq])); Params := Format('/C echo %%APPDATA%% > %s', [TempFileName]); Log(Format('Resolving APPDATA using %s', [Params])); Cmd := ExpandConstant('{cmd}'); if ExecAsOriginalUser(Cmd, Params, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0) then begin if LoadStringFromFile(TempFileName, Buf) then begin AppDataPath := Trim(Buf); Log(Format('APPDATA resolved to %s', [AppDataPath])); end else begin Log(Format('Error reading %s', [TempFileName])); end; DeleteFile(TempFileName); end else begin Log(Format('Error %d resolving APPDATA', [ResultCode])); end; Result := True; end;
更多类似的问题: