我在Windows7中有一个批处理脚本来更新失败的hosts
文件。 我以具有pipe理权限的用户身份login。
即使我用“以pipe理员身份运行”选项运行脚本我得到Access denied. 0 files copied
执行这部分脚本时Access denied. 0 files copied
:
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do set ip=%%b set ip=%ip:~1% REM create changing part of hosts file... if exist %temp%\temp.txt del %temp%\temp.txt echo %ip% myproxy >> %temp%\temp.txt REM check this... set hostpath=C:\WINDOWS\system32\drivers\etc REM add static part of hosts file type "%hostpath%\hosts-static" >> %temp%\temp.txt REM replace hosts file copy /y %temp%\temp.txt "%hostpath%\hosts" ipconfig /flushdns netsh interface ip delete arpcache pause
我也尝试创build一个快捷方式,并设置“高级 – >以pipe理员身份运行”选项,但没有运气。
如果我以pipe理员身份打开一个cmd shell,然后从那里运行脚本,一切正常,但没有办法直接双击文件(或链接)。 任何想法?
编辑:
我试图创build一个快捷方式,以pipe理员身份执行以下命令
C:\ Windows \ System32 \ cmd.exe / c script.bat
也是失败的 从相同的快捷方式(无参数),我可以打开一个窗口,我可以正确执行批处理。 我真的不明白为什么。
在copy
命令之前,请尝试attrib -r -s -h -a "%hostpath%\hosts"
。 如果任何文件归属于+ r,+ s或+ h,则如果您尝试使用copy
覆盖该copy
,则会显示“访问被拒绝”。