当用户使用“以管理员身份运行"时如何使用安装程序写入用户的“我的文档"目录 [英] How to write to the user's My Documents directory with installer when the user used 'Run As Administrator'

查看:120
本文介绍了当用户使用“以管理员身份运行"时如何使用安装程序写入用户的“我的文档"目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,需要在安装时在我的文档"目录中创建文件.这是一个严格的固定要求,无法更改.问题是,如果用户对安装文件执行以管理员身份运行",则innosetups常量{userdocs}指向管理员的文档目录,而不是原始登录的用户.

I have a program that needs to create files in the My Document directory on installation. This is a strict fixed requirement, there is no changing this. Problem is that if the user does 'Run As Administrator' on the Setup file, innosetups constant {userdocs} points to the Administrator's document directory not the original logged in user.

因此,谷歌搜索并找到了这个

So, Googled and found this:

安装Windows Vista/7上的Inno安装程序将文件复制到原始用户的我的文档"文件夹中

答案是错误的,因为innosetup甚至指出

The answer is wrong, however, because innosetup even states that

如果用户通过右键单击其EXE文件并选择来启动安装程序 以管理员身份运行",那么不幸的是,此标志将没有 效果,因为安装程序没有机会使用 原始用户凭据.如果从安装程序启动安装程序也是如此 已经升高的过程.但是请注意,这不是Inno 特定于设置的限制;基于Windows Installer的安装程序无法 在这种情况下,都将返回到原始用户凭据.

If a user launches Setup by right-clicking its EXE file and selecting "Run as administrator", then this flag, unfortunately, will have no effect, because Setup has no opportunity to run any code with the original user credentials. The same is true if Setup is launched from an already-elevated process. Note, however, that this is not an Inno Setup-specific limitation; Windows Installer-based installers cannot return to the original user credentials either in such cases.

我想我可以鼓励用户不要使用以管理员身份运行",但是我不知道如何防止他进入高架状态.

I guess I can encourage the user to not use Run As Administrator but I don't know how to prevent him from not coming in elevated.

我当时在考虑让程序本身在首次运行(安装后)时设置我的文档\程序"名称目录.这种解决方法行得通吗?它必须以潜在的受限用户身份从其程序文件目录中复制文件.有可能还是会遇到特权问题?

I was thinking of maybe having the program itself set up the My Documents\Program name directory on first run (after being installed). Would this workaround work? It'd have to copy files from its program files directory as potentially limited user. Is it possible or will I run into priveleges problems?

推荐答案

原始答案正确,但不建议使用.运行安装程序时,RunAsOriginalUser将以当前登录Windows的用户身份运行. 通过不运行一部分安装程序来完成此操作,然后运行另一个已提升的副本以进行实际安装.

The answer to the original is valid but not recomended. When the setup is run, RunAsOriginalUser will run as the user currently logged into Windows. This is done by having part of the setup run unelevated, and then run another copy that is elevated to do the actual install.

当用户明确地执行以管理员身份运行"时,未提升的存根"也将提升运行,在这种情况下,由于该信息已被替换,因此设置程序无权访问原始用户.

When the user explicitly does "Run as admin", the "unelevated stub" runs elevated as well, in which case, there is nothing the setup can do to access the original user as that information has already been replaced.

公认的做法是按照您的建议在应用程序本身中进行任何特定于配置文件的工作,这也意味着它可以在Vista之前的版本中在其他用户和LUA环境中正常工作(在这种情况下,您可能会遇到与您完全相同的情况'现在正在看).

The accepted practice is to do any profile specific work in the application itself as you suggested, which also means it will work for other users and in a LUA environment in pre Vista (Where you would have had exactly the same situation that you're seeing now).

这篇关于当用户使用“以管理员身份运行"时如何使用安装程序写入用户的“我的文档"目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆