Computing.Net > Forums > Programming > c++ prevent program execution

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

c++ prevent program execution

Reply to Message Icon

Name: DJAS
Date: August 25, 2007 at 07:37:35 Pacific
OS: Fedora Core 6/Windows Vis
CPU/Ram: Intel T7200 2.00GHz 1024M
Product: LG S1 Pro
Comment:

Ok we've all seen the anoying error message "this msi must be launched through setup" when you try to lauch a Microsoft installation file manually but is there a way to create a similar effect on my own program?
I have to applications, the first program launches the second after running a few checks using WinExec(). But I want to be able to prevent the second program from being executed manually.
Does anyone know a method of doing this?

Thanks in advance :)
DJAS



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: August 25, 2007 at 09:11:29 Pacific
Reply:

If you look at the command line for that program when it launches through setup, you'll notice a fairly cryptic command line argument. So, preventing execution is as simple as a cstring comparison.


0

Response Number 2
Name: DJAS
Date: August 25, 2007 at 12:30:38 Pacific
Reply:

I'm sorry I don't quite understand what you mean. How can I see the command line if its run through the setup?


0

Response Number 3
Name: Razor2.3
Date: August 25, 2007 at 15:10:50 Pacific
Reply:

The command line is something Windows keeps track of, but never reports to the standard user.

You have a few options. First, you can download something like Process Explorer, or you could use [a] WMI [script].


0

Response Number 4
Name: DJAS
Date: August 25, 2007 at 17:18:42 Pacific
Reply:

ok you've completely lost me now, sorry but can you please explain in a bit more detail? Maybe if you could give a small code example?

thanks


0

Response Number 5
Name: Razor2.3
Date: August 25, 2007 at 19:43:40 Pacific
Reply:

A code sample for what, exactly? WMI? The link I gave you has examples. Not explicitly spelled out, true, but it's not your only option. Just go with Process Explorer.

Alternatively, you could just read up on how to use command line arguments in C++, and skip knowing whatever argument setup passes that msi.


0

Related Posts

See More



Response Number 6
Name: DJAS
Date: August 26, 2007 at 06:35:58 Pacific
Reply:

Well the two applications i'm talking about I have written myself and would like to be able to implement a similar system that the msi uses. That is why I asked for a code example because I may be wrong but I assumed there would be some form of code exception handling involved to prevent manual execution.
Sorry if I'm being totally dense in not understanding but I fail to see how Process Explorer can help me with my problem.



0

Response Number 7
Name: Razor2.3
Date: August 26, 2007 at 17:22:47 Pacific
Reply:

It wouldn't. All it would show you is the method that the MSI uses, which is a command line argument.

Look, it's not really that hard. Just poll some data, make a hash, and pass it as an argument to your other EXE. Then, that program polls the same data, makes a hash, and then compares its results to the argument. If they match, you're golden. If not, throw a dialog box and exit the program.


0

Response Number 8
Name: DJAS
Date: August 27, 2007 at 14:35:15 Pacific
Reply:

Thanks for making it clear, I understand now. So for example I could generate an md5 hash and pass it as an argument to the second app which would in turn try to generate the same hash and compare them.
I know I've been a pain but I got there in the end and I'm sorry I took so long.
Thanks again
DJAS


0

Response Number 9
Name: RWD1996
Date: September 5, 2007 at 22:08:46 Pacific
Reply:

I've done this very thing in plain C. I've never used C++, but it looks like it should work. It might be too late but I thought I'd just throw this in.

Suppose that the program that runs this 2nd program is A, and the 2nd program, the one that throws the error is B.

In C, the Command Line is a string in the WinAPI function. It's the 3rd argument in WinAPI. In my program, program A just executed program B passing a predefined command line switch. Then when program B is launched, it tries to find the command line switch in the command line. If it's not found, it throws an error.

Here's a sample of how it worked...

----------

#include <windows.h>
#include <string.h>

const char clswitch[] = "-runprog"; // the switch that program 1 passes to program 2. If the command line does not contain this, the program throws an error

int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) // lpszArgument are the command line arguments
{
// The comparison
if ((_stristr(lpszArgument, clswitch)) != 0) // if somebody just double-clicked the file,
{
MessageBox(GetActiveWindow(), "Please run the setup application.", "Error", MB_OK | MB_ICONSTOP); //alert the user
return 0; //exit the program
}

/*

Program initialization goes here

*/

return 0;
}

----------

It's a tried and proven fact that Jesus is the answer for every problem that people who trust in Him have.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: c++ prevent program execution

Pause program execution www.computing.net/answers/programming/pause-program-execution/3573.html

c-64 program www.computing.net/answers/programming/c64-program/115.html

C programing in DOS www.computing.net/answers/programming/c-programing-in-dos/1217.html