psexec %1 不是有效的 Win32 应用程序

赫曼斯·瓦蒂

这是我用来运行远程服务器上的 exe 文件的代码。我在我的 Web 服务器中使用以下代码部署了控制台应用程序,以调用远程服务器上的 exe。但我收到错误“psexec %1 不是有效的 Win32 应用程序”。我在本地机器上测试了这段代码,它工作正常……但它在服务器上不起作用。

        ProcessStartInfo info = new ProcessStartInfo("C:\\PsTools");
        info.FileName = @"C:\PsTools\psexec.exe";
        info.Arguments = @"\\" + "MyComputerName" + @" -h D:\Idealake\Schedulers\SBIHangFireConsole\bin\Debug\SBIHangFireConsole.exe";
        info.RedirectStandardOutput = true;
        info.UseShellExecute = false;
        Process p = Process.Start(info);

服务器详情——

内核版本:Windows Server 2012 R2 Standard,Multiprocessor Free 产品类型:Standard Edition 产品版本:6.3 Service Pack:0 内核内部版本号:9600 注册组织:注册所有者:Windows 用户 IE 版本:9.0000 系统根目录:C:\Windows 处理器: 4 处理器速度:2.5 GHz 处理器类型:AMD Opteron(tm) 处理器 6380 物理内存:2 MB 视频驱动程序:VMware SVGA 3D

此包中的 PsTools 版本:2.45

赫曼斯·瓦蒂
Install Power Shell in the Remote PC
Enable Power Shell Remoting to execute Powershell Commnads on the remote server by using the command "Enable-PSRemoting"
Add the server from which you are making the call as a Trusted one by using the command-
set-item wsman:\localhost\Client\TrustedHosts -value 172.16.0.0

注意:确保在两台计算机上都运行上述命令

Now use the below code in your project to execute exe on remote server


  Runspace runspace = RunspaceFactory.CreateRunspace();
  runspace.Open();
  Pipeline pipeline = runspace.CreatePipeline();
  ps.Commands.AddScript("$User = \"domain\\username\"");
  ps.Commands.AddScript("$PWord = ConvertTo-SecureString -String \"yourpassword\" - 
  AsPlainText -Force");
  ps.Commands.AddScript("$Credential = New-Object -TypeName 
  System.Management.Automation.PSCredential -ArgumentList $User, $PWord");
  ps.Commands.AddScript("Invoke-Command -ComputerName REMOTECOMPUTERIP -ScriptBlock { 
  D:\\TestApp.exe } -cred $Credential");

  Collection<PSObject> resultst = ps.Invoke();
                Collection<ErrorRecord> errors = ps.Streams.Error.ReadAll();
                StringBuilder errorDetails = new StringBuilder();
                if (errors != null && errors.Count > 0)
                {
                    foreach (ErrorRecord er in errors)
                    {
                        errorDetails.AppendLine(er.Exception.ToString());

                    }
                    throw new Exception(errorDetails.ToString());
                }

                Console.WriteLine(errorDetails.ToString());
                StringBuilder stringBuilder = new StringBuilder();
                foreach (PSObject obj in resultst)
                {
                    stringBuilder.AppendLine(obj.ToString());
                }`enter code here`
                Console.WriteLine(stringBuilder.ToString());
                runspace.Close();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

CreateProcess错误= 193,%1不是有效的Win32应用程序-> [帮助1]

DLL加载失败:%1不是有效的Win32应用程序-Appcelerator

JNI C ++ DLL-'UnsatisfiedLinkError:%1不是有效的Win32应用程序'

OSError:[WinError 193]%1不是有效的Win32应用程序

Python:DLL加载失败:%1不是有效的Win32应用程序

PHP加载错误:%1不是有效的Win32应用程序。

WinError 193]%1不是有效的Win32应用程序

Python [WinError 193]%1不是有效的Win32应用程序

Rails 3.2.1:%1不是有效的Win32应用程序。-c:/ RailsInstaller

错误:%1不是有效的Win32应用程序

VLC.DotNet System.ComponentModel.Win32Exception:'%1不是有效的Win32应用程序'

IOException:无法运行程序:CreateProcess错误= 193,%1不是有效的Win32应用程序

为什么很少用“%1不是有效的Win32应用程序”代替%1。

解决“ DLL加载失败:%1不是有效的Win32应用程序。” 对于Pygame

python cython ImportError:DLL加载失败:%1不是有效的Win32应用程序

Anaconda / Orange3产生OSError:[WinError 193]%1不是有效的Win32应用程序

ImportError:DLL加载失败:%1不是有效的Win32应用程序。但是DLL在那里

错误:java.io.IOException:CreateProcess错误= 193,%1不是有效的Win32应用程序

CMake:运行链接命令时出错:%1不是有效的Win32应用程序

ImportError:DLL加载失败:%1不是_imaging模块的有效Win32应用程序

Pycharm与Electron -Runnerw.exe:CreateProcess失败,错误193:%1不是有效的Win32应用程序

读取Perl脚本错误:CreateProcess错误= 193,%1不是有效的Win32应用程序

启动IPython Notebook(Anaconda 3)时出现错误“%1不是有效的Win32应用程序”

OSError:[WinError 193]%1不是有效的Win32应用程序opencv.js

如何解决“ OSError:[WinError 193]%1不是有效的Win32应用程序”

如何修复Jupyter Notebook熊猫错误(OSError:[WinError 193]%1不是有效的Win32应用程序)

cx-freeze“ ImportError:DLL加载失败:%1不是有效的Win32应用程序”

.Net Framework 4.6安装导致错误“%1不是有效的win32应用程序”

OSError: [WinError 193] %1 在使用 ctypes 时不是有效的 Win32 应用程序