我想通过Windows -> Run
对话框以不同的用户身份运行批处理文件。
我努力了:
runas /profile /user:test CMD "C:\Users\MyName\Desktop\Run.bat"
runas /profile /user:test "CMD "C:\Users\MyName\Desktop\Run.bat""
runas /profile /user:test "CMD \"C:\Users\MyName\Desktop\Run.bat\""
runas /profile /user:test "CMD \"C:\Users\MyName\Desktop\Run.bat"\"
但还是没运气。它打开 CMD 并要求我输入密码。我输入密码,它使用另一个用户名打开另一个 CMD 窗口,但它不会运行蝙蝠。相反,标题栏只是说
管理员:cmd“C:\Users\MyName\Desktop\Run.bat”(以 Home-PC\test 身份运行)
有人可以帮忙吗?
答案1
你缺少一个开关。来自CMD /?
:
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
这些命令应该可以工作。选择适合您需要的那个。
runas /profile /user:test "CMD /C C:\Users\MyName\Desktop\Run.bat"
runas /profile /user:test "CMD /K C:\Users\MyName\Desktop\Run.bat"
如果路径包含空格,请用转义的双引号 ( \"
) 将其括起来:
runas /profile /user:test "CMD /C \"C:\Users\My Name\Desktop\Run.bat\""
runas /profile /user:test "CMD /K \"C:\Users\My Name\Desktop\Run.bat\""