gpt4 book ai didi

c# - 我想在远程 Windows 机器上复制并运行 .exe 文件?

转载 作者:可可西里 更新时间:2023-11-01 09:26:30 24 4
gpt4 key购买 nike

我已经复制了exe文件,没问题,使用下面的代码,但现在我想运行它,anyboyd可以帮我解决这个问题吗?注意:我可以通过远程桌面访问服务器,但不能手动执行此操作,因为它们有几十个,无法让程序在其上运行,例如 psex 或其他任何程序。

WindowsIdentity wi = new WindowsIdentity(token);

//Next I set the WindowsImportsonationContext

WindowsImpersonationContext impctx = wi.Impersonate();
System.IO.File.Copy("C:\\output.html", "\\\\PW42\\c$\\output1.html", true);
System.Diagnostics.Process p = new System.Diagnostics.Process();
try
{
System.Diagnostics.Process.Start(@"\\PW42\c$\txt.bat");
//runFile();
}
catch
{
Console.WriteLine("error");
}

最佳答案

根据您在服务器上的访问权限,您可以使用类似 psexec 的程序或使用 WMI 远程启动文件。

一个示例 psexec 命令是

psexec \\computername -u remoteusername filepath(on remote computer) arguments

如果需要,Psexec 可以预先复制文件,并且可以针对计算机列表运行(将 \\computername 替换为 @computer-list.txt)。使用 WMI,您需要连接到 Win32_Process 类并创建一个新对象来启动它。 second post在这个线程中可以工作。

不幸的是,这两个选项都需要多个防火墙规则(如 RPC 和 WMI)才能从正在运行的工作站使用。如果您的公司仅启用了通过防火墙的 RDP 访问,则这些都可能不起作用。

关于c# - 我想在远程 Windows 机器上复制并运行 .exe 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3593658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com