c# 远程启动exe
时间: 2023-08-02 19:25:48 浏览: 170
可以使用C#中的Process类来启动远程计算机上的exe文件。以下是一个示例代码:
```csharp
using System.Diagnostics;
string remoteMachineName = "RemoteMachineName";
string remoteExePath = @"\\RemoteMachineName\C$\Path\To\Exe\file.exe";
ProcessStartInfo processStartInfo = new ProcessStartInfo(remoteExePath);
processStartInfo.UseShellExecute = false;
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.UserName = "RemoteMachineUsername";
processStartInfo.Password = new System.Security.SecureString();
string password = "RemoteMachinePassword";
foreach (char c in password)
{
processStartInfo.Password.AppendChar(c);
}
Process process = new Process();
process.StartInfo = processStartInfo;
process.Start();
```
请将RemoteMachineName,remoteExePath,RemoteMachineUsername和RemoteMachinePassword替换为实际的值。
阅读全文