从WPF按钮运行服务器上的文件按

问题描述 投票:0回答:1

使用Process.Start()PsExec.exe在serverpc上启动视频的一些应用程序代码在从控制台应用程序运行时运行正常,但在从WPF应用程序中按下按钮运行时则不运行。这让我今天疯了。

所以:

我在PC上运行一个小型WPF应用程序,一旦按下按钮,它将向服务器PC发送命令以运行视频文件。我正在使用PsExec.exe以交互方式在服务器上运行该进程(未使用WMI进行管理)这是我正在使用的代码:


Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.FileName = @"C:\Windows\System32\PsExec.exe";
p.StartInfo.Arguments = @"\\192.168.1.3 -u Administrator -p hagarmikejessav -i cmd.exe /c START E:\Media\FerroniConcettaAapp\Videos\Photoslideshow.mp4";
            p.StartInfo.CreateNoWindow = true;
            p.Start();

不,当从普通控制台App运行时,这个完全相同的代码可以在服务器PC(192.168.1.3)上打开视频文件Photoslideshow.mp4。但是,当我按下WPF应用程序中的按钮后尝试运行它时,p.Start()给了我一个“系统找不到指定的文件”错误。这是WPF代码片段(与上面相同):

private void Video1_btn_Click(object sender, RoutedEventArgs e)
{
    try
    {
        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.RedirectStandardInput = true;
        p.StartInfo.FileName = @"C:\Windows\System32\PsExec.exe";
        p.StartInfo.Arguments = @"\\192.168.1.3 -u Administrator -p hagarmikejessav -i cmd.exe /c START E:\Media\FerroniConcettaAapp\Videos\Photoslideshow.mp4  //fullscreen";
        p.StartInfo.CreateNoWindow = true;
        p.Start();
    }
}

当我尝试在我的PC本地文件上使用p.Start时,它按预期打开。它只是没有“看到”FileName的服务器。正如我之前所说的那样,相同的代码仅在按钮点击后访问p.Start时失败。

我究竟做错了什么?请有人告诉我,这是PC前几个小时的结果,这只是一个我无法看到的愚蠢错误!

编辑:

经过更多的游戏,我意识到错误“系统找不到指定的文件”与此行有关:p.StartInfo.FileName = @“C:\ Windows \ System32 \ PsExec.exe”;

enter image description here

将此行更改为:

p.StartInfo.FileName = @“C:\ Windows \ System32 \ Notepad.exe”;

并删除下一行,记事本在我的本地PC上打开。但是,当我将2行更改为类似于:

p.StartInfo.FileName = @“Notepad.exe”; p.StartInfo.Arguments = @“\ 192.168.1.3 -u Administrator -p pass-i cmd.exe / c START C:\ realtek.txt”; ...

记事本在我的本地PC上打开,但出现“未找到网络路径”错误。 (这与我运行'非按钮代码时的错误类似。)

因此我知道问题与WPF / Button应用程序有关。但我不知道问题是什么!

非常感谢,马里奥

c# wpf psexec system.diagnostics
1个回答
0
投票

我设法搞清楚了。

出于某种原因,系统没有从此路径中找到PSExec(即使它存在于该文件夹中)。 p.StartInfo.FileName = @“C:\ Windows \ System32 \ PsExec.exe”;

将文件复制到另一个目录并使用完整路径后,它终于有效了。

© www.soinside.com 2019 - 2024. All rights reserved.