Vibsy
Vibsy

Reputation: 11

how to write a vbscript to ask for password for running the actual script....?

I want a vbscript which can be added before a desired vbscript to ask for a password to run the desired vbscript.

For example, a script for opening the browser window is there. I want to add password protection for running this script. On running the whole script, first it should ask for password, and then if password is correct, it should then open the browser window. If the password is wrong then ask for the password until it is correct.

I tried the below script to run a .bat file which was located at D:\Technical\jarvis Files\close firefox.bat in my pc, but had no successs.

Set objShell = CreateObject("Wscript.Shell")

dim password

password=InputBox("Please Enter Password:","3 - Tries Left")

if password = ("---------YOUR PASSWORD HERE---------") then
    dim correct
    correct =MsgBox("Correct Password!",64,"correct")
    objShell.Run("-------YOUR LINK HERE--------")

Else

dim again

      again =MsgBox("Incorect Password! Do You Want To Try Again?",53,"Incorect Password!")

    If again = 4 Then
    dim password2
    password2=InputBox("Please Enter Password:","2 - Tries Left")
    if password2 = ("---------YOUR PASSWORD HERE---------") then
        dim correct2
        correct2 =MsgBox("Correct Password!",64,"correct")
        objShell.Run("-------YOUR LINK HERE--------")
    Else
        dim again2
        again2 =MsgBox("Incorect Password! Do You Want To Try Again?",53,"Incorect Password!")
        If again2 = 4 Then
        dim password3
        password3=InputBox("Please Enter Password:","1 - Tries Left")
        if password3 = ("---------YOUR PASSWORD HERE---------") then
            dim correct3
            correct3 =MsgBox("Correct Password!",64,"correct")
            objShell.Run("-------YOUR LINK HERE--------")
        Else
            dim again3
            again3 =MsgBox("Incorect Password! Do You Want To Try Again?",53,"Incorect Password!")
            If again3 = 4 Then

                dim incorect
                incorect =MsgBox("To many incorect passwords! Program will now lock!",16,"WARNIG!!")
                objShell.Run("-------YOUR FAIL LINK HERE--------")

                    end if

                end if

            end if

        end if

    end if

end if

This is just what I tried, but I want to do it the other way. Instead of running a .vbs or .bat file with this, I want to integrate the code of that vbs script after the password prompt script so that before running the program script, the password is asked for.

Upvotes: 0

Views: 13574

Answers (1)

Bond
Bond

Reputation: 16321

The code you found is just using the InputBox() function to prompt the user to enter some text. In this case, the password. While you can certainly use InputBox() for this purpose, the text won't be obfuscated while the user is typing, which means their password will be visible to anyone looking over their shoulder.

BTW, this code isn't meant for a batch file (.BAT). It's a VBScript, which means you need to give it a .VBS extension. If you do that, then double-click it, you can see what it's doing.

See this page for two ways you can prompt the user to enter a password using VBScript. One is done via the command prompt and the other uses Internet Explorer to create a login form.

Good luck.

Upvotes: 0

Related Questions