简体   繁体   English

批处理文件不会以管理员身份运行

[英]batch file will not run as administrator

I am trying to run this code in a windows batch (.bat) file 我试图在Windows批处理(.bat)文件中运行此代码

@echo off

echo Adding New User - LogMeInRemoteUser
net user | find /i "LogMeInRemoteUser" || Net user LogMeInRemoteUser password /add /fullname:"LogMeInRemoteUser"

pause

echo Adding User to Administrators Group
NET LOCALGROUP Administrators "LogMeInRemoteUser" /ADD

pause

echo Creating Registry Keys to remove the new user from the login page
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon\SpecialAccounts\UserList" /v "LogMeInRemoteUser" /t REG_DWORD /d 0

pause

echo Finished

if i run the file normally, i get an Access Denied error so I try to run as Administrator but the cmd windows opens and instantly closes, what have i done wrong? 如果我正常运行该文件,我得到一个拒绝访问错误,所以我尝试以管理员身份运行但cmd窗口打开并立即关闭,我做错了什么?

When you run as administrator the current directory is changed under you. 以管理员身份运行时,您下面的当前目录已更改。 To prove that (and fix it) enter these 3 lines under your @echo off 要证明(并修复它),请在@echo关闭下输入这3行

echo(%cd%
pushd %~dp0
echo(%cd%

You can remove both of the echo( statements after you see what is happening. 您可以删除两个echo(在看到发生的事情之后的语句)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM