在 C# 中模拟时发生未知错误 (0xfffffffe)
C# 模拟错误
您好,想要创建一个应用程序,该应用程序将赋予我使用具有此类访问权限的用户安装应用程序的权限。重要的是,具有提升权限的用户将从应用程序内部登录,这就是我一直在尝试做的事情,但似乎不起作用。
所以我所做的是使用这个库: http://impersonation.codeplex.com/
所以我可以从应用程序内模拟管理员用户。
一切正常,直到我尝试使用提升的用户访问权限实际运行应用程序,如果我不使用管理员用户登录,那么我的应用程序只会给我异常,它说访问被拒绝,当但是我使用具有这些权限的用户登录,它给了我未知错误异常,所以我想知道为什么会这样。
但是,当我尝试运行当前用户有权访问的文件时,它运行得很好。
现在可能没有任何解决方法,除非我将此应用程序作为服务运行 >,但我只是想确定。
应用程序 GUI
(来源: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());
}
}
}
}
任何帮助都是赞赏。
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
(source: upload.ee)
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论