相关疑难解决方法(0)

提升权限不适用于UseShellExecute = false

我想启动一个具有提升权限但具有隐藏窗口的子进程(实际上是相同的控制台应用程序).

我做下一个:

var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location)
{
    UseShellExecute = true, // !
    Verb = "runas", 
};

var process = new Process
{
    StartInfo = info
};

process.Start();
Run Code Online (Sandbox Code Playgroud)

这工作:

var identity = new WindowsPrincipal(WindowsIdentity.GetCurrent());
identity.IsInRole(WindowsBuiltInRole.Administrator); // returns true
Run Code Online (Sandbox Code Playgroud)

但是UseShellExecute = true创建了一个新窗口,我也无法重定向输出.

所以我下次做的时候:

var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location)
{
    RedirectStandardError = true,
    RedirectStandardOutput = true,
    UseShellExecute = false, // !
    Verb = "runas"
};

var process = new Process
{
    EnableRaisingEvents = true,
    StartInfo = info
};

DataReceivedEventHandler actionWrite …
Run Code Online (Sandbox Code Playgroud)

c# uac processstartinfo elevated-privileges

18
推荐指数
2
解决办法
2万
查看次数

Foo.cmd不会输出正在处理的行(在网站上)

我在理解.NET中ProcessStartInfo类的in和out时遇到了问题.我使用这个类来执行像FFmpeg这样的.exe程序,没有任何问题.

但是,当我使用ProcessStartInfo启动.cmd程序时,就像一个简单的foo.cmd只包含@echo Hello world它不会输出任何内容.

    ProcessStartInfo oInfo = new ProcessStartInfo(@"C:\Program Files (x86)\itms\foo.cmd")
    {
        UseShellExecute = false,
        RedirectStandardError = true,
        RedirectStandardOutput = true,
        CreateNoWindow = true
    };

    using (Process p = new Process())
    {
        p.StartInfo = oInfo;
        p.OutputDataReceived += new DataReceivedEventHandler(transporter_OutputDataReceived);

        p.Start();

        p.BeginOutputReadLine();

        p.WaitForExit();
    }

private void transporter_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    Response.Write(e.Data + " - line<br/>");
}
Run Code Online (Sandbox Code Playgroud)

我见过很多例子,人们使用cmd.exe启动.cmd程序,我试过这个,但没有成功.该程序只是无限期地加载.

    ProcessStartInfo oInfo = new ProcessStartInfo("cmd", "/c start foo.cmd")
    {
        UseShellExecute = false,
        RedirectStandardError = true,
        RedirectStandardOutput = true,
        CreateNoWindow = true, …
Run Code Online (Sandbox Code Playgroud)

.net c# cmd process

8
推荐指数
1
解决办法
2万
查看次数

System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)拒绝访问

我试图上传文件并将其转换为另一种格式,然后将其保存在我的Web服务器上,但是我收到以下错误:System.ComponentModel.Win32Exception(0x80004005):在System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)中拒绝访问)在System.Diagnostics.Process.Start()

当我尝试在本地计算机的Web服务器(Windows 7)上执行此操作时没有问题,但是在将我的网站部署到具有Windows Server 2008 R2的Web托管提供商后,我收到此错误.

我正在使用ASP.NET c#.我猜这是一个权限问题,但我不知道如何提升任何权限.请帮忙!

c# asp.net permissions iis-7

6
推荐指数
2
解决办法
2万
查看次数