Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Rcontrol.cpp
  5. Abstract:
  6. This is the entry of our Remote Assistance DirectPlay application.
  7. Author:
  8. steveshi 10/1/2000
  9. --*/
  10. #include "atlbase.h"
  11. extern CComModule _Module;
  12. #include "atlcom.h"
  13. #include "stdafx.h"
  14. #include "resource.h"
  15. #include "sessions.h"
  16. #include "utils.h"
  17. #include "rcontrol.h"
  18. #include "rcbdyctl.h"
  19. #include "rcbdyctl_i.c"
  20. //#include "imsession.h"
  21. #include "Shared.h"
  22. #include "sessions_i.c"
  23. //#include "sessions_i.c"
  24. TCHAR c_szHttpPath[] = _T("http://www.microsoft.com");
  25. CComModule _Module;
  26. HWND g_hWnd = NULL;
  27. BEGIN_OBJECT_MAP(ObjectMap)
  28. END_OBJECT_MAP()
  29. INT WINAPI
  30. WinMain(HINSTANCE hInstance,
  31. HINSTANCE hPrevInstance,
  32. LPSTR lpCmdLine,
  33. INT nShowCmd)
  34. {
  35. HRESULT hr;
  36. DWORD dwID;
  37. BOOL bIsInviter = FALSE;
  38. IIMSession* pIMSession = NULL;
  39. CoInitialize(NULL);
  40. _Module.Init(NULL, hInstance);
  41. for (LPSTR lpszToken=lpCmdLine; lpszToken && *lpszToken !='\0' && *lpszToken != '-'; lpszToken++) ;
  42. if (lpszToken && *lpszToken == '-')
  43. {
  44. if (_stricmp(++lpszToken, "UnregServer")==0)
  45. {
  46. RegisterEXE(FALSE);
  47. }
  48. else if (_stricmp(lpszToken, "RegServer")==0)
  49. {
  50. RegisterEXE(TRUE);
  51. }
  52. else if (_stricmp(lpszToken, "LaunchRA")==0)
  53. {
  54. TCHAR szCommandLine[2000];
  55. TCHAR szHscPath[] = _T("\\pchealth\\helpctr\\binaries\\helpctr.exe\" -FromStartHelp -url \"hcp://services/centers/support?topic=hcp://CN=Microsoft Corporation,L=Redmond,S=Washington,C=US/Remote Assistance/Escalation/Common/rcscreen1.htm\"");
  56. PROCESS_INFORMATION ProcessInfo;
  57. STARTUPINFO StartUpInfo;
  58. TCHAR szWinDir[2048];
  59. int iLen = 0;
  60. iLen = GetWindowsDirectory(szWinDir, 2048);
  61. if (iLen == 0)
  62. goto done;
  63. ZeroMemory((LPVOID)&StartUpInfo, sizeof(STARTUPINFO));
  64. StartUpInfo.cb = sizeof(STARTUPINFO);
  65. if ((iLen + _tcslen(szHscPath)) >= 1999) // buffer overrun
  66. goto done;
  67. wsprintf(szCommandLine, _T("\"%s%s"), szWinDir, szHscPath);
  68. CreateProcess(NULL, szCommandLine,NULL,NULL,TRUE,CREATE_NEW_PROCESS_GROUP,NULL,&szWinDir[0],&StartUpInfo,&ProcessInfo);
  69. }
  70. else
  71. {
  72. // Wrong parameter. Do nothing.
  73. }
  74. goto done;
  75. }
  76. // OK, it's not Reg/UnRegserver. Lets run it.
  77. hr = ::CoCreateInstance(CLSID_IMSession, NULL, CLSCTX_INPROC_SERVER,
  78. IID_IIMSession, (LPVOID*)&pIMSession);
  79. if (FAILED_HR(TEXT("CoCreate IMSession failed %s"), hr))
  80. goto done;
  81. dwID = GetCurrentProcessId();
  82. hr = pIMSession->GetLaunchingSession(dwID);
  83. if (FAILED_HR(TEXT("GetLaunchingSession failed: %s"), hr))
  84. goto done;
  85. hr = pIMSession->get_IsInviter(&bIsInviter);
  86. if (FAILED_HR(TEXT("Session Get flags failed: %s"), hr))
  87. goto done;
  88. if (bIsInviter) // Inviter. Only happened when Messenger UI sends this invitation.
  89. {
  90. MSG msg;
  91. InitInstance(hInstance, 0);
  92. if (FAILED(hr = pIMSession->Hook(NULL, g_hWnd)))
  93. goto done;
  94. #define RA_TIMEOUT 300*1000 // 5 minutes
  95. SetTimer(g_hWnd, TIMER_TIMEOUT, RA_TIMEOUT, NULL);
  96. // Goto msg pump
  97. while (GetMessage(&msg, NULL, 0, 0))
  98. {
  99. TranslateMessage(&msg);
  100. DispatchMessage(&msg);
  101. }
  102. }
  103. else // Invitee: should be handled inside HelpCtr.
  104. {
  105. pIMSession->Release(); // since I don't need it.
  106. pIMSession = NULL;
  107. // 1. Create HelpCtr and pass it my process ID.
  108. TCHAR szCommandLine[2000];
  109. TCHAR szPath[] = _T("/Interaction/Client/rctoolScreen1.htm\" -ExtraArgument \"IM=");
  110. PROCESS_INFORMATION ProcessInfo;
  111. STARTUPINFO StartUpInfo;
  112. TCHAR szWinDir[2048];
  113. int iLen;
  114. iLen = GetWindowsDirectory(szWinDir, 2048);
  115. if (iLen == 0)
  116. goto done;
  117. ZeroMemory((LPVOID)&StartUpInfo, sizeof(STARTUPINFO));
  118. StartUpInfo.cb = sizeof(STARTUPINFO);
  119. if ((iLen + _tcslen(szWinDir) + _tcslen(CHANNEL_PATH) + 10) >= 1998) // Buffer overrun. Note: 10: assume dwID < 10 digits.
  120. goto done;
  121. wsprintf(szCommandLine, _T("\"%s%s%s%d\""), szWinDir,CHANNEL_PATH, szPath, dwID);
  122. CreateProcess(NULL, szCommandLine,NULL,NULL,TRUE,CREATE_NEW_PROCESS_GROUP,NULL,&szWinDir[0],&StartUpInfo,&ProcessInfo);
  123. //#define SLEEP_TIME 60 * 1000 // 60 seconds
  124. // Sleep(SLEEP_TIME);
  125. }
  126. done:
  127. if (pIMSession)
  128. pIMSession->Release();
  129. _Module.Term();
  130. CoUninitialize();
  131. return 0;
  132. }
  133. //////////////////////////////////////////////////////////////////////////////////////////////
  134. // The Inviter World: Only get called when Messenger UI starts this invitation.
  135. /////////////////////////////////////////////////////////////////////////////////////////////
  136. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  137. {
  138. HWND hWnd;
  139. WNDCLASSEX wcex;
  140. wcex.cbSize = sizeof(WNDCLASSEX);
  141. wcex.style = CS_HREDRAW | CS_VREDRAW;
  142. wcex.lpfnWndProc = WndProc;
  143. wcex.cbClsExtra = 0;
  144. wcex.cbWndExtra = 0;
  145. wcex.hInstance = hInstance;
  146. wcex.hIcon = NULL; //LoadIcon(hInstance, (LPCTSTR)IDI_MARBLE);
  147. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  148. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  149. wcex.lpszMenuName = NULL; //(LPCSTR)IDC_MARBLE;
  150. wcex.lpszClassName = szWindowClass;
  151. wcex.hIconSm = NULL; //LoadIcon(wcex.hInstance, (LPCTSTR)IDI_MARBLE);
  152. RegisterClassEx(&wcex);
  153. hWnd = CreateWindow(szWindowClass, TEXT("Remote Assistance"), WS_OVERLAPPEDWINDOW,
  154. CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, hInstance, NULL);
  155. if (!hWnd)
  156. {
  157. return FALSE;
  158. }
  159. g_hWnd = hWnd; // Save the window handle
  160. #ifdef DEBUG // Maybe it's useful for debug build.
  161. //ShowWindow(hWnd, nCmdShow);
  162. //UpdateWindow(hWnd);
  163. #endif
  164. return TRUE;
  165. }
  166. void RegisterEXE(BOOL bRegister)
  167. {
  168. CComBSTR bstrRAName;
  169. HKEY hKey = NULL;
  170. TCHAR szPath[MAX_PATH];
  171. #define REG_KEY_SESSMGR_RA _T("SOFTWARE\\Microsoft\\MessengerService\\SessionManager\\Apps\\") C_RA_APPID
  172. //{56b994a7-380f-410b-9985-c809d78c1bdc}]
  173. bstrRAName.LoadString(IDS_RA_NAME);
  174. if (bRegister)
  175. {
  176. // Fix for Bug 617011 : Prefast bug
  177. GetModuleFileName(NULL, szPath, MAX_PATH-1);
  178. szPath[MAX_PATH -1] = 0;
  179. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, REG_KEY_SESSMGR_RA, 0, NULL,
  180. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL))
  181. {
  182. RegSetValueExW(hKey, L"Name", 0, REG_SZ, (LPBYTE)((BSTR)bstrRAName), bstrRAName.Length()*sizeof(WCHAR));
  183. RegSetValueEx(hKey, _T("URL"), 0, REG_SZ, (LPBYTE)c_szHttpPath, _tcslen(c_szHttpPath)*sizeof(TCHAR));
  184. RegSetValueEx(hKey, _T("Path"), 0, REG_SZ, (LPBYTE)szPath, _tcslen(szPath)*sizeof(TCHAR));
  185. }
  186. RegCloseKey(hKey);
  187. // Need to clean up some leftover from Beta2, if it's still there.
  188. SHDeleteKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\MicroSoft\\DirectPlay\\Applications\\Remote Assistance"));
  189. }
  190. else
  191. {
  192. RegDeleteKey(HKEY_LOCAL_MACHINE, REG_KEY_SESSMGR_RA);
  193. }
  194. return;
  195. }
  196. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  197. {
  198. int wmId, wmEvent;
  199. switch (message)
  200. {
  201. case WM_CREATE:
  202. {
  203. }
  204. break;
  205. case WM_DESTROY:
  206. {
  207. PostQuitMessage(0);
  208. }
  209. break;
  210. case WM_TIMER:
  211. {
  212. if (wParam == TIMER_TIMEOUT)
  213. {
  214. DestroyWindow(g_hWnd);
  215. PostQuitMessage(0);
  216. }
  217. }
  218. break;
  219. default:
  220. return DefWindowProc(hWnd, message, wParam, lParam);
  221. }
  222. return 0;
  223. }