Advertisement
Wasif_Hasan_

FolderLocker.bat

Sep 10th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 14.55 KB | None | 0 0
  1. @echo off & title Folder Locker & pushd "%~dp0" & color 0a
  2. ::****************************************************************
  3. openfiles >nul 2>&1 & if %errorlevel% EQU 1 (
  4.   setlocal disableDelayedExpansion & color 4f
  5.   echo Running Admin Shell, Please wait.... & ping localhost -n 1 >nul
  6.   set "bPath=%~f0" & setlocal enableDelayedExpansion
  7.   echo Dim UAC : Set UAC = CreateObject^("Shell.Application"^) >Elevate.vbs
  8.   echo For Each strArg in Wscript.Arguments >>Elevate.vbs
  9.   echo   args = args ^& strArg ^& " " >>Elevate.vbs
  10.   echo Next >>Elevate.vbs
  11.   echo UAC.ShellExecute "!bPath!",args,"","runas",1 >>Elevate.vbs
  12.   echo Set objShell = Nothing >>Elevate.vbs
  13.   cscript //nologo Elevate.vbs & del Elevate.vbs & exit /b
  14. )
  15. ::****************************************************************
  16. if not exist "%userprofile%\desktop\%~n0.lnk" (
  17.   (
  18.   echo Call Shortcut("%~f0","Folder Locker"^)
  19.   echo Sub Shortcut(Application,Name^)
  20.   echo    Dim objShell,DesktopPath,objShortCut,MyTab
  21.   echo    Set objShell = CreateObject("WScript.Shell"^)
  22.   echo    MyTab = Split(Application,"\"^)
  23.   echo    If Name = "" Then
  24.   echo      Name = MyTab(UBound(MyTab^)^)
  25.   echo    End if
  26.   echo    DesktopPath = objShell.SpecialFolders("Desktop"^)
  27.   echo    Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Name ^& ".lnk"^)
  28.   echo    objShortCut.TargetPath = Chr(34^) ^& Application ^& Chr(34^)
  29.   echo    ObjShortCut.IconLocation = "shell32.dll,47"
  30.   echo    objShortCut.Save
  31.   echo End Sub
  32.   ) >>crshort.vbs
  33.   cscript //nologo crshort.vbs & del crshort.vbs
  34. )
  35. ::**************************************************************
  36. mode 160,40
  37. if not exist "%userprofile%\id.spfile" goto first_lock
  38. goto :Unlocker_Password
  39. :first_lock
  40. cls & echo. & echo.
  41. echo                              #########################################
  42. echo                                      Welcome to Folder Locker
  43. echo                              #########################################
  44. echo.
  45. echo No Private Folder was found, a folder is needed to be created
  46. echo.
  47. Call :InputPassword "Create a strong password for the locker"
  48. ::**************************************************************
  49. cls & echo. & echo.
  50. echo Please choose a folder where to create the locker, a dialog box will come:
  51. Call :ChooseFolder "%Userprofile%\Desktop" "Choose the folder where the hidden folder locker will be created, preffereably choose an unpredictable secure location, though it will be completely hidden"
  52. cls
  53. ::**************************************************************
  54. echo             #########################################################################
  55. echo                            Creating the private folder, please wait.....
  56. echo             #########################################################################
  57. echo.
  58. type nul >"%userprofile%\id.spfile"
  59. md "%folder%\SecretLocker" & md "%AppData%\Wasif"
  60. echo %password% >"%AppData%\Wasif\pwd.spfile"
  61. echo %folder% >"%AppData%\Wasif\folder.spfile"
  62. call :LockFolder "%AppData%" "Wasif"
  63. call :LockFolder "%folder%" "SecretLocker"
  64. ping localhost -n 2 -w 1000 >nul 2>&1
  65. ::*************************************************************
  66. cls
  67. echo Creation of the private folder was done
  68. echo To work with the folder, re-launch this (%~nx0) batch file
  69. echo Then input the password again and options will come
  70. echo.
  71. pause >nul | echo Press any key to quit.....
  72. exit /b 0
  73. ::***********************************************************
  74.  
  75. :Unlocker_Password
  76. ::***********************************************************
  77. cls & echo. & echo.
  78. Call :InputPassword "Enter your password"
  79. Call :UnlockFolder "%Appdata%" "Wasif" False
  80. set /p actpassword=<"%Appdata%\Wasif\pwd.spfile"
  81. if %actpassword%==%password% (goto :Unlocker_Menu)
  82. goto :Bad_Password
  83. ::***********************************************************
  84. :Bad_Password
  85. color 0c & cls
  86. echo Bad password entered
  87. pause >nul | echo Press any key to quit.....
  88. Call :LockFolder "%Appdata%" "Wasif"
  89. exit /b 0
  90. ::***********************************************************
  91. :Unlocker_Menu
  92. cls & color 0a & echo. & echo.
  93. for /f "tokens=* delims= " %%a in ('type "%Appdata%\Wasif\folder.spfile"') do set "folder=%%a"
  94. echo                      ###################################
  95. echo                              Folder Locker Menu
  96. echo                      ###################################
  97. echo                Private folder is in: %folder:~0,-1%
  98. echo.
  99. echo [1] Unlock Private folder
  100. echo [2] Unlock Private folder and open in explorer
  101. echo [3] Change password
  102. echo [4] Delete Private folder
  103. echo [5] Lock and Quit (Recommended you quit from here)
  104. choice /c 12345 /n
  105. goto %errorlevel%
  106. ::***********************************************************
  107. :1
  108. Call :UnlockFolder "%folder:~0,-1%" "SecretLocker" False
  109. cls & echo Unlocked!
  110. pause & Goto :Unlocker_Menu
  111. ::***********************************************************
  112. :2
  113. Call :UnlockFolder "%folder:~0,-1%" "SecretLocker" True
  114. cls & echo Unlocked!
  115. pause & Goto :Unlocker_Menu
  116. ::***********************************************************
  117. :3
  118. Call :InputPassword "Enter new password"
  119. echo %password% >"%Appdata%\Wasif\pwd.spfile"
  120. cls & echo Changed password!
  121. pause & goto :Unlocker_Menu
  122. ::***********************************************************
  123. :4
  124. Call :Unlock_Folder "%folder:~0,-1%" "SecretLocker" False
  125. rd /s /q "%folder:~0,-1%\SecretLocker"
  126. rd /s /q "%Appdata%\Wasif"
  127. del /f /q "%userprofile%\id.spfile"
  128. cls & echo Deletion was successful!
  129. pause >nul | echo Press any key to quit...
  130. exit /b 0
  131. ::***********************************************************
  132. :5
  133. Call :LockFolder "%Appdata%" "Wasif"
  134. Call :LockFolder "%folder:~0,-1%" "SecretLocker"
  135. exit /b 0
  136. ::***********************************************************
  137.  
  138. :: Functions                      
  139. ::************************************************************
  140. :ChooseFolder <StrInitialFolderPath> <StrDescription>
  141. for /f "usebackq tokens=* delims=" %%a in (`powershell -Command "& {Add-Type -AssemblyName System.windows.forms;$f=New-Object System.Windows.Forms.FolderBrowserDialog;$f.SelectedPath='%~1';$f.Description='%~2';$f.ShowDialog();$f.SelectedPath}"`) do set "folder=%%a"
  142. exit /b 0
  143. ::************************************************************
  144. :LockFolder <StrParentFolderPath> <StrFolderName>
  145. set "alias=AnonymousHacker.{2227A280-3AEA-1069-A2DE-08002B30309D}"
  146. ren "%~1\%~2" "%alias%" >nul 2>&1 & attrib +r +s +h "%~1\%alias%" >nul 2>&1
  147. icacls "%~1\%alias%" /deny Users:F >nul 2>&1 & exit /b 0
  148. ::************************************************************
  149. :UnlockFolder <StrParentFolderPath> <StrOldFolderName> <BoolOpenInExplorer>
  150. set "alias=AnonymousHacker.{2227A280-3AEA-1069-A2DE-08002B30309D}"
  151. icacls "%~1\%alias%" /grant Users:F >nul 2>&1 & attrib -r -s -h "%~1\%alias%" >nul 2>&1
  152. ren "%~1\%alias%" "%~2" >nul 2>&1 & if '%~3'=='True' (explorer "%~1\%~2")
  153. exit /b 0
  154. ::************************************************************
  155. :InputPassword <StrPrompt>
  156. for /f "tokens=* delims=" %%a in ('powershell -command "& {$Password=read-host '%~1' -AsSecureString;$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password);[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)}"') do set "password=%%a"
  157. exit /b 0
  158. ::************************************************************@echo off & title Folder Locker & pushd "%~dp0" & color 0a
  159. ::****************************************************************
  160. openfiles >nul 2>&1 & if %errorlevel% EQU 1 (
  161.   setlocal disableDelayedExpansion & color 4f
  162.   echo Running Admin Shell, Please wait.... & ping localhost -n 1 >nul
  163.   set "bPath=%~f0" & setlocal enableDelayedExpansion
  164.   echo Dim UAC : Set UAC = CreateObject^("Shell.Application"^) >Elevate.vbs
  165.   echo For Each strArg in Wscript.Arguments >>Elevate.vbs
  166.   echo   args = args ^& strArg ^& " " >>Elevate.vbs
  167.   echo Next >>Elevate.vbs
  168.   echo UAC.ShellExecute "!bPath!",args,"","runas",1 >>Elevate.vbs
  169.   echo Set objShell = Nothing >>Elevate.vbs
  170.   cscript //nologo Elevate.vbs & del Elevate.vbs & exit /b
  171. )
  172. ::****************************************************************
  173. if not exist "%userprofile%\desktop\%~n0.lnk" (
  174.   (
  175.   echo Call Shortcut("%~f0","Folder Locker"^)
  176.   echo Sub Shortcut(Application,Name^)
  177.   echo    Dim objShell,DesktopPath,objShortCut,MyTab
  178.   echo    Set objShell = CreateObject("WScript.Shell"^)
  179.   echo    MyTab = Split(Application,"\"^)
  180.   echo    If Name = "" Then
  181.   echo      Name = MyTab(UBound(MyTab^)^)
  182.   echo    End if
  183.   echo    DesktopPath = objShell.SpecialFolders("Desktop"^)
  184.   echo    Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Name ^& ".lnk"^)
  185.   echo    objShortCut.TargetPath = Chr(34^) ^& Application ^& Chr(34^)
  186.   echo    ObjShortCut.IconLocation = "shell32.dll,47"
  187.   echo    objShortCut.Save
  188.   echo End Sub
  189.   ) >>crshort.vbs
  190.   cscript //nologo crshort.vbs & del crshort.vbs
  191. )
  192. ::**************************************************************
  193. mode 160,40
  194. if not exist "%userprofile%\id.spfile" goto first_lock
  195. goto :Unlocker_Password
  196. :first_lock
  197. cls & echo. & echo.
  198. echo                              #########################################
  199. echo                                      Welcome to Folder Locker
  200. echo                              #########################################
  201. echo.
  202. echo No Private Folder was found, a folder is needed to be created
  203. echo.
  204. Call :InputPassword "Create a strong password for the locker"
  205. ::**************************************************************
  206. cls & echo. & echo.
  207. echo Please choose a folder where to create the locker, a dialog box will come:
  208. Call :ChooseFolder "%Userprofile%\Desktop" "Choose the folder where the hidden folder locker will be created, preffereably choose an unpredictable secure location, though it will be completely hidden"
  209. cls
  210. ::**************************************************************
  211. echo             #########################################################################
  212. echo                            Creating the private folder, please wait.....
  213. echo             #########################################################################
  214. echo.
  215. type nul >"%userprofile%\id.spfile"
  216. md "%folder%\SecretLocker" & md "%AppData%\Wasif"
  217. echo %password% >"%AppData%\Wasif\pwd.spfile"
  218. echo %folder% >"%AppData%\Wasif\folder.spfile"
  219. call :LockFolder "%AppData%" "Wasif"
  220. call :LockFolder "%folder%" "SecretLocker"
  221. ping localhost -n 2 -w 1000 >nul 2>&1
  222. ::*************************************************************
  223. cls
  224. echo Creation of the private folder was done
  225. echo To work with the folder, re-launch this (%~nx0) batch file
  226. echo Then input the password again and options will come
  227. echo.
  228. pause >nul | echo Press any key to quit.....
  229. exit /b 0
  230. ::***********************************************************
  231.  
  232. :Unlocker_Password
  233. ::***********************************************************
  234. cls & echo. & echo.
  235. Call :InputPassword "Enter your password"
  236. Call :UnlockFolder "%Appdata%" "Wasif" False
  237. set /p actpassword=<"%Appdata%\Wasif\pwd.spfile"
  238. if %actpassword%==%password% (goto :Unlocker_Menu)
  239. goto :Bad_Password
  240. ::***********************************************************
  241. :Bad_Password
  242. color 0c & cls
  243. echo Bad password entered
  244. pause >nul | echo Press any key to quit.....
  245. Call :LockFolder "%Appdata%" "Wasif"
  246. exit /b 0
  247. ::***********************************************************
  248. :Unlocker_Menu
  249. cls & color 0a & echo. & echo.
  250. for /f "tokens=* delims= " %%a in ('type "%Appdata%\Wasif\folder.spfile"') do set "folder=%%a"
  251. echo                      ###################################
  252. echo                              Folder Locker Menu
  253. echo                      ###################################
  254. echo                Private folder is in: %folder:~0,-1%
  255. echo.
  256. echo [1] Unlock Private folder
  257. echo [2] Unlock Private folder and open in explorer
  258. echo [3] Change password
  259. echo [4] Delete Private folder
  260. echo [5] Lock and Quit (Recommended you quit from here)
  261. choice /c 12345 /n
  262. goto %errorlevel%
  263. ::***********************************************************
  264. :1
  265. Call :UnlockFolder "%folder:~0,-1%" "SecretLocker" False
  266. cls & echo Unlocked!
  267. pause & Goto :Unlocker_Menu
  268. ::***********************************************************
  269. :2
  270. Call :UnlockFolder "%folder:~0,-1%" "SecretLocker" True
  271. cls & echo Unlocked!
  272. pause & Goto :Unlocker_Menu
  273. ::***********************************************************
  274. :3
  275. Call :InputPassword "Enter new password"
  276. echo %password% >"%Appdata%\Wasif\pwd.spfile"
  277. cls & echo Changed password!
  278. pause & goto :Unlocker_Menu
  279. ::***********************************************************
  280. :4
  281. Call :Unlock_Folder "%folder:~0,-1%" "SecretLocker" False
  282. rd /s /q "%folder:~0,-1%\SecretLocker"
  283. rd /s /q "%Appdata%\Wasif"
  284. del /f /q "%userprofile%\id.spfile"
  285. cls & echo Deletion was successful!
  286. pause >nul | echo Press any key to quit...
  287. exit /b 0
  288. ::***********************************************************
  289. :5
  290. Call :LockFolder "%Appdata%" "Wasif"
  291. Call :LockFolder "%folder:~0,-1%" "SecretLocker"
  292. exit /b 0
  293. ::***********************************************************
  294.  
  295. :: Functions                      
  296. ::************************************************************
  297. :ChooseFolder <StrInitialFolderPath> <StrDescription>
  298. for /f "usebackq tokens=* delims=" %%a in (`powershell -Command "& {Add-Type -AssemblyName System.windows.forms;$f=New-Object System.Windows.Forms.FolderBrowserDialog;$f.SelectedPath='%~1';$f.Description='%~2';$f.ShowDialog();$f.SelectedPath}"`) do set "folder=%%a"
  299. exit /b 0
  300. ::************************************************************
  301. :LockFolder <StrParentFolderPath> <StrFolderName>
  302. set "alias=AnonymousHacker.{2227A280-3AEA-1069-A2DE-08002B30309D}"
  303. ren "%~1\%~2" "%alias%" >nul 2>&1 & attrib +r +s +h "%~1\%alias%" >nul 2>&1
  304. icacls "%~1\%alias%" /deny Users:F >nul 2>&1 & exit /b 0
  305. ::************************************************************
  306. :UnlockFolder <StrParentFolderPath> <StrOldFolderName> <BoolOpenInExplorer>
  307. set "alias=AnonymousHacker.{2227A280-3AEA-1069-A2DE-08002B30309D}"
  308. icacls "%~1\%alias%" /grant Users:F >nul 2>&1 & attrib -r -s -h "%~1\%alias%" >nul 2>&1
  309. ren "%~1\%alias%" "%~2" >nul 2>&1 & if '%~3'=='True' (explorer "%~1\%~2")
  310. exit /b 0
  311. ::************************************************************
  312. :InputPassword <StrPrompt>
  313. for /f "tokens=* delims=" %%a in ('powershell -command "& {$Password=read-host '%~1' -AsSecureString;$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password);[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)}"') do set "password=%%a"
  314. exit /b 0
  315. ::************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement