Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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.

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

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].

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

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.

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.

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.

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

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.

![]() |
![]() |
![]() |

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