Вот тут я нашел прогу, которая запускает аутлук, вводит в него пароль, и нажимает кнопку OK. Пароль запоминается в файлике на диске, это не совсем хорошо с точки зрения безопасности, но мне на это наплевать.
Я немножко модифицировал код, теперь программа спрашивает и запоминает еще и логин - для тех случаев, когда exchange-овский логин отличается от системного, как у меня.
Исходник
- /*
- // outlook_login.cpp
- // Works with MS Outlook 2003, can be used as template for automatical entering data to other programs.
- // On first run, program asks for login/password, storing it in the file "outlook_login.ini".
- // On next runs, program takes stored info and enter into login window.
- // To change login and password, just delete "outlook_login.ini".
- // This is modified version of code, written by Gabriele: http://www.mondada.net/gabriele/autologin/
- // Now the program is asking for login as well, and storing it in the file.
- */
- //#pragma resource "outlook_login.res" // Just an icon there
- #include <windows.h>
- #include <stdio.h>
- /*** global vars ***/
- unsigned long int process_id = 0;
- HWND login_win = 0;
- /*** functions ***/
- static int CALLBACK _enum_windows_proc(HWND hwnd, LPARAM lParam)
- {
- char title[256];
- unsigned long int h;
- int style, match;
- // get window title and properties
- title[0] = 0;
- GetWindowText(hwnd, title, 256);
- GetWindowThreadProcessId(hwnd, &h);
- style = GetWindowLong(hwnd, GWL_STYLE);
- // check if it's the login window - method 1
- match = (process_id != 0) && (h == process_id) && (style & WS_VISIBLE) && (style & DS_SETFOREGROUND) && (style & WS_DLGFRAME) && (strlen(title) > 10);
- if (match) {
- login_win = hwnd;
- printf("login window found (method 1): 0x%08X\n", hwnd);
- }
- // check if it's the login window - method 2
- if (!strncmp(title, "Connect to ", 11)) {
- login_win = hwnd;
- printf("login window found (method 2en): 0x%08X\n", hwnd);
- }
- return 1;
- }
- void send_str(HWND hwnd, char *s)
- {
- for (int i=0; i<(int)strlen(s); i++)
- SendMessage(hwnd, WM_CHAR, s[i], 0x40001);
- }
- int autologin(char * login,char * passw)
- {
- HWND hwnd;
- // Search Outlook window (not displayed)
- hwnd = FindWindow(NULL, "Microsoft Outlook");
- // Get process id
- process_id = 0;
- if (hwnd != 0)
- GetWindowThreadProcessId(hwnd, &process_id);
- printf("outlook wnd = %X, process id = %X\n", hwnd, process_id);
- // search login window
- login_win = 0;
- EnumWindows((WNDENUMPROC)_enum_windows_proc, 0);
- if (login_win == 0)return 0;
- hwnd = FindWindowEx(login_win, 0, "SysCredential", NULL);
- if (hwnd == 0)return 0;
- hwnd = FindWindowEx(hwnd, 0, "Edit", NULL);
- if (hwnd == 0)return 0;
- // sending password
- send_str(hwnd, passw);
- hwnd = FindWindowEx(login_win, 0, "SysCredential", NULL);
- if (hwnd == 0)return 0;
- hwnd = FindWindowEx(hwnd, 0, "ComboBoxEx32", NULL);
- if (hwnd == 0)return 0;
- hwnd = FindWindowEx(hwnd, 0, "ComboBox", NULL);
- if (hwnd == 0)return 0;
- hwnd = FindWindowEx(hwnd, 0, "Edit", NULL);
- if (hwnd == 0)return 0;
- // sending login
- send_str(hwnd, login);
- hwnd = FindWindowEx(login_win, 0, "Button", "OK");
- if (hwnd == 0)return 0;
- SendMessage(hwnd, WM_LBUTTONDOWN, 1, 0x00010001); // press down mouse button at location 1,1
- SendMessage(hwnd, WM_LBUTTONUP, 0, 0x00010001); // release mouse button at location 1,1
- return 1;
- }
- int main(int argc, char *argv[])
- {
- char fname[] = "outlook_login.ini",login[256],passw[256];
- FILE * f = fopen(fname,"rt");
- if(!f)
- {
- printf("Warning! Login and passwords will be stored unsecured, in file %s. ",fname);
- printf("If you want to change login and password, just delete file %s.\r\n",fname);
- printf("\r\nEnter login :");
- gets(login);
- printf("Enter password:");
- gets(passw);
- FILE * f = fopen(fname,"wt");
- if(f)
- fprintf(f,"%s\n%s",login,passw);
- }
- else
- {
- fgets(login,255,f);
- fgets(passw,255,f);
- }
- if(f)
- fclose(f);
- // start outlook
- int i = (int)ShellExecute(0, "open", "outlook", NULL, NULL, SW_SHOWDEFAULT);
- printf("Shell ret = %d\n", i);
- // autologin
- for (i=0; i<60; i++)
- {
- Sleep(1000);
- if(autologin(login,passw))
- break;
- }
- return 0;
- }
Скомпилировать можно бесплатным Борландовским компилятором, также я могу выслать exe-шник на почту - у меня сейчас нет хостинга, где можно бы было выложить exe-шник.
Прога работает так:
1. При первом запуске спрашивает логин и пароль, запоминает их в файле outlook_login.ini.
2. При последующих запусках читает их из файла, автоматически запускает аутлук, сама вводит логин и пароль, нажимает ОК.
3. Если хотите изменить логин и пароль - либо отредактируйте файл outlook_login.ini в текстовом редакторе, либо вообще удалите его.
Этот исходник хорош тем, что его можно использовать как образец для других программ, где после запуска надо вводить логин и пароль.
Чтобы гугль нашел этот пост: microsoft outlook 2003 save credentials, ms outlook autologin, ms outlook automatic login, ms outlook remember login and password, ms outlook store username and password, ms outlook automatic enter login and password, запоминание пароля в ms outlook 2003, автоматическое сохранение пароля в microsoft outlook.
No comments:
Post a Comment