批处理文件:使用批处理文件中推出,不同的用户CMD.EXE命令运行 [英] Batch file: run command in a cmd.exe launched as a different user using batch file
问题描述
嗨伙计我是一个新手,批处理文件和我面临的一个挑战。我要做以下自动使用批处理文件的步骤。步骤1和3,我能够搞清楚,但是,对于第2步,我需要你的帮助:
Hi Folks I am a newbie to batch files and I am facing a challenge. I have to do following steps using a batch file automatically. Steps 1 and 3 I am able to figure out, however for step 2 i need your help:
一个。使用的用户身份运行命令提示符:
A. Run command prompt using a user:
注释:这个我想通了,我可以用做:
Comment: This I have figured out, I can do it using:
@Echo Off
runas /profile /savecred /user:xyzasa\asdasq "cmd"
乙。请使用这在previous步
B. Make some registry changes using the command prompt which opened in the previous step
点评:我知道这是可以使用reg add命令然而,当我在没有得到执行时该批处理文件把这个命令来完成。下面是我的批处理文件的当前形状:
Comment: I know this can be done using the reg add command however when i am putting this command in the batch file it is not getting executed. Here is the current shape of my batch file:
@echo off
runas /profile /savecred /user:xyzasa\asdasq "cmd"
reg add <Machine Name><Registry path and the changes to be made>
℃。启动一个RDP文件
C. Launch a rdp file
注释:这也是我可以通过简单地提RDP文件作为最后一个步骤的名称做。
Comment: This also I can do by simply mentioning the name of the rdp file as the last step.
@echo off
runas /profile /savecred /user:xyzasa\asdasq "cmd"
reg add <Machine Name><Registry path and the changes to be made>
asd.rdp
问:如何确保cmd的启动为previous结果步骤后,REG ADD命令,在最近推出的提示执行
推荐答案
你有它的方式,runas命令将推出的独立的cmd.exe的实例运行作为用户,你可以'吨从原来的cmd.exe实例的任何实际的方式进行交互。
The way you have it, the runas command will launch a separate cmd.exe instance running as that user, that you can't interact with in any practical way from the original cmd.exe instance.
我建议你创建两个脚本:一个只包含运行方式命令(例如,main.bat),另一个包含您希望该用户帐户下所做的一切(比如,sub.bat) 。然后做这样的事情在main.bat:
I recommend you create two scripts: one that contains only the "runas" command (say, "main.bat"), and another that contains everything you want done under that user account (say, "sub.bat"). Then do something like this in main.bat:
runas /profile /savecred /user:xyzasa\asdasq "cmd /c sub.bat"
这篇关于批处理文件:使用批处理文件中推出,不同的用户CMD.EXE命令运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!