+ OSVERSIONINFO osi;
+ HMODULE advapi;
+
+ /*
+ * Determine whether we're an NT system (should have security
+ * APIs) or a non-NT system (don't do security).
+ */
+ memset(&osi, 0, sizeof(OSVERSIONINFO));
+ osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ if (GetVersionEx(&osi) && osi.dwPlatformId==VER_PLATFORM_WIN32_NT) {
+ has_security = TRUE;
+ } else
+ has_security = FALSE;
+
+ if (has_security) {
+#ifndef NO_SECURITY
+ /*
+ * Attempt to ge the security API we need.
+ */
+ advapi = LoadLibrary("ADVAPI32.DLL");
+ getsecurityinfo = (gsi_fn_t)GetProcAddress(advapi, "GetSecurityInfo");
+ if (!getsecurityinfo) {
+ MessageBox(NULL,
+ "Unable to access security APIs. Pageant will\n"
+ "not run, in case it causes a security breach.",
+ "Pageant Fatal Error", MB_ICONERROR | MB_OK);
+ return 1;
+ }
+#else
+ MessageBox(NULL,
+ "This program has been compiled for Win9X and will\n"
+ "not run on NT, in case it causes a security breach.",
+ "Pageant Fatal Error", MB_ICONERROR | MB_OK);
+ return 1;
+#endif
+ } else
+ advapi = NULL;
+
+ /*
+ * First bomb out totally if we are already running.
+ */
+ if (FindWindow("Pageant", "Pageant")) {
+ MessageBox(NULL, "Pageant is already running", "Pageant Error",
+ MB_ICONERROR | MB_OK);
+ if (advapi) FreeLibrary(advapi);
+ return 0;
+ }