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.

139 lines
5.2 KiB

  1. // ----------------------------------------------------------------------------
  2. //
  3. // _UMClnt.h
  4. //
  5. // Client definition for Utility Manager
  6. //
  7. // Author: J. Eckhardt, ECO Kommunikation
  8. // (c) 1997-99 Microsoft
  9. //
  10. // History: created oct-98 by JE
  11. // JE nov-15-98: removed any code related to key hook
  12. // JE nov-15-98: changed UMDialog message to be a service control message
  13. // JE nov-15 98: changed "umc_machine_ts" to save memory
  14. // JE nov-15 98: changed "umc_machine_ts" to support launch specific client
  15. // JE nov-15 98: changed "umclient_ts" for multiple instances support
  16. // YX jun-01 99: added DisplayName member to the umc_machine_ts
  17. // YX jun-23 99: added IsAdmin function
  18. // ----------------------------------------------------------------------------
  19. #ifndef __UMCLNT_H_
  20. #define __UMCLNT_H_
  21. #include "UtilMan.h"
  22. // ---------------------------------
  23. // HKLM\Software\Microsoft\Windows NT\CurrentVersion\Accessibility\Utility Manager\[Application Name]
  24. // ---------------------------------
  25. #define ACC_KEY_NONE -1
  26. typedef struct
  27. {
  28. WCHAR ApplicationName[MAX_APPLICATION_NAME_LEN];
  29. WCHAR DisplayName[MAX_APPLICATION_NAME_LEN]; // YX: added for localization purposes
  30. DWORD ApplicationType;//APPLICATION_TYPE_xxx
  31. DWORD WontRespondTimeout;//NO_WONTRESPONDTIMEOUT or up to MAX_WONTRESPONDTIMEOUT (sec)
  32. DWORD MaxRunCount;// instances (only a byte in registry)
  33. DWORD ClientControlCode;//JE nov-15 98
  34. WPARAM AcceleratorKey; // micw - the accelerator key for this applet
  35. } umc_machine_ts,*umc_machine_tsp;
  36. // ---------------------------------
  37. // HKCU\Software\Microsoft\Windows NT\CurrentVersion\Accessibility\Utility Manager\[Application Name]
  38. typedef struct
  39. {
  40. BOOL fCanRunSecure;
  41. BOOL fStartWithUtilityManager;
  42. BOOL fStartAtLogon;
  43. BOOL fStartOnLockDesktop;
  44. BOOL fRestartOnDefaultDesk;
  45. } umc_user_ts, *umc_user_tsp;
  46. // ---------------------------------
  47. // internal client struct (for each instance)
  48. #define UM_CLIENT_NOT_RUNNING 0
  49. #define UM_CLIENT_RUNNING 1
  50. #define UM_CLIENT_NOT_RESPONDING 2
  51. typedef struct
  52. {
  53. umc_machine_ts machine;
  54. umc_user_ts user;
  55. DWORD runCount;// number of instance
  56. DWORD state;
  57. DWORD processID[MAX_APP_RUNCOUNT];
  58. HANDLE hProcess[MAX_APP_RUNCOUNT];
  59. DWORD mainThreadID[MAX_APP_RUNCOUNT];
  60. DWORD lastResponseTime[MAX_APP_RUNCOUNT];
  61. } umclient_ts, *umclient_tsp;
  62. // ---------------------------------
  63. // header structure
  64. #define START_BY_OTHER 0x0
  65. #define START_BY_HOTKEY 0x1
  66. #define START_BY_MENU 0x2
  67. #define MAX_NUMBER_OF_CLIENTS 16
  68. typedef struct
  69. {
  70. DWORD numberOfClients; // number of applets being managed
  71. DWORD dwStartMode; // one of START_BY_HOTKEY, START_BY_MENU, or START_BY_OTHER
  72. BOOL fShowWarningAgain; // flag for showing warning dlg when started via Start menu
  73. } umc_header_ts, *umc_header_tsp;
  74. // ---------------------------------
  75. // memory mapped files
  76. #define UMC_HEADER_FILE _TEXT("UtilityManagerClientHeaderFile")
  77. // sizeof(umc_header_ts)
  78. #define UMC_CLIENT_FILE _TEXT("UtilityManagerClientDataFile")
  79. // sizeof(umclient_ts) * (umc_header_tsp)->numberOfClients
  80. // ---------------------------------
  81. #ifdef __cplusplus
  82. extern "C" {
  83. #endif
  84. BOOL StartClient(HWND hParent,umclient_tsp client);
  85. BOOL StopClient(umclient_tsp client);
  86. BOOL StartApplication(LPTSTR pszPath, LPTSTR pszArg, BOOL fIsTrusted,
  87. DWORD *pdwProcessId, HANDLE *phProcess, DWORD *pdwThreadId);
  88. BOOL GetClientApplicationPath(LPTSTR ApplicationName, LPTSTR ApplicationPath,DWORD len);
  89. BOOL CheckStatus(umclient_tsp c, DWORD cClients);
  90. BOOL IsAdmin();
  91. BOOL IsInteractiveUser();
  92. BOOL IsSystem();
  93. HANDLE GetUserAccessToken(BOOL fNeedImpersonationToken, BOOL *fError);
  94. BOOL TestServiceClientRuns(umclient_tsp client,SERVICE_STATUS *ssStatus);
  95. // Helpers to start up the utilman instance that displays UI
  96. extern HANDLE g_hUIProcess;
  97. __inline void OpenUManDialogOutOfProc()
  98. {
  99. TCHAR szUtilmanPath[_MAX_PATH+64] = {0};
  100. if (GetModuleFileName(NULL, szUtilmanPath, _MAX_PATH+64))
  101. {
  102. // This function is called (when there is an interactive user) to bring up
  103. // the utilman UI in the user's security context. This avoids the problem
  104. // where a non-trusted application could send a message to utilman and cause
  105. // some process to start as SYSTEM. In this context, utilman is not considered
  106. // trusted; it must start as the interactive user or not at all.
  107. StartApplication(szUtilmanPath, TEXT("/start"), FALSE, NULL, &g_hUIProcess, NULL);
  108. }
  109. }
  110. __inline HANDLE GetUIUtilman()
  111. {
  112. return g_hUIProcess;
  113. }
  114. __inline BOOL ResetUIUtilman()
  115. {
  116. // This process detected the switch and should quit on its own
  117. if (g_hUIProcess)
  118. {
  119. CloseHandle(g_hUIProcess);
  120. g_hUIProcess = 0;
  121. return TRUE;
  122. }
  123. return FALSE;
  124. }
  125. __inline void SetUIUtilman(HANDLE hProcess)
  126. {
  127. ResetUIUtilman();
  128. g_hUIProcess = hProcess;
  129. }
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif __UMCLNT_H_