我想在远程 Windows 计算机上复制并运行 .exe 文件?
我已经复制了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");
}
i have copied the exe file and it was no problem, useing the following code, but now i want to run it, can anyboyd help me on this.
NOTE: i have the access to servers through remote desktop, but cant do this manually, coz there are dozens of them, cant get a program running on it like psex or whatever.
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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您在服务器上拥有的访问权限,您可以使用类似 psexec 或使用 WMI 远程启动文件。
示例 psexec 命令为
Psexec 可以根据请求提前复制文件,并且可以针对计算机列表运行(将
\\computername
替换为@computer-list.txt
) 。使用 WMI,您需要连接到Win32_Process
类并创建一个新对象来启动它。 第二篇文章 在此线程中可以工作。不幸的是,这两个选项都需要运行工作站提供多个防火墙规则(如 RPC 和 WMI)。如果您的公司仅通过防火墙启用了 RDP 访问,那么这些都可能不起作用。
Depending on what access you have on the server you can use a program like psexec or using WMI to launch the file remotely.
A sample psexec command would be
Psexec can copy the file beforehand if requested and can run against a list of computers instead (replacing
\\computername
with@computer-list.txt
). With WMI you need to connect to theWin32_Process
class and Create a new object to start it. The second post in this thread could work.Unfortunately both of these options require multiple firewall rules (like RPC and WMI) to be available from the running workstation. If your company only has RDP access enabled through the firewall, neither of these will probably work.