if (FindWindow("Pageant", "Pageant"))
if (agent_exists())
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {    WNDCLASS wndclass;    MSG msg;    OSVERSIONINFO osi;    HMODULE advapi;    char *command = NULL;    int added_keys = 0;    /*     * 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 get 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;    instance = inst;    /*     * Find out if Pageant is already running.     */    already_running = FALSE;    if (FindWindow("Pageant", "Pageant"))	already_running = TRUE;    else {	if (!prev) {	    wndclass.style         = 0;	    wndclass.lpfnWndProc   = WndProc;	    wndclass.cbClsExtra    = 0;	    wndclass.cbWndExtra    = 0;	    wndclass.hInstance     = inst;	    wndclass.hIcon         = LoadIcon (inst,					       MAKEINTRESOURCE(IDI_MAINICON));	    wndclass.hCursor       = LoadCursor (NULL, IDC_IBEAM);	    wndclass.hbrBackground = GetStockObject (BLACK_BRUSH);	    wndclass.lpszMenuName  = NULL;	    wndclass.lpszClassName = APPNAME;	    RegisterClass (&wndclass);	}	hwnd = keylist = NULL;	hwnd = CreateWindow (APPNAME, APPNAME,			     WS_OVERLAPPEDWINDOW | WS_VSCROLL,			     CW_USEDEFAULT, CW_USEDEFAULT,			     100, 100, NULL, NULL, inst, NULL);	/* Set up a system tray icon */	{	    BOOL res;	    NOTIFYICONDATA tnid;	    HICON hicon;#ifdef NIM_SETVERSION	    tnid.uVersion = 0;	    res = Shell_NotifyIcon(NIM_SETVERSION, &tnid);#endif	    tnid.cbSize = sizeof(NOTIFYICONDATA);	    tnid.hWnd = hwnd;	    tnid.uID = 1;                  /* unique within this systray use */	    tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;	    tnid.uCallbackMessage = WM_SYSTRAY;	    tnid.hIcon = hicon = LoadIcon (instance, MAKEINTRESOURCE(201));	    strcpy(tnid.szTip, "Pageant (PuTTY authentication agent)");	    res = Shell_NotifyIcon(NIM_ADD, &tnid);	    if (hicon)		DestroyIcon(hicon);	    systray_menu = CreatePopupMenu();	    /* accelerators used: vkxa */	    AppendMenu (systray_menu, MF_ENABLED, IDM_VIEWKEYS, "&View Keys");	    AppendMenu (systray_menu, MF_ENABLED, IDM_ADDKEY, "Add &Key");	    AppendMenu (systray_menu, MF_ENABLED, IDM_ABOUT, "&About");	    AppendMenu (systray_menu, MF_ENABLED, IDM_CLOSE, "E&xit");	}	ShowWindow (hwnd, SW_HIDE);	/*	 * Initialise storage for RSA keys.	 */	rsakeys = newtree234(cmpkeys_rsa);	ssh2keys = newtree234(cmpkeys_ssh2);    }    /*     * Process the command line and add keys as listed on it.     * If we already determined that we need to spawn a program from above we     * need to ignore the first two arguments. [DBW]     */    {        char *p;        int inquotes = 0;        int ignorearg = 0;        p = cmdline;        while (*p) {            while (*p && isspace(*p)) p++;            if (*p && !isspace(*p)) {                char *q = p, *pp = p;                while (*p && (inquotes || !isspace(*p)))                {                    if (*p == '"') {                        inquotes = !inquotes;                        p++;                        continue;                    }                    *pp++ = *p++;                }                if (*pp) {                    if (*p) p++;                    *pp++ = '\0';                }		if (!strcmp(q, "-c")) {		    /*		     * If we see `-c', then the rest of the		     * command line should be treated as a		     * command to be spawned.		     */		    while (*p && isspace(*p)) p++;		    command = p;		    break;		} else {		    add_keyfile(q);		    added_keys = TRUE;		}            }        }    }    if (command) spawn_cmd (command, show);    /*     * If Pageant was already running, we leave now. If we haven't     * even taken any auxiliary action (spawned a command or added     * keys), complain.     */    if (already_running) {	if (!command && !added_keys) {	    MessageBox(NULL, "Pageant is already running", "Pageant Error",		       MB_ICONERROR | MB_OK);	}        if (advapi) FreeLibrary(advapi);        return 0;    }    /*     * Main message loop.     */    while (GetMessage(&msg, NULL, 0, 0) == 1) {        TranslateMessage(&msg);        DispatchMessage(&msg);    }    /* Clean up the system tray icon */    {        NOTIFYICONDATA tnid;        tnid.cbSize = sizeof(NOTIFYICONDATA);         tnid.hWnd = hwnd;        tnid.uID = 1;        Shell_NotifyIcon(NIM_DELETE, &tnid);         DestroyMenu(systray_menu);    }    if (advapi) FreeLibrary(advapi);    exit(msg.wParam);}