简体   繁体   English

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

[英]I want to copy and run .exe file on a remote Windows machine?

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. 我已经复制了exe文件,没有问题,使用下面的代码,但现在我想运行它,anyboyd可以帮助我。 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. 注意:我可以通过远程桌面访问服务器,但不能手动执行此操作,因为有几十个,无法像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");
}

Depending on what access you have on the server you can use a program like psexec or using WMI to launch the file remotely. 根据您在服务器上的访问权限,您可以使用psexec等程序或使用WMI远程启动文件。

A sample psexec command would be 一个样本psexec命令就是

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

Psexec can copy the file beforehand if requested and can run against a list of computers instead (replacing \\\\computername with @computer-list.txt ). 如果请求,Psexec可以预先复制文件,并且可以针对计算机列表运行(用@computer-list.txt替换\\\\computername )。 With WMI you need to connect to the Win32_Process class and Create a new object to start it. 使用WMI,您需要连接到Win32_Process类并创建一个新对象来启动它。 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. 不幸的是,这两个选项都需要从运行的工作站获得多个防火墙规则(如RPC和WMI)。 If your company only has RDP access enabled through the firewall, neither of these will probably work. 如果您的公司仅通过防火墙启用了RDP访问,则这些都不会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM