怎么用批处理修改桌面路径

把desktop的值修改到D盘,怎么写个批处理代码
2024-11-18 03:18:46
推荐回答(3个)
回答(1):

@echo off
::cd /d d:
::md 桌面
::for /f "tokens=2,*" %%i in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop"') do Set dt=%%j
::xcopy "%dt%" "D:\桌面" /I /E /D /H
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop" /t REG_SZ /d "D:\桌面" /f
pause

这是我之前写来重装系统转移资料的批处理,根据你的需要修改了下,前面注释掉的代码是备份桌面文件到D盘,如果只是单纯修改注册表值,使用 reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop" /t REG_SZ /d "D:\桌面" /f 就可以了.

回答(2):

有软件的,不用那么麻烦

回答(3):

以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI
@echo off
rem 更改桌面默认路径
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
set "newdesktop=D:\xxx\Desktop"
if not exist "%newdesktop%" (md "%newdesktop%"||(pause&exit))
if "%newdesktop:~-1%" equ "\" set "newdesktop=%newdesktop:~,-1%"
set "olddesktop="
>"%tmp%\v.v" echo;WSH.echo CreateObject("Wscript.Shell").SpecialFolders("Desktop"):WSH.Quit
for /f "delims=" %%a in ('cscript -nologo -e:vbscript "%tmp%\v.v"') do (
set "olddesktop=%%~a"
)
if not defined olddesktop (echo;Failed to get desktop path&pause&exit)
echo;Old="%olddesktop%"
echo;New="%newdesktop%"
echo;files moving……
xcopy "%olddesktop%" "%newdesktop%\" /e /y /q /h /r
set "regpath1=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
set "regpath2=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
reg add "%regpath1%" /v Desktop /t REG_SZ /d "%newdesktop%" /f
reg add "%regpath2%" /v Desktop /t REG_SZ /d "%newdesktop%" /f
echo;%#% +%$%%$%/%@% %z%
set /p input=restart the computer now?[y/n]:
if /i "%input%" equ "Y" (shutdown -r -t 8)
pause
exit