Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- SETLOCAL
- SET count=2
- SET OldName=%1
- SET NewName=%2
- REM Check if command line parameters are provided
- IF DEFINED OldName (
- IF NOT DEFINED NewName (
- set /p "NewName=Enter the new name: "
- )
- GOTO :CommandLineMode
- )
- REM Original interactive mode
- FOR /F "USEBACKQ tokens=*" %%F IN (`%SystemRoot%\System32\reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles" /s /v ProfileName`) DO ( call :procline "%%F"
- )
- ECHO(
- set /p "selected_line=Enter the number of the profile to rename (1-%count%): "
- set /p "new_name=Enter the new name: "
- call :GetVar GUID %%GUID%selected_line%%%
- call :GetVar PName %%PNAME%selected_line%%%
- call :DoRename "%GUID%" "%PName%" "%new_name%"
- GOTO :eof
- :CommandLineMode
- REM Command line mode - find the profile by name
- SET FoundGUID=
- SET FoundProfile=
- FOR /F "USEBACKQ tokens=*" %%F IN (`%SystemRoot%\System32\reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles" /s /v ProfileName`) DO ( call :FindProfile "%%F"
- )
- IF NOT DEFINED FoundGUID (
- echo Profile "%OldName%" not found.
- GOTO :eof
- )
- call :DoRename "%FoundGUID%" "%OldName%" "%NewName%"
- GOTO :eof
- :FindProfile
- SET line=%~1
- SET tempGUID=
- FOR /F "tokens=1,2 delims={}" %%F IN ("%line%") DO (
- SET tempGUID=%%G
- )
- IF DEFINED tempGUID (
- SET CurrentGUID=%tempGUID%
- ) ELSE (
- FOR /F "tokens=1,2,* delims= " %%H IN ("%line%") DO (
- IF DEFINED CurrentGUID (
- IF %%H==ProfileName (
- IF "%%J"=="%OldName%" (
- SET FoundGUID=%CurrentGUID%
- SET FoundProfile=%%J
- )
- )
- )
- )
- )
- EXIT /b
- :procline
- SET /a quo=%count% / 2
- SET /a remainder=%count% %% 2
- IF %remainder% EQU 0 (
- SET pGUID=
- FOR /F "tokens=1,2 delims={}" %%F IN ("%~1") DO (
- SET pGUID=%%G
- SET /a count=%count%+1
- )
- ) ELSE (
- FOR /F "tokens=1,2,* delims= " %%H IN ("%~1") DO (
- IF DEFINED pGUID (
- IF %%H==ProfileName (
- echo %quo%: %%J
- SET GUID%quo%=%pGUID%
- SET PName%quo%=%%J
- SET /a count=%count%+1
- EXIT /b
- )
- )
- SET /a count=%count%-1
- )
- )
- EXIT /b
- :GetVar
- set "%~1=%~2"
- goto :eof
- :DoRename
- REM Parameters: %1=GUID, %2=OldName, %3=NewName
- %SystemRoot%\System32\reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\{%~1}" /v ProfileName /t REG_SZ /d "%~3" /f
- if errorlevel 1 (
- echo Failed to update the profile name %~2.
- ) else (
- echo Profile name %~2 updated successfully to %~3.
- )
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement