Advertisement
Guest User

Untitled

a guest
Jun 9th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.64 KB | Source Code | 0 0
  1. @echo off
  2. SETLOCAL
  3. SET count=2
  4. SET OldName=%1
  5. SET NewName=%2
  6.  
  7. REM Check if command line parameters are provided
  8. IF DEFINED OldName (
  9.     IF NOT DEFINED NewName (
  10.         set /p "NewName=Enter the new name: "
  11.     )
  12.     GOTO :CommandLineMode
  13. )
  14.  
  15. REM Original interactive mode
  16. 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"
  17. )
  18. ECHO(
  19. set /p "selected_line=Enter the number of the profile to rename (1-%count%): "
  20. set /p "new_name=Enter the new name: "
  21. call :GetVar GUID %%GUID%selected_line%%%
  22. call :GetVar PName %%PNAME%selected_line%%%
  23. call :DoRename "%GUID%" "%PName%" "%new_name%"
  24. GOTO :eof
  25.  
  26. :CommandLineMode
  27. REM Command line mode - find the profile by name
  28. SET FoundGUID=
  29. SET FoundProfile=
  30. 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"
  31. )
  32.  
  33. IF NOT DEFINED FoundGUID (
  34.     echo Profile "%OldName%" not found.
  35.     GOTO :eof
  36. )
  37.  
  38. call :DoRename "%FoundGUID%" "%OldName%" "%NewName%"
  39. GOTO :eof
  40.  
  41. :FindProfile
  42. SET line=%~1
  43. SET tempGUID=
  44. FOR /F "tokens=1,2 delims={}" %%F IN ("%line%") DO (
  45.     SET tempGUID=%%G
  46. )
  47. IF DEFINED tempGUID (
  48.     SET CurrentGUID=%tempGUID%
  49. ) ELSE (
  50.     FOR /F "tokens=1,2,* delims= " %%H IN ("%line%") DO (
  51.         IF DEFINED CurrentGUID (
  52.             IF %%H==ProfileName (
  53.                 IF "%%J"=="%OldName%" (
  54.                     SET FoundGUID=%CurrentGUID%
  55.                     SET FoundProfile=%%J
  56.                 )
  57.             )
  58.         )
  59.     )
  60. )
  61. EXIT /b
  62.  
  63. :procline
  64.    SET /a quo=%count% / 2
  65.    SET /a remainder=%count% %% 2
  66.    IF %remainder% EQU 0 (
  67.      SET pGUID=
  68.      FOR /F "tokens=1,2 delims={}" %%F IN ("%~1") DO (
  69.        SET pGUID=%%G
  70.        SET /a count=%count%+1
  71.      )    
  72.    ) ELSE (
  73.      FOR /F "tokens=1,2,* delims= " %%H IN ("%~1") DO (
  74.        IF DEFINED pGUID (
  75.          IF %%H==ProfileName (
  76.            echo %quo%: %%J
  77.            SET GUID%quo%=%pGUID%
  78.            SET PName%quo%=%%J
  79.            SET /a count=%count%+1
  80.            EXIT /b
  81.          )
  82.        )
  83.      SET /a count=%count%-1
  84.      )
  85.    )
  86. EXIT /b
  87.  
  88. :GetVar
  89. set "%~1=%~2"
  90. goto :eof
  91.  
  92. :DoRename
  93. REM Parameters: %1=GUID, %2=OldName, %3=NewName
  94. %SystemRoot%\System32\reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\{%~1}" /v ProfileName /t REG_SZ /d "%~3" /f
  95. if errorlevel 1 (
  96.   echo Failed to update the profile name %~2.
  97. ) else (
  98.   echo Profile name %~2 updated successfully to %~3.
  99. )
  100. goto :eof
Tags: batch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement