开发者

Unknown error (0xfffffffe) while impersonating in C#

开发者 https://www.devze.com 2023-04-08 10:24 出处:网络
C# Impersonate Error Hello, wanted to create an application that would give me privileges to install applications with an user that has such accesses. It\'s important that the user with elevated privi

C# Impersonate Error

Hello, wanted to create an application that would give me privileges to install applications with an user that has such accesses. It's important that the user with elevated privileges would be log onto from inside the application and thats what i've been trying to do but it seems it doesn't work.

So what i did was used this library: http://impersonation.codeplex.com/

So i could impersonate admin user from within the application.

Everything works fine until i try to actually run the application with elevated user access, if i don't log in with admin user, then my application simply gives me exception where it says that access is denied, when however i log in with user that has these privileges, it gives me unknown error exception, so im wondering why is that.

However, when i try to run file that my current user has access to, it runs just fine.

Now there probably isn't any workaround here unless i run this application as service, but i just want to make sure.

Application GUI

Unknown error (0xfffffffe) while impersonating in C#

(source: upload.ee)

Error Snapshot

Unknown error (0xfffffffe) while impersonating in C#

Full source:

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 btnOpe开发者_开发问答nFile_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());
            }
        }
    }
}

Any help is appreciated.

0

精彩评论

暂无评论...
验证码 换一张
取 消