1

C# 模拟错误

您好,想创建一个应用程序,让我有权使用具有此类访问权限的用户安装应用程序。重要的是,具有提升权限的用户将从应用程序内部登录,这就是我一直在尝试做的,但它似乎不起作用。

所以我所做的是使用这个库:http: //impersonation.codeplex.com/

所以我可以从应用程序中模拟管理员用户。

一切正常,直到我尝试以提升的用户访问权限实际运行应用程序,如果我不使用管理员用户登录,那么我的应用程序只会给我一个异常,它说访问被拒绝,但是当我使用该用户登录时拥有这些特权,它给了我未知的错误异常,所以我想知道为什么会这样。

但是,当我尝试运行我当前用户有权访问的文件时,它运行得很好。

现在可能没有任何解决方法,除非我将此应用程序作为服务运行,但我只是想确保

应用程序图形用户界面

应用程序图形用户界面
(来源:upload.ee

错误快照

错误快照

完整来源:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Diagnostics;

using Iuf.Network.Authentication;

namespace AccessPool
{
    public partial class Form1 : Form
    {
        Impersonation UserAccess;
        Process FileProcess;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void btnButton_Click(object sender, EventArgs e)
        {
            UserAccess = new Impersonation(txtUsername.Text, txtPassword.Text, "ametikool.local");

            try
            {
                UserAccess.ImpersonateUser();
            }
            catch (Exception ImpersonateException)
            {
                MessageBox.Show(ImpersonateException.ToString());
            }
            finally
            {
                MessageBox.Show("Access granted!");
                btnOpenFile.Enabled = true;
            }
        }

        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog FileDialogObject = null;

            try
            {
                FileDialogObject = new OpenFileDialog();
                FileDialogObject.ShowDialog();
            }
            catch (Exception FileDialogException)
            {
                MessageBox.Show(FileDialogException.ToString());
                return;
            }
            finally
            {
                txtFilePath.Text = FileDialogObject.FileName;
            }
        }

        private void btnRun_Click(object sender, EventArgs e)
        {
            try
            {
                FileProcess = new Process();
                FileProcess.StartInfo.FileName = txtFilePath.Text;
                FileProcess.Start();
            }
            catch (Exception FileProcessException)
            {
                MessageBox.Show(FileProcessException.ToString());
            }
        }
    }
}

任何帮助表示赞赏。

4

0 回答 0