Advertisement
aveyo

Delete_On_Boot

Oct 23rd, 2017
1,610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.02 KB | None | 0 0
  1. goto="Batch" /* Delete_On_Boot by AveYo v1
  2. :DelOnBoot
  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" DelOnBoot "%input%" & exit /b
  10. :DelOnBoot_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 :DelOnBoot
  14. reg query HKEY_USERS\S-1-5-20\Environment /v temp 1>nul 2>nul && goto :DelOnBoot || goto :DelOnBoot_Run_As_Admin
  15. :"JScript" */
  16. function DelOnBoot(f){
  17.   ListDir=function(src, _root,_list) {
  18.     _root=_root || src, _list=_list || [];
  19.     var root=fso.GetFolder(src), files=new Enumerator(root.Files), dirs=new Enumerator(root.SubFolders);
  20.     while (!files.atEnd()) { _list.push(files.item()); files.moveNext(); }
  21.     while (!dirs.atEnd()) { _list=ListDir(dirs.item().path, _root,_list); _list.push(dirs.item()); dirs.moveNext(); }
  22.     return _list;
  23.   };
  24.   var HKLM=0x80000002, k='SYSTEM\\CurrentControlSet\\Control\\Session Manager', v='PendingFileRenameOperations';
  25.   var reg=GetObject('winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv'), ws=WSH.CreateObject('WScript.Shell');  
  26.   var confirmation=ws.Popup(" Delete on next boot? [OK]\n Clear previous entries? [Cancel]\n\n "+f,0,'Delete_On_Boot by AveYo',33);
  27.   if (confirmation == 2) { reg.DeleteValue(HKLM, k, v); WSH.quit(); } // Clear existing entries on Cancel press and quit script
  28.   var mtd=reg.Methods_('GetMultiStringValue').InParameters.SpawnInstance_(); mtd.hDefKey=HKLM; mtd.sSubKeyName=k; mtd.sValueName=v;
  29.   var query=reg.ExecMethod_('GetMultiStringValue', mtd), regvalue=(!query.ReturnValue) ? query.SValue.toArray():[,], entries=[];
  30.   var fso=new ActiveXObject('Scripting.FileSystemObject'), fn=fso.GetAbsolutePathName(f);
  31.   if (fso.FolderExists(fn)) { var list=ListDir(fn); for (var i in list) entries.push('\\??\\'+list[i],''); }
  32.   entries.push('\\??\\'+fn,'');
  33.   reg.CreateKey(HKLM, k); reg.SetMultiStringValue(HKLM, k, v, entries.concat(regvalue));
  34. }
  35. if (WSH.Arguments.length>=2 && WSH.Arguments(0)=='DelOnBoot') DelOnBoot(WSH.Arguments(1));
  36.  
  37. function RunAsAdmin(self, arguments) { WSH.CreateObject('Shell.Application').ShellExecute(self, arguments, '', 'runas', 1) }
  38. if (WSH.Arguments.length>=1 && WSH.Arguments(0)=='RunAsAdmin') RunAsAdmin(WSH.ScriptFullName, WSH.Arguments(1));
  39. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement