批处理文件自动执行的Sysinternals [英] Batch file to automate Sysinternals execution
问题描述
我想创建批处理文件来自动执行的Sysinternals。
这将最终由一个Python脚本来执行操作时自动提升程序的凭据(是的,我知道这是不好的做法,是的,有办法提供密码为运行方式,等等等等,但是这些解决方案具有为我工作)
I am trying to create batch file to automate Sysinternals execution. This will eventually be executed by a Python script to automatically elevate credentials of a program (yes, I know this is bad practice, yes, there were ways to supply the password to "runas", etc, etc, but none of these solutions have worked for me)
当我打开命令提示符作为一个普通用户,然后键入以下
When I open a command prompt as a regular user and type the following
.\psexec \\my_IP_address -u DOMAIN\my_admin_account -p my_admin_password cmd
我得到
PsExec v2.0 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Windows\system32>
从那里我可以键入
From there I can type in
.\psloggedon -l -x \\ip_address_of_remote_computer
和屏幕打印出结果。
PsLoggedon v1.34 - See who's logged on
Copyright (C) 2000-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
Users logged on locally:
DOMAIN\last_user_logged_in
但是,当我尝试创建下面的批处理文件
But when I try to create the following batch file
cd pstools
.\psexec \\my_IP_address -u DOMAIN\adminaccount -p adminpasword cmd
cd pstools
.\psloggedon -l -x \\ip_address_of_remote_computer
当我执行批处理文件,它只是执行前两个命令
And when I execute the batch file, it only executes the first two commands
cd pstools
.\psexec \\my_IP_address -u DOMAIN\adminaccount -p adminpasword cmd
我如何得到它来执行所有的命令?
How do I get it to execute all of the commands?
在影响,我打开一个命令提示符,然后提升权限(这是我计划纳入一个脚本)
In affect, I am opening a command prompt and THEN elevating privileges (which is something I plan to incorporate into a script)
推荐答案
这是因为在原来的CMD您psloggedon命令运行,而不是新的。
This is because your psloggedon command runs in the original cmd, not the new one.
您应该传递你想运行为CMD参数是什么。例如,这个工作对我来说:
You should pass what you want to be run as a parameter for cmd. For example, this worked for me:
psexec cmd /c "whoami & pause"
所以,你也应该做同样的事情,例如:
So you should also do something similar, e.g.:
cd pstools
.\psexec \\my_IP_address -u DOMAIN\adminaccount -p adminpasword cmd /c "cd pstools & psloggedon -l -x \\ip_address_of_remote_computer"
另一种选择,如果内部逻辑变得更复杂的是特别有用的,是创建只是一个新的批处理文件,并将其作为参数传递给CMD运行。
Another option, especially useful if the internal logic grows more complicated, is to create a new batch file just for that, and pass it as a parameter to cmd to run.
这篇关于批处理文件自动执行的Sysinternals的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!