Re: Detect if running in Windows environment




"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

.



Relevant Pages

  • Re: Those little dots
    ... > Marlett font char 'n' is thte one Windows uses. ... I thought it was unicode character $2022 of font Tahoma. ... Windows XP displays the dot. ...
    (borland.public.delphi.language.objectpascal)
  • Re: This showed up last night... What is it?!
    ... Zonealarm said "Rundll32.exe wants access to the Internet" I thought ... There also seemed to be an explorer.exe in my windows directory. ... On the mentions of IRC. ... > 25495 Char 10 goto start ...
    (comp.security.firewalls)
  • Re: [Full-disclosure] Windows .ANI LoadAniIcon Stack Overflow
    ... Windows .ANI LoadAniIcon Stack Overflow ... unsigned char uszAniHeader[] = ... memset(szBuffer, 0x90, sizeof(szBuffer)); ...
    (Full-Disclosure)
  • Re: Resetting the ms-DS-MachineAccountQuota attribute for a single use
    ... Override the Default Limit of the Number of Computers an ... You can override the default limit, using either of the following methods:. ... Use the Ldp tool included in the Microsoft Windows 2000 Resource ... I highly recommend the Delegation and discourage the Override limit. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Replacing fgets
    ... One more pointer is that if I use mmap it will solve my problem that is ... on SCO UNIX and on windows. ... char *buffer = 0; ... //Total Buffer Length ...
    (comp.lang.c)