我正在寻找一些帮助,以了解是什么导致我的批处理文件无法执行以下命令。我正在尝试更改桌面图标以进行大规模自动化成像。代码还有很多内容,但我将粘贴与问题相关的内容。帮助我理解为什么我可以在命令提示符中运行 reg add 命令并保存注册表编辑,但是当我运行批处理文件(具有管理权限)时,reg 编辑不会保存到注册表编辑器。
以下是代码:
@echo off
Title Lets making Imaging Policies a bit faster!
OpenFiles > NUL > 2&1
:Menu
echo =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
echo !ESC![34mWelcome %username%: %Msg1%!ESC![0m
echo =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
echo.
echo Do not close this cmd prompt window if you are running a command.
echo You need some cmd skill to use this, if you need help just ask.
echo.
echo 1. Change Desktop Icons
Set INPUT=
Set /P INPUT=Enter a Menu number and press ^< Enter ^> :
If /I '%INPUT%'=='0' Goto Exit
If /I '%INPUT%'=='1' Goto DESKTOP_ICON
:DESKTOP_ICON
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 0
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 0
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {59031a47-3f72-44a7-89c5-5595fe6b30ee} /t REG_DWORD /d 0
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {59031a47-3f72-44a7-89c5-5595fe6b30ee} /t REG_DWORD /d 0
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {645FF040-5081-101B-9F08-00AA002F954E} /t REG_DWORD /d 0
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {645FF040-5081-101B-9F08-00AA002F954E} /t REG_DWORD /d 0
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 0
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 0
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {59031a47-3f72-44a7-89c5-5595fe6b30ee} /t REG_DWORD /d 0
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {59031a47-3f72-44a7-89c5-5595fe6b30ee} /t REG_DWORD /d 0
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {645FF040-5081-101B-9F08-00AA002F954E} /t REG_DWORD /d 0
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {645FF040-5081-101B-9F08-00AA002F954E} /t REG_DWORD /d 0
taskkill /f /im explorer.exe
echo Please wait 10 seconds to allow the script to run. Do not worry about the background, the explorer is refreshing
timeout /t 10 /nobreak
echo Thanks for being patient! Now allow everything to reload
start explorer.exe
echo.
echo ^< Press ANY key to return to the Menu ^> & Pause > NUL)
CLS & Goto :Menu
答案1
@echo off && setlocal enabledelayedexpansion
Title <nul & cd /d "%~dp0" & OpenFiles 1>nul 2>&1
Title Lets making Imaging Policies a bit faster!!
set _bar=<nul & for /l %%L in =;(1 1 38);= do set "_bar=!_bar!=+"
set "_Msg1=Variable: %%_Msg1%% // not defined in your question //"
for /f skip^=4 %%b in =;('echo;prompt;$H^|cmd.exe');= do set "_BS=%%~b"
for /f skip^=4 %%e in =;('echo;prompt $E^|cmd.exe');= do set "_$E=%%~e"
set "_KEY=HKCU,HKLM"
set "_NST=Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel"
set "_CSM=SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu"
set "_REG=20D04FE0-3AEA-1069-A2D8-08002B30309D,59031a47-3f72-44a7-89c5-5595fe6b30ee,645FF040-5081-101B-9F08-00AA002F954E"
:Menu
cls & echo\ !_bar!
echo\ !_$E![34m Welcome %username%: %_Msg1%!_$E![0m & echo\ !_bar!
echo\ Do not close this cmd prompt window if you are running a command.
echo\ You need some cmd skill to use this, if you need help just ask. & echo\
echo\ 1. Change Desktop Icons & echo\ 2. Keep without Changing Icons
Set /p INPUT=<nul & Set /P INPUT=!_BS! Enter a Menu number and press ^< Enter ^> : || Goto :Menu
echo\"%INPUT%" | findstr ^"1^" >nul && Goto :DESKTOP_ICON || >nul =;(
echo\"%INPUT%" | findstr ^"2^" && Goto :Exit || Goto :Menu );=
:DESKTOP_ICON
for %%K in =;(!_KEY!);= do for %%r in =;("!_NST!","!_CSM!");= do for %%# in =;(
!_REG!);= do 1>nul reg add "%%~K\%%~r" /v "{%%~#}" /t REG_DWORD /d 0 /f 2>&1
1>nul taskkill /f /im explorer.exe & timeout /t 10 /nobreak | =;(
echo\ Please wait 10 seconds to allow the script to run.
echo\ Do not worry about the background, the explorer is refreshing
);= && echo\ Thanks for being patient! Now allow everything to reload
start "" explorer.exe & echo.
timeout -1 | set /p ".=!_BS! < Press ANY key to return to the Menu >" & Goto :Menu
:Exit
endlocal
我假设你正在运行行政人员,因此尝试
""
使用"{ ... }"
/f
:... /d 0 /f