Advanced Search

Results 1 to 2 of 2

Thread: Batch program - password protect and open program

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default Batch program - password protect and open program

    I wrote a batch program to open a program depending on a right or wrong password:

    Code:
    cls
    @echo off
    set passWord = samplepassword
    goto CHECK
    
    :CHECK
    echo SUP HOMIE:
    set/p "pass=>"
    if %pass%==%passWord% goto OPEN
    goto END
    
    :OPEN
    echo Right Password...
    @START "C:\Program Files\SampleProgram\SampleProgram.exe"
    goto END
    
    :END
    echo closing...
    pause
    It doesn't work, though. No matter what you type in as the password, it goes to END. Before, when I was messing with it, I got it to OPEN, but it went to OPEN no matter what the user inputted. And, what opened was not the program, just a command prompt with the address of the program in the title.

    Any ideas?
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Code:
    set passWord = samplepassword
    No spaces in between the equal sign. It means that the batch script will look for %passWord % and not %password%

    set/p "pass=>" should be set /p pass="Password=> "

    And lastly, there's no need for start. You can use cmd /c [COMMAND]

    Here's the working code:

    Code:
    cls
    @echo off
    set passWord=samplepassword
    goto CHECK
    
    :CHECK
    echo SUP HOMIE:
    set /p pass="Password=> "
    if %pass%==%passWord% goto OPEN
    goto END
    
    :OPEN
    echo Right Password...
    cmd /c "C:\Program Files\SampleProgram\SampleProgram.exe"
    goto END
    
    :END
    echo closing...
    pause
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •