Unknown error (0xfffffffe) while impersonating in C#

1

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

Application GUI
(source: upload.ee)

Error Snapshot

Error Snapshot

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 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());
            }
        }
    }
}

Any help is appreciated.

c#
elevated-privileges
impersonation
asked on Stack Overflow Sep 23, 2011 by Ardi Vaba • edited Aug 13, 2019 by Glorfindel

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0