Re: Detect if running in Windows environment
- From: "Bill Leary" <Bill_Leary@xxxxxxx>
- Date: Wed, 14 Mar 2007 23:01:01 -0400
"Sonny" <smaniaol@xxxxxxxxx> wrote in message news:1173920544.685864.255050@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mar 14, 6:20 pm, Herbert Kleebauer <k...@xxxxxxxxx> wrote:
uhm, how can I do this? Can you please elaborate, if possible with a
code. Thanks
I've been using the following since Windows 95, or maybe even Windows 3.1.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *test;
for (test = getenv("PATH"); *test != '\0'; test++)
{
if ((strnicmp(test, "\\windows\\", 9) == 0)
|| (strnicmp(test, "\\winnt\\", 7) == 0))
{
fprintf(stderr, "Program won't run under Windows\n");
fflush(stderr);
exit(-1);
}
}
printf("Not windows, we're good\n");
fflush(stdout);
/* Rest of program goes here */
}
The draw back, of course, is that if the user installs in a non-standard location, this will fail.
It will also fail if the user, say under Windows 95, boots to DOS rather than Windows because "\Windows\" will still be in their path.
It worked for my purposes because the customer machines were always built "normally," thus causing the Windows directory to be where it belonged. For my own purposes, I always included a command line argument to override the detection. So, when I had the machines booted under DOS rather than Windows, I could include the override and get the program to work anyway. But the users were never told about the override, so they couldn't pull that trick.
- Bill
.
- References:
- Detect if running in Windows environment
- From: Sonny
- Re: Detect if running in Windows environment
- From: Herbert Kleebauer
- Re: Detect if running in Windows environment
- From: Sonny
- Detect if running in Windows environment
- Prev by Date: Re: Detect if running in Windows environment
- Next by Date: Re: Detect if running in Windows environment
- Previous by thread: Re: Detect if running in Windows environment
- Next by thread: Re: Detect if running in Windows environment
- Index(es):
Relevant Pages
|