皮条客我的UAC和它的几个问题 [英] Pimp my UAC and a few questions about it

查看:134
本文介绍了皮条客我的UAC和它的几个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的应用程序,需要做一些事情的保护路径(如%PROGRAMFILES%),我知道我应该使用%APPDATA%,但我不能改变的现在。我已经分离出所有的事情,可能需要UAC来显示在另一个项目中,这里是一个示例code:

I have this application that need to do some things in protected paths (like %PROGRAMFILES%), I know that I should be using %APPDATA%, but I can't change that for now. I have isolated all the things that could require UAC to show up on another project, here's a sample code:

using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

class Class1
{
    static void Main(string[] args)
    {
        try
        {
            File.CreateText(Path.Combine(Application.StartupPath, "something.txt"));
        }
        catch (UnauthorizedAccessException ex)
        {
            MessageBox.Show(ex.Message, "UnauthorizedAccessException", MessageBoxButtons.OK, MessageBoxIcon.Error);

            if (args.Length == 0)
            {
                Process proc = new Process();
                proc.StartInfo.FileName = Application.ExecutablePath;
                proc.StartInfo.Arguments = "not again";
                proc.StartInfo.Verb = "runas";
                proc.Start();
            }
            else
            {
                MessageBox.Show("Exit to avoid loop.");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}

所以,我把这个可执行文件从我的主程序,如果失败,因为一个未经授权的访问,也将推出自己显示UAC要求。

So, I call this executable from my main program, and if it fails because of an unauthorized access, it will launch itself showing the UAC request.

我的问题是:

1),我不得不从DLL输出项目转换为EXE,因为我找不到任何办法从DLL要求UAC提升,有没有什么简单的方法来做到这一点?

1) I had to convert the project output from a DLL to an EXE because I couldn't find any way to request UAC elevation from a DLL, is there any easy way to do that?

2)我也注意到,一些程序显示一个个性化的UAC消息,随着计划徽标和所有这些事情,让我告诉你一个例​​子:

2) I also noticed that some programs show a personalized UAC message, with the program logo and all those things, let me show you an example:

我怎样才能做到这一点对我的程序?

How can I do that for my program?

3)为了避免进入一个循环时使用提升的权限运行它得到另一个UnauthorizedAccessException我做那件事经过任何的args。你会怎么做来达到同样的目标?

3) To avoid entering in a loop when is running with elevated privileges an it gets another UnauthorizedAccessException I did that thing passing any args. What would you do to achieve the same goal?

我想这就是现在。感谢您的时间。

I think that's all for now. Thanks for your time.

推荐答案

1,你无法控制你的托管DLL进程的海拔模式。您可以授予权限到目标文件夹或注册表为大家<一个HREF =htt​​p://msdn.microsoft.com/en-us/library/d9k65z2d.aspx>在安装过程中如果你能控制的安装过程。

1 you can not control the elevation mode of the process hosting your DLL. You can grant permission to the target folder or registry for everyone during the install process if you can control install process.

2,你需要<一个href="http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/50a72eb8-298b-4302-9651-aed0169de1c9/">sign该程序与由将由客户端的被信任的证书授权发布的证书。访问你的本地证书存储区(控制面板 - > Internet选项,内容选项卡中,发布者)看到常见的证书颁发机构。

2 you need to sign the program with a certificate published by a certificate authority that would be trusted by the client. Visit your local certificate store (control panel->internet options, content tab, publishers) to see common certificate authorities.

3,当你得到UnauthorizedAccessExceotion,把它给托管EXE或返回错误值,表明存在安全问题。您的DLL的调用者再决定该怎么做,如显示安全错误对话框,告知用户如果程序已经升高(未授予域控制器允许吗?),或的,如果它没有升高msdn.com/vistacompatteam/archive/2006/09/25/771232.aspx">restarting~~V升高模式中的过程。

3 when you get UnauthorizedAccessExceotion, throw it to the hosting exe or return an error value indicating a security problem. The caller of your DLL then decide what to do, such as displaying a security error dialog to inform the user if the program is already elevated (permission not granted by domain controller?) , or restarting the process in elevated mode using the runas command if it is not elevated.

这篇关于皮条客我的UAC和它的几个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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