访问“程序文件”;需要文件夹
我遇到了这个经常提到的问题,但即使在查找了几乎所有资源之后,我也没有得到答案。问题如下:
我编写了一个小更新程序工具,它连接到服务器以检查应用程序的新版本,然后将新版本复制到客户端机器。所以模式如下:
客户端安装由我使用特定应用程序预先配置的更新程序。所以基本上更新程序位于 Program Files 文件夹中的某个位置。然后更新程序启动,连接到我们的服务器并获取最新版本并将其安装到与安装更新程序相同的目录中。所以客户端不知道有两个应用程序。更新程序和更新程序的主要应用程序。我希望你能明白。
这就是为什么我需要访问 Program Files 文件夹。
我正在Windows 7下开发,该软件也可以在7上运行。
有没有办法确保更新程序由管理员运行。我需要管理员权限才能访问它吗?即使我确实拥有管理员权限,它仍然拒绝访问,还有什么?有没有办法在代码中检查用户拥有哪些权限?
I ran into this quite often stated problem but even after looking up nearly every scource I didn’t get an aswer. Problem is as follows:
I wrote a little updater tool that connects to a server to check for new versions of an application and then copies the new version to the clientmashine. So the pattern is as follows:
Client installs the updater which is pre configured by me with a specific application. So basicly the updater is somewhere in the Program Files Folder. Then the updater is started, connects to our server and gets the newest version and installs it to the very same dir as the updater is installed. So the client doesn’t know there are two applications. the updater and the main application the updater is for. I hope you get the idea.
So this is why I need access to the Program Files folder.
I am developing under windows 7 and the software is to run on 7 as well.
Is there a way to make sure the updater is run by administrator. Do I need admin rights to access it? What else since it denies access even if I do have admin rights? Is there a way to check in code what rights a user has?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的应用程序中使用 app.manifest。将 requireadministrator 设置为 true。或复制粘贴上面的以下 xml
是 vb.net 应用程序的。
Use app.manifest in your app. Set requireadministrator to true. or copy paste the below xml
above is of an vb.net app.
我会将检查器和更新器分成两个不同的应用程序。检查器可以以普通用户身份运行。当它检测到有更新时,它会启动更新程序。对于更新程序,您有声明其需要管理员权限的清单 。这将导致提示用户授予访问权限(假定已启用 UAC)。
I would split the checker and the updater into two different apps. The checker can run as the regular user. When it detects that there is an update, it launches the updater. For the updater you have a manifest that states that it needs admin rights. This will cause the user to be prompted to grant access (given that UAC is enabled).
由于 Vista、7 和 2008 服务器上的安全模型,您应该创建一个清单来告诉用户您的应用程序需要什么级别的访问权限,并让它自动提示管理权限(如果它们在没有 UAC 的情况下运行)。
频道 9 - 如何:告诉 Vista 的 UAC 您的应用程序需要什么权限级别
频道 9 - 如何:使用 Vista 的 UAC 功能避免始终需要管理员权限
MSDN - Windows Vista 和 Windows Server 2008 开发人员故事:用户帐户控制 (UAC) 的 Windows Vista 应用程序开发要求
UAC 团队博客
代码项目 - Vista Bridge(许多新 Vista/7/ 的托管包装器) 2008 年特色)
Due to the security model on Vista, 7, and 2008 server you should create a manifest to tell the use what level of access your application requires and to have it automaticly prompt for administrative rights (if they are running without UAC.)
Channel 9 - How To: Tell Vista's UAC What Privelege Level Your App Requires
Channel 9 - How To: Use Vista's UAC Feature To Avoid Always Requiring Admin Rights
MSDN - The Windows Vista and Windows Server 2008 Developer Story: Windows Vista Application Development Requirements for User Account Control (UAC)
UAC Team Blog
Code Project - Vista Bridge (Managed Wrapper for many of the new Vista/7/2008 features)