Computer Hope

Microsoft => Microsoft DOS => Topic started by: Skamber on December 03, 2016, 10:21:23 AM

Title: Batch File Help
Post by: Skamber on December 03, 2016, 10:21:23 AM
I have done a batch file for my VeraCyrt and everyting is OKAY.. But when i select any (1-2-3) I need to press Enter to goto this line.. I want that; When I select any of these 3 choice; command line goes the line without pressing ENTER.. What should i do ?

thank you so much..



@ECHO off
cls
:start
ECHO.
ECHO 1. Mount with Read-Only Mode
ECHO 2. Mount with Writetable Mode
echo[
ECHO 3. Dismount Encrypted Partitions
echo[
set choice=
set /p choice=Type the number to start Action..
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto ROMode
if '%choice%'=='2' goto WritetableMode
if '%choice%'=='3' goto Dismount
cls
goto ROMode

:ROMode
cls
c:
cd "C:\Program Files\VeraCrypt"
echo "Please Enter Your Password to Encrypt Partition.."
VeraCrypt /v \\?\Volume{3fde54d0-27c1-01d2-682a-2d9ee013e900}\VCP /mountoption ro /a /e /q
cls
goto exit

:WritetableMode
cls
c:
cd "C:\Program Files\VeraCrypt"
echo "Please Enter Your Password to Encrypt Partition.."
VeraCrypt /v \\?\Volume{3fde54d0-27c1-01d2-682a-2d9ee013e900}\VCP /a /e /q
goto exit

:Dismount
cls
c:
cd "C:\Program Files\VeraCrypt"
veracrypt /q /d
goto Exit

:exit
cls
exit
Title: Re: Batch File Help
Post by: Salmon Trout on December 03, 2016, 12:07:55 PM
In Windows Vista onwards you have the Choice command. Study the documentation and type choice /? at the prompt

https://technet.microsoft.com/en-us/library/cc732504(v=ws.11).aspx

@echo off
ECHO 1. Mount with Read-Only Mode
ECHO 2. Mount with Writeable Mode
ECHO 3. Dismount Encrypted Partitions
CHOICE /C 123 /M "Your choice"
set choice=%errorlevel%


I fixed your spelling of 'writeable'.


Title: Re: Batch File Help
Post by: Skamber on December 04, 2016, 04:54:46 AM
thank you so much.. It works..

Here is final batch;

One more question; shoul i leave  "set choice=" command that line or can i remove it? What does it do ?



@ECHO off
cls
:start
ECHO.
ECHO.
echo. Build by SK - High Level Security Protection
ECHO.
ECHO  1. Mount with Read-Only Mode
ECHO  2. Mount with Writetable Mode
echo[
ECHO  3. Dismount Encrypted Partitions
ECHO  4. Exit
echo[
echo[

set choice=
CHOICE /C 1234 /M  "Your choice to Encrypt Security"
set choice=%errorlevel%
if '%choice%'=='1' goto RO
if '%choice%'=='2' goto Writeable
if '%choice%'=='3' goto Dismount
if '%choice%'=='4' goto Exit
cls

:RO
cls
c:
cd "C:\Program Files\VeraCrypt"
echo "Please Enter Your Password to Encrypt Partition.."
VeraCrypt /v \\?\Volume{3fde54d0-27c1-01d2-682a-2d9ee013e900}\VCP /mountoption ro /a /e /q
cls
goto exit

:Writeable
cls
c:
cd "C:\Program Files\VeraCrypt"
echo "Please Enter Your Password to Encrypt Partition.."
VeraCrypt /v \\?\Volume{3fde54d0-27c1-01d2-682a-2d9ee013e900}\VCP /a /e /q
goto exit

:Dismount
cls
c:
cd "C:\Program Files\VeraCrypt"
veracrypt /q /d
goto Exit

:exit
cls
exit

Title: Re: Batch File Help
Post by: Salmon Trout on December 04, 2016, 05:15:33 AM
Quote
One more question; shoul i leave  "set choice=" command that line or can i remove it? What does it do ?

This line
Code: [Select]
set choice=set the variable %choice% equal to NOTHING (it is blank) so that if you had this line immediately after, YES would be echoed.
Code: [Select]
if "%choice%"=="" echo YES
The line set choice= does nothing in your new code, since %choice% will always be set to the CHOICE command's errorlevel. You can take it out.
Title: Re: Batch File Help
Post by: Skamber on December 04, 2016, 05:43:52 AM
thank you very much.. I have done..

here is final..

@echo off
:: BatchGotAdmin
::-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"="
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"

@ECHO off
cls
ECHO.
ECHO.
echo. Build by SK - High Level Security Protection

:bitlocker
ECHO.
ECHO Unlock Bitlocker
manage-bde X: -unlock -pw
cls
goto Vera

:Vera
ECHO.
ECHO.
echo. Build by SK - High Level Security Protection
ECHO:
ECHO  1. Mount with Read-Only Mode
ECHO  2. Mount with Writeable Mode
echo[
ECHO  3. Dismount Encrypted Partitions
ECHO  4. Exit
echo[
echo[
CHOICE /C 1234 /M "Your choice to Encrypt Security"
set choice=%errorlevel%
if '%choice%'=='1' goto RO
if '%choice%'=='2' goto Writeable
if '%choice%'=='3' goto Dismount
if '%choice%'=='4' goto Exit
cls

:RO
cls
c:
cd "C:\Program Files\VeraCrypt"
echo "Please Enter Your Password to Encrypt Partition.."
VeraCrypt /v \\?\Volume{3fde54d0-27c1-01d2-682a-2d9ee013e900}\VCP /mountoption ro /a /e /q
cls
goto exit

:Writeable
cls
c:
cd "C:\Program Files\VeraCrypt"
echo "Please Enter Your Password to Encrypt Partition.."
VeraCrypt /v \\?\Volume{3fde54d0-27c1-01d2-682a-2d9ee013e900}\VCP /a /e /q
cls
goto exit

:Dismount
c:
cd "C:\Program Files\VeraCrypt"
veracrypt /q /d
cls
Echo.
Echo All Partitions Unmounted..
goto Vera

:exit
cls
exit
Title: Re: Batch File Help
Post by: Skamber on December 04, 2016, 06:57:28 AM
@echo off
:: BatchGotAdmin
::-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"="
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"

@ECHO off
cls
ECHO.

:Menu
ECHO.
ECHO.
echo. Build by SK - High Level Security Protection
ECHO:
ECHO  1. Unlock Bitlocker
ECHO  2. Mount with Read-Only Mode
ECHO  3. Mount with Writeable Mode
ECHO.
ECHO  4. Dismount Encrypted Partitions
ECHO  5. Lock Bitlocker
ECHO.
ECHO  6. Exit
ECHO.

CHOICE /C 123456 /M "Your choice to Encrypt Security"
set choice=%errorlevel%
if '%choice%'=='1' goto unlockbitlocker
if '%choice%'=='2' goto VeraRO
if '%choice%'=='3' goto VeraWriteable
if '%choice%'=='4' goto Dismount
if '%choice%'=='5' goto lockbitlocker
if '%choice%'=='6' goto exit
cls
 

:unlockbitlocker
cls
ECHO.
ECHO Unlock Bitlocker
manage-bde X: -unlock -pw
cls
echo.
Echo Bitlocked Unlocked..
goto Menu


:VeraRO
cls
c:
cd "C:\Program Files\VeraCrypt"
echo "Please Enter Your Password to Encrypt Partition.."
VeraCrypt /v \\?\Volume{3fde54d0-27c1-01d2-682a-2d9ee013e900}\VCP /mountoption ro /a /e /q
cls
echo.
Echo Partition Mounted with RO Mode..
goto Menu


:VeraWriteable
cls
c:
cd "C:\Program Files\VeraCrypt"
echo "Please Enter Your Password to Encrypt Partition.."
VeraCrypt /v \\?\Volume{3fde54d0-27c1-01d2-682a-2d9ee013e900}\VCP /a /e /q
cls
echo.
Echo Partition Mounted with Writeable Mode..
goto Menu


:Dismount
c:
cd "C:\Program Files\VeraCrypt"
veracrypt /q /d
cls
Echo.
Echo All Partitions Unmounted..
goto Menu

:lockbitlocker
cls
manage-bde -lock -ForceDismount X:
cls
echo.
Echo Bitlocked Locked..
goto Menu


:exit
cls
exit