如何使用psexec在远程PC上运行exe [英] How to run exe on remote PC using psexec

查看:105
本文介绍了如何使用psexec在远程PC上运行exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

远程pc(SYSDES208)中有一个exe(D:\ TestFile.exe).运行时,它只会创建一个包含一些文本的文本文件.手动运行时效果很好.
我正在尝试在命令提示符下以这种方式从另一台PC执行此操作.

There is an exe (D:\TestFile.exe) in remote pc(SYSDES208). When run, it just creates a text file with some text. It works fine when run manually.
I'm trying to execute this from another PC this way, in command prompt.

D:\PsTools>cmdkey.exe /add:SYSDES208 /user:admin /pass:admin123
//Message - CMDKEY: Credential added successfully

D:\PsTools>psexec \\SYSDES208 D:\TestFile.exe
//Message - D:\TestFile.exe exited on SYSDES208 with error code 0.

没有错误,也没有创建文本文件.

There is no error and also no text file created.

命令中传递的凭据是远程PC的凭据.

The credentials passed in the command are of the remote PC's.

更新:想到改用批处理文件来运行exe.因此,我使用此代码创建了一个批处理文件,并将其放置在远程PC(D:\ Test.bat)中:

UPDATE: Thought of using a batch file instead, to run the exe. So, I created a batch file with this code and placed it in the remote pc (D:\Test.bat):

start /d "D:\" TestFile.exe

以下是从本地PC运行的命令:

Here are the commands run from the local PC:

D:\PsTools>cmdkey.exe /add:SYSDES208 /user:admin /pass:admin123
//Message - CMDKEY: Credential added successfully

D:\PsTools>psexec \\SYSDES208 D:\Test.bat
//Message - c:\windows\system32>start /d "D:\" TestFile.exe
            D:\Test.bat exited on SYSDES208 with error code 0

如消息中所示,批处理文件已执行,但exe未执行.我在这里想念什么

As seen in the message, the batch file is executed but the exe is not. What am i missing here

推荐答案

我的网络管理员为此使用Powershell.不知道您是否仅限于CMD.

My network admins would use Powershell for this. Not sure if you are restricted to only CMD.

调用命令-计算机名SYSDES208 -scriptblock {D:\ TestFile.exe}

invoke-command -computername SYSDES208 -scriptblock { D:\TestFile.exe }

如果您正在使用域帐户,或者在远程计算机上具有完全相同的帐户,则不需要输入凭据,因为powershell会使用本地用户的凭据.

If you are using a domain account or have the exact same account on the remote machine you shouldn't need to enter credentials as powershell will use the cred of the local user.

这篇关于如何使用psexec在远程PC上运行exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆