Results 1 to 18 of 18

Thread: [Help Needed] Require Correct Input and execute bat

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Exclamation [Help Needed] Require Correct Input and execute bat

    Is there a way to require a person to enter a certain text to get it to continue like:
    Code:
    const int size = 5;
    char enter[size];
    cout << "enter hello";
    cin >> enter
    and then get it to continue if the text was entered correctly, also, is there a way to shell a bat file?
    Last edited by Bobalandi; Sep 13th, 2007 at 08:51 PM.
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Require Correct Input and execute bat

    ..yes.
    Code:
    while (true)
    {
        cout << "Enter Hello" << endl;
        cin >> hello;
        if (hello == "hello")
            break;
        cout << "Incorrect" << endl;
    }
    Windows.h has the definition of the ShellExecute API. That will 'shell a bat file' for you.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: Require Correct Input and execute bat

    thanks a bunch...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [RESOLVED] Require Correct Input and execute bat

    Whoops, forgot to ask, is this a function, or should I just add this in the main code?
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [RESOLVED] Require Correct Input and execute bat

    umm... this doesnt work, no matter what you put, the answer is incorrect....
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  6. #6
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [RESOLVED] Require Correct Input and execute bat

    Show your code.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [RESOLVED] Require Correct Input and execute bat

    Here you go:
    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    int main()
    {
    	while (true)
    {
        cout << "Please enter the correct password: ";
        char pass[9];
    	cin >> pass;
        if (pass == "Bobalandi")
            break;
        cout << "Wrong Password...\n";
    }
    	ShellExecute(0,"OPEN","me.bat","","",SW_NORMAL);
    	cin.get();
    	return 0;
    }
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  8. #8
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [RESOLVED] Require Correct Input and execute bat

    Try using a string:
    Code:
    // char pass[9];
    string pass;
    Remember, when you type the "password" in.. its case-sensitive.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [RESOLVED] Require Correct Input and execute bat

    hmmm, string desnt even work with the compiler..
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  10. #10
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [RESOLVED] Require Correct Input and execute bat

    Oh.. you need to include <string>.

    I think its best if you research the Standard Library and the most useful/common containers and types.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [RESOLVED] Require Correct Input and execute bat

    Edit: It works with string, but now I am using this code to execute a batch, but it isnt working... any ideas?
    c++ Code:
    1. int main()
    2. {
    3.     while (true)
    4. {
    5.     cout << "Please enter the correct password: ";
    6.     string pass;
    7.     cin >> pass;
    8.     if (pass == "Bobalandi")
    9.         break;
    10.     cout << "Wrong Password...\n";
    11.     ShellExecute(0,"OPEN","badpass.bat","","",SW_NORMAL);
    12. }
    13.     ShellExecute(0,"OPEN","me.bat","","",SW_NORMAL);
    14.     cin.get();
    15.     return 0;
    16. }
    When it is correct it works, but the incorrect one doesn't...
    Last edited by Bobalandi; Sep 13th, 2007 at 07:38 PM.
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [Help Needed] Require Correct Input and execute bat

    One more question, is it possible to to shellexecute that .bat in the same window as the commandline app that it is in?
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  13. #13
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [Help Needed] Require Correct Input and execute bat

    No thats not possible. Well.. anything is possible, but what you're talking about is extremely low-level if possible..

    What are you trying to do exactly.. ? Do you want that badpass batch file to execute every single time the user enters a bad password?

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [Help Needed] Require Correct Input and execute bat

    no, just once, and then end the program...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  15. #15
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [Help Needed] Require Correct Input and execute bat

    You don't need a while loop for that then...
    C++ Code:
    1. #include <windows.h>
    2. #include <iostream.h>
    3. #include <string>
    4.  
    5. int main()
    6. {
    7.     std::string pass;
    8.     std::cout << "Enter your password: ";
    9.     std::cin >> pass;
    10.     if (pass == "Bobalandi")
    11.         ShellExecute(0, "OPEN", "badpass.bat", "", "", SW_NORMAL);
    12.     else
    13.         ShellExecute(0, "OPEN", "me.bat", "", "", SW_NORMAL);
    14. }
    ...

    Have you tried putting the full path to the batch files in there?

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [Help Needed] Require Correct Input and execute bat

    well, the problem, is that it is on a usb drive... so the path is dynamic, also, the me.bat works, but the other one doesnt...
    PS. Is there a way to get the bat file to execute from the same window as this console app?
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  17. #17
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [Help Needed] Require Correct Input and execute bat

    No you can't get it to execute from inside the console application. Its a completely different environment. If you make a console application that just lets the user type stuff in, and the user types "cd C:".. nothing will happen.

    Are you sure its not a problem with your batch file then? Because the code above works for me fine..

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [Help Needed] Require Correct Input and execute bat

    ok, I'll check the file, thanks for all your help...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

Posting Permissions

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



Click Here to Expand Forum to Full Width