There is a program. I want to make a console application that would launch it. How to do it?

For the development of used visual studio.

( I need to protect the program from non-licensed use. To do this, I am writing an application that creates a file, without which the program cannot work. Next, this application must run the exe file. All this (console application) does, of course, only when the necessary conditions are fulfilled. )

    5 answers 5


      @ Andrei Alekseev , and it works in Windows too

       #include <stdio.h> #include <stdlib.h> #include <unistd.h> #define check_is_OK() (1) main () { if (check_is_OK()) execl("c:/Documents and Settings/avp/src/hashcode/a.exe","xaxa",0); printf ("Not working...\n"); exit(-1); } 

      In short, the program in the same process changes its code. Or in other words, calls the executable module, and ends itself.

      In this case, the module called .exe will see its name not c:\Documents and Settings\avp\src\hashcode\a.exe and xaxa .

      For more information about the functions of the exec family, read man 2 execl

      • @avp: based on Visual Studio and the complexity of the issue, the vehicle may have problems with man . +1 for cross-platform solution and process replacement. PS: and if you still need to specify the type of the return value of the function? - VladD
      • At the Visual Studio TS, unistd.h is not there, pulled out with MinGW or Cygwin, she flatly refuses to accept. - falstaf
      • Generally speaking, I found only one library that provides a relatively cross-platform way to start processes - Poco , class Process . - skegg
      • one
        @mikillskegg There is still boost :: process (but it is not included in the official boost). Well, for the task sounded by the TC and a simple system (...) is enough, it is also quite a cross platform. - falstaf
      • 2
        Here is the simplest #include <Poco / Process.h> using namespace :: Poco; int main () {Process :: Args args; args.push_back (""); args.push_back (""); ProcessHandle handler = Process :: launch ("google-chrome", args); handler.wait (); } - skegg

      Use CreateProcess (another description ) or at worst WinExec , but this is already outdated.

        You can use the CreateProcess function. But I do not think that in this way you will get any good protection.

        • there is particularly difficult and not needed. The price is not so high that they would try to hack it. It has a narrow focus. - andrw
        • @ Andrei Alekseev: what is the basis of protection? If someone will copy, copy and console application. - VladD
        • for enthusiasts, the price does not matter) the bottleneck is to check the license, and even so it’s easy to open .exe will give you a lot of antiviruses. - vv2cc
        • @VladD, protection is based on time. month. This program is not needed without the fee that we (at my place of work) are releasing. It is written specifically for this board. and the protection is based on time. There will be a txt file in which there is an initial license date and a final one. each time we go in, the program will overwrite the start date. those. Changing the date in the computer will not help. And protection is not from copying, but from long time use. - andrw
        • one
          @Andrey Alekseev: Why is there a separate command line utility for this? Check everything in the main program, business! - VladD

        @VladD , so as not to program the program. In a month, if you pay money (conditions - 50% of the amount before, 50% after), you must leave the program without checking. Of course, you can leave the verification condition, but this is an extra cost. The programs work under the old computers.

        • 2
          Nooooo, it seems to me that everything is not so tragic. The condition is certainly checked in a couple of microseconds, and no one will notice. In addition, the cost of launching a new process is much more than an elementary check, especially on older computers. So no benefit is visible, some are flaws. - VladD
        • Ok-ok) convinced-I run everything in the same application - andrw
        • @andrw: now we must also convince the topstarter :) - VladD
        • @VladD, convinced: D when I tied this account to facebook, then for some reason I re-registered my account for the same mail .. - andrw
        • @ HashCode, @andrw: we need to inform the moderators, let them connect accounts. - VladD 3:49 pm