This is a program that is supposed to run on startup when the computer turns on...
What I did was I put the name of the program in the RunOnce Registry key attached below... when u double click the key, it puts the program name in the registry telling it to run the program on boot once and after that the key is deleted from the registry. The program was placed in my C:/Windows folder which is where the RunOnce key says to look... If it cant find the program, itll just skip it and load everything else.

thing is the program does get found, it does start... but it only prints/couts the first line onto the screen, opens another program aka system("\"C:/Program Files/Alwil Software/Avast5/AvastUI.exe\""); and then it never moves, it does nothing after that... it just stays on the screen showing cout<<"Opening Avast5\n"; It wont cout/print anything thing else after the system command... WHY? What have I done wrong? Why does the program not continue printing the rest of stuff/continue moving :S

If u want to see what I mean, doubleclick RunOnce.REG (dont worry it deletes itself after 1 boot). Copy patcherscript.exe to C:/Windows. and reboot... the program will then run and GET STUCK and delete the RunOnce =(

Note: if u are going to help... the RunOnce.cpp needs to be changed/rename/change extension to .REG so itll be RunOnce.REG not .cpp

U can edit it in a text file such as notepad just to see that it is not harmful/ search up RunOnce if u are scared to help but I need it

//PatcherScript
#include <iostream>
#include <windows.h>

using namespace std;

char x,y,z;

void RegRun();
void saymsg();
void getinput();
void askagain();
void start();       

int main()
{
    cout<<"Opening Avast5\n";
    system("\"C:/Program Files/Alwil Software/Avast5/AvastUI.exe\"");
    cout<<"Due to Tampering Laws, the following has to be done manually:\n\n";
    Sleep(2000);
    cout<<"In the Avast Window that is open, go to MAINTENANCE\n\n";
    Sleep(7000);
    cout<<"Press SUBSCRIPTION & Then Insert TRIAL License File:\n\n";
    Sleep(5000);
    cout<<"Insert the one in the folder where I am Located aka ~/Desktop/Avast5 :)\n";
    Sleep(7000);
    cout<<"Confirm it by pressing yes\n\n";
    Sleep(5000);
    cout<<"Go to Settings at the Very Top-Right\n\n";
    Sleep(5000);
    cout<<"Go to TroubleShooting at the left panel and uncheck:\n\n";
    cout<<"Self Defense Module, Confirm it by pressing YES\n";
    Sleep(7000);
    cout<<"When done:\n\n";
    system("Pause");
    cout<<"System Registry must be Edited Once more to add a New Key!\n";
    start();
    cout<<"Editing Finished According To User:\n";
    system("shutdown -r");
    cout<<"Restarting Computer in 60 Seconds\n";
    
    return 0;
}


     //Functions(1) Defined After Main and Before Main as Prototypes... Taken from old project "test cases.cpp" & Modified to Suit...


                                             
void RegRun()
{
     system("C:/Windows/RunOnce2.reg");
}

void saymsg()
{
     cout<<"Did you press yes to edit the registry this time?\n";
}

void getinput()
{
     cin>>x;
     cin.ignore();
     switch(x)
     {
              case '1': false;
                        break;
              case '2': askagain();
              break;
              default: cout<<"You entered A letter or character that is not in the menu\n";
                       cout<<"Please try again!\n";
                       cout<<"Did you press yes to allow registry editing?  y = 1  n = 2\n";
                       getinput();
              }     
}
void askagain()
{
     cout<<"Would you like to try editing the registry again?? 1 = Yes , 2 = No just exit!\n";
                   cin>>y;
                   cin.ignore();
                   switch(y){
                             case '1': 
                                  RegRun();
                                  saymsg();
                                  getinput();
                                  break;
                             case '2': exit(0);      // want to make the program terminate... tried return 0 but it failed...
                             break;
                             default: cout<<"You entered A letter or character that is not in the menu\n";
                                      cout<<"Please try again!\n";
                                      askagain();
                             break;
                             }
                   }
                   
void start()
{
     RegRun();
     cout<<"Did you press yes to allow registry editing?   y = 1   n = 2\n";
     getinput();
}

Recommended Answers

All 4 Replies

From this reference:

[system()] Invokes the command processor to execute a command. Once the command execution has terminated, the processor gives the control back to the program, returning an int value, whose interpretation is system-dependent.

This says that your program waits until the command executed with system() finishes. Does AvastUI.exe end?

well it cant end... its an antivirus... it stays running on the system

well it cant end... its an antivirus... it stays running on the system

Like WaltP said, the system call waits for the AvastUI.exe program to return. The rest of your program won't run until the system call returns.

Is there anyway to make it not wait for the return value?


Figured it out by changing the key to:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce]

Current User instead of Local Machine... that loads the desktop then runs the programs...

Pretty stupid that I cant skip the return value or anything :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.