如何解决如何使用特定用户执行外部 exe
我正在制作一个需要使用 FileSystemWatcher 监视文件系统的应用程序,以检测安装如何影响文件系统。
为了消除噪音,我想过滤由其创建用户创建的事件,并且该代码与 //BUILTIN //Administrator 用户一起使用,在进行安装时默认使用该用户。但仍然有相当多的噪音。然后我有了创建一个特定用户的想法,我可以用它来运行安装文件,并过滤该特定用户,从而消除几乎所有的噪音。
这是我的流程创建和启动代码
private void executeInnoInstaller(string path,string fileName)
{
// Use ProcessStartInfo class
ProcessStartInfo installerProces = new ProcessStartInfo();
installerProces.CreateNoWindow = true;
installerProces.UseShellExecute = false;
installerProces.FileName = path + "\"" + fileName + "\"";
installerProces.WindowStyle = ProcessWindowStyle.Normal;
installerProces.UserName = "test";
System.Security.SecureString encPassword = new System.Security.SecureString();
foreach (System.Char c in "test")
{
encPassword.AppendChar(c);
}
encPassword.MakeReadOnly();
installerProces.Password = encPassword;
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(installerProces))
{
exeProcess.WaitForExit();
//int exitCode = exeProcess.ExitCode;
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
此代码退出并拒绝访问。
操作系统=Windows
我已经尝试使用 SHIFT 从操作系统文件处理程序运行 installer.exe - 使用指定的用户右键单击,并且它可以工作。 VisualStudio 以管理员身份运行。 我曾尝试以管理员身份运行构建项目exe文件,但它不起作用。
在没有用户凭据的情况下,代码工作并使用 //BUILTIN //Administrator 帐户
有人知道吗?
预先感谢您的时间和精力。
解决方法
如果我将 UAC 安全级别调低到最低,则此代码有效。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。