Advertisement
aveyo

Rename_On_Boot

Oct 23rd, 2017
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.52 KB | None | 0 0
  1. goto="Batch" /* Rename_On_Boot by AveYo v1
  2. :RenOnBoot
  3. set "input=%*" & call set "input=%%input:?=%%"                            &rem line below adds entry to right-click -- "SendTo" menu
  4. if /i "_%~dp0"=="_%APPDATA%\Microsoft\Windows\SendTo\" (set .=) else copy /y "%~f0" "%APPDATA%\Microsoft\Windows\SendTo\" >nul 2>nul
  5. if "_%1"=="_" color 4f & echo   ERROR! No input provided & ping -n 6 localhost >nul & exit /b
  6. for %%# in ("C:\" "C:\Boot" "C:\Recovery" "%WINDIR%" "%WINDIR%\system32" "%ProgramData%" "%ProgramFiles%" "%USERPROFILE%") do (
  7.  if /i "_%input%"=="_%%~#" color 4f & echo   ERROR! %%# is not safe to delete & ping -n 6 localhost >nul & exit /b
  8. )
  9. color 0B & echo   Please wait, folders might take a while .. & call cscript /nologo /e:JScript "%~f0" RenOnBoot "%input%" & exit /b
  10. :RenOnBoot_Run_As_Admin
  11. color 4f & echo   Asking permission to run as Admin.. & call cscript /nologo /e:JScript "%~f0" RunAsAdmin "%~f1???" & exit /b
  12. :"Batch"
  13. @echo off & setlocal disabledelayedexpansion & mode 96,4 & echo. & title %~nx0 by AveYo & if not exist "%~f1" goto :RenOnBoot
  14. reg query HKEY_USERS\S-1-5-20\Environment /v temp 1>nul 2>nul && goto :RenOnBoot || goto :RenOnBoot_Run_As_Admin
  15. :"JScript" */
  16. function RenOnBoot(f){
  17.   var HKLM=0x80000002, k='SYSTEM\\CurrentControlSet\\Control\\Session Manager', v='PendingFileRenameOperations';
  18.   var reg=GetObject('winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv'), ws=WSH.CreateObject('WScript.Shell');  
  19.   var confirmation=ws.Popup(" Rename on next boot? [OK]\n Clear previous entries? [Cancel]\n\n "+f,0,'Rename_On_Boot by AveYo',33);
  20.   if (confirmation == 2) { reg.DeleteValue(HKLM, k, v); WSH.quit(); } // Clear existing entries on Cancel press and quit script
  21.   var mtd=reg.Methods_('GetMultiStringValue').InParameters.SpawnInstance_(); mtd.hDefKey=HKLM; mtd.sSubKeyName=k; mtd.sValueName=v;
  22.   var query=reg.ExecMethod_('GetMultiStringValue', mtd), regvalue=(!query.ReturnValue) ? query.SValue.toArray():[,], entries=[];
  23.   var fso=new ActiveXObject('Scripting.FileSystemObject'), fn=fso.GetAbsolutePathName(f);
  24.   entries.push('\\??\\'+fn,'\\??\\'+fn+'.ren');
  25.   reg.CreateKey(HKLM, k); reg.SetMultiStringValue(HKLM, k, v, entries.concat(regvalue));
  26. }
  27. if (WSH.Arguments.length>=2 && WSH.Arguments(0)=='RenOnBoot') RenOnBoot(WSH.Arguments(1));
  28.  
  29. function RunAsAdmin(self, arguments) { WSH.CreateObject('Shell.Application').ShellExecute(self, arguments, '', 'runas', 1) }
  30. if (WSH.Arguments.length>=1 && WSH.Arguments(0)=='RunAsAdmin') RunAsAdmin(WSH.ScriptFullName, WSH.Arguments(1));
  31. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement