|
Answer» Hi all
you know that we use the command REG QUERY to get the data of a value in the registry
How can I make a variable take the data of a value OR value under a key as a value of it
Thanks if you want a single key to variable try this:
Code: [Select]@echo off Reg Query <the key name> > <temporary file> set /p return=<<same temporary file>
example: @echo off reg query EXAMPLEKEY > return.tmp set /p return= Hope this helps ,Nick(macdad-)Hello
This is the contene of my BATCH file
it is simple locker of files
so user can lock his files by a password
you can read it in know how it doesn,t work ( when it unlocks the folder
P.S : I want to convert it to exe file
Code: [Select]cls @ECHO OFF title Folder Locker BY: Feras Jubeir --- E-mail: [emailprotected] mode 70,18 color 12 if EXIST "Control Panel.{21EC2020- 3AEA-1069- A2DD-08002B30309 D}" goto UNLOCK if NOT EXIST Locker goto MDLOCKER :CONFIRM cls echo. echo Are you sure you want to Lock the folder (Y/N) echo. set/p "cho=>" if %cho%==Y goto LOCK if %cho%==y goto LOCK if %cho%==n goto END if %cho%==N goto END goto CONFIRM :LOCK cls echo. echo Enter your password please echo. set/p "pass1=>" cls echo. echo Re enter your password please echo. set/p "pass2=>" if NOT %pass1%==%pass2% goto relock ren Locker "Control Panel.{21EC2020- 3AEA-1069- A2DD-08002B30309 D}" attrib +h +s "Control Panel.{21EC2020- 3AEA-1069- A2DD-08002B30309 D}" goto End :relock cls echo. echo Sorry, The entered passwords do not match echo. echo Enter your password please echo. set/p "pass3=>" cls echo. echo Re enter your password please echo. set/p "pass4=>" if NOT %pass3%==%pass4% goto relock ren Locker "Control Panel.{21EC2020- 3AEA-1069- A2DD-08002B30309 D}" attrib +h +s "Control Panel.{21EC2020- 3AEA-1069- A2DD-08002B30309 D}" echo Folder locked goto End :UNLOCK cls echo. echo Enter your password please echo. set/p "unlockpass=>" if %unlockpass%==%pass1% goto unlocked if %unlockpass%==%pass3% goto unlocked goto FAIL :unlocked cls attrib -h -s "Control Panel.{21EC2020- 3AEA-1069- A2DD-08002B30309 D}" ren "Control Panel.{21EC2020- 3AEA-1069- A2DD-08002B30309 D}" Locker echo Folder Unlocked successfully goto End :FAIL cls echo. echo. echo. echo. echo. echo. echo WRONG Password echo. echo. echo. echo. pause exit :MDLOCKER md Locker goto End :End exit
thank you i can tell you that the variables that HOLD the password are deleted after the batch program closes. this happens to all variables in batch.
try storing the password in a registry key.
and for turning this into a EXE, try here: http://www.download.com/Bat-To-Exe-Converter/3000-2069_4-10555897.htmlhello
I have bat to exe converter
*I stored the password in reg key, please write here the complete code
Thank you could just use REG Query again to load up the password into a variable once the batch program starts..like i showed you before.this is a script i wrote few months ago when i learn "reg query". this will set the autorun status of drive type. autorun.bat purpose: example when you plug in a USB flashdisk, if autorun for removable is on, then it will automatically execute the "autorun.inf" in the flashdisk. if flashdisk contain virus, then your computer will be infected.
you can learn how to read and write to registry from below batch, you are free to modify and use it to suit your need.
Code: [Select]::AutoRun.bat DriveType as %1 [On|Off as %2] @echo off&setlocal enabledelayedexpansion
set 0=BACKUPREG set 1=UNKNOWNDRIVE set 2=NOROOTDIR set 4=REMOVABLE set 8=HDD set 16=NETWORK set 32=CDROM set 64=RAMDISK set 128=RESERVE set 255=ALL
echo.%*|find "?">nul && goto :SYNTAX || if "%~1"=="" %0 ALL
set TYPE= for %%i in (1 2 4 8 16 32 64 128 255) do if /i !%%i!==%~1 set TYPE=%%i if not defined TYPE goto :SYNTAX
set QUERY=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoDriveTypeAutorun %3 cls %3 reg query %QUERY% %3 if ERRORLEVEL 1 reg add %QUERY% /t REG_DWORD /d 0 & %0 %* echo ------------------------------------------------------------------------
::Display Current Status for /f "skip=4 tokens=3 delims= " %%a in ('reg query %QUERY%') do set /a VALUE=%%a echo ^>^>AutoRun Status: for %%i in (1 2 4 8 16 32 64 128) do ( set /a CMP=%TYPE%^&%%i if not !CMP!==0 ( set /a CMP=%VALUE%^&%%i if !CMP!==0 (echo !%%i! = ON) ELSE echo !%%i! = OFF ) )
::Toggle Drive Type to On or Off if NOT "%~2"=="" ( if /i "%~2"=="ON" set /a CMP=%TYPE%^^0xFF & set /a VALUE=!VALUE!^&!CMP! if /i "%~2"=="OFF" set /a VALUE=!VALUE!^|!TYPE! reg add %QUERY% /t REG_DWORD /d !VALUE! /f if not errorlevel 1 %0 ALL "" :: ) %3 echo. & echo Type %0 /? For Help
pause & endlocal & exit /b 0
:BACKUPREG for %%i in (HKLM :SYNTAX echo Check Autorun Status Base On DriveType & echo. echo Usage: %0 DriveType [ON^|OFF] & echo. echo DriveType: for %%i in (1 2 4 8 16 32 64 128 255) do echo !%%i! echo. & echo [ON^|OFF]: Optional - Toggle AutoRun to ON or OFF endlocal & exit /b 1
WARNING: i am not responsible for any damage that might be cause by the above script. though its unlikely that it can cause damage, put the warning just in case mm
good
thanks
|