Changeset 105432 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Jul 22, 2024 6:04:56 PM (7 months ago)
- svn:sync-xref-src-repo-rev:
- 164089
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSessionTracking.cpp
r98103 r105432 71 71 gVBoxSt.fIsConsole = (*pProtocolType == 0); 72 72 gVBoxSt.enmConnectState = *penmConnectState; 73 LogFlowFunc(("Session information: ProtocolType %d, ConnectState %d", *pProtocolType, *penmConnectState)); 73 74 return VINF_SUCCESS; 74 75 } 75 76 else 77 { 78 DWORD dwErr = GetLastError(); 79 LogWarnFunc(("WTSQuerySessionInformationA WTSClientProtocolType failed, error = %08X\n", dwErr)); 80 rc = RTErrConvertFromWin32(dwErr); 81 } 82 } 83 else 84 { 76 85 DWORD dwErr = GetLastError(); 77 LogFlowFunc(("WTSQuerySessionInformationA WTSClientProtocolType failed, error = %08X\n", dwErr)); 78 rc = RTErrConvertFromWin32(dwErr); 79 } 80 else 81 { 82 DWORD dwErr = GetLastError(); 83 LogFlowFunc(("WTSQuerySessionInformationA WTSConnectState failed, error = %08X\n", dwErr)); 86 LogWarnFunc(("WTSQuerySessionInformationA WTSConnectState failed, error = %08X\n", dwErr)); 84 87 rc = RTErrConvertFromWin32(dwErr); 85 88 } … … 95 98 { 96 99 RT_ZERO(gVBoxSt); 97 int rc = RTLdrLoadSystem("WTSAPI32.DLL", false /*fNoUnload*/, &gVBoxSt.hLdrModWTSAPI32); 100 int rc = RTLdrLoadSystem("WTSAPI32.DLL", true /*fNoUnload*/, &gVBoxSt.hLdrModWTSAPI32); 101 98 102 if (RT_SUCCESS(rc)) 99 103 { … … 101 105 (void **)&gVBoxSt.pfnWTSRegisterSessionNotification); 102 106 if (RT_SUCCESS(rc)) 103 {104 107 rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSUnRegisterSessionNotification", 105 (void **)&gVBoxSt.pfnWTSUnRegisterSessionNotification); 106 if (RT_SUCCESS(rc)) 108 (void **)&gVBoxSt.pfnWTSUnRegisterSessionNotification); 109 if (RT_SUCCESS(rc)) 110 rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSQuerySessionInformationA", 111 (void **)&gVBoxSt.pfnWTSQuerySessionInformationA); 112 113 AssertRC(rc); 114 RTLdrClose(gVBoxSt.hLdrModWTSAPI32); 115 } 116 117 if (RT_SUCCESS(rc)) 118 { 119 gVBoxSt.hWTSAPIWnd = hWnd; 120 if (gVBoxSt.pfnWTSRegisterSessionNotification(gVBoxSt.hWTSAPIWnd, NOTIFY_FOR_THIS_SESSION)) 121 { 122 LogFunc(("hWnd(%p) registered for WTS session changes\n", gVBoxSt.hWTSAPIWnd)); 123 vboxStCheckState(); 124 } 125 else 126 { 127 DWORD dwErr = GetLastError(); 128 LogRel(("WTSRegisterSessionNotification failed, error = %08X\n", dwErr)); 129 if (dwErr == RPC_S_INVALID_BINDING) 107 130 { 108 rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSQuerySessionInformationA", 109 (void **)&gVBoxSt.pfnWTSQuerySessionInformationA); 110 if (RT_FAILURE(rc)) 111 LogFlowFunc(("WTSQuerySessionInformationA not found\n")); 131 gVBoxSt.idDelayedInitTimer = SetTimer(gVBoxSt.hWTSAPIWnd, TIMERID_VBOXTRAY_ST_DELAYED_INIT_TIMER, 132 2000, (TIMERPROC)NULL); 133 gVBoxSt.fIsConsole = TRUE; 134 gVBoxSt.enmConnectState = WTSActive; 135 rc = VINF_SUCCESS; 112 136 } 113 137 else 114 LogFlowFunc(("WTSUnRegisterSessionNotification not found\n")); 115 } 116 else 117 LogFlowFunc(("WTSRegisterSessionNotification not found\n")); 138 rc = RTErrConvertFromWin32(dwErr); 139 } 140 118 141 if (RT_SUCCESS(rc)) 119 { 120 gVBoxSt.hWTSAPIWnd = hWnd; 121 if (gVBoxSt.pfnWTSRegisterSessionNotification(gVBoxSt.hWTSAPIWnd, NOTIFY_FOR_THIS_SESSION)) 122 vboxStCheckState(); 123 else 124 { 125 DWORD dwErr = GetLastError(); 126 LogFlowFunc(("WTSRegisterSessionNotification failed, error = %08X\n", dwErr)); 127 if (dwErr == RPC_S_INVALID_BINDING) 128 { 129 gVBoxSt.idDelayedInitTimer = SetTimer(gVBoxSt.hWTSAPIWnd, TIMERID_VBOXTRAY_ST_DELAYED_INIT_TIMER, 130 2000, (TIMERPROC)NULL); 131 gVBoxSt.fIsConsole = TRUE; 132 gVBoxSt.enmConnectState = WTSActive; 133 rc = VINF_SUCCESS; 134 } 135 else 136 rc = RTErrConvertFromWin32(dwErr); 137 } 138 139 if (RT_SUCCESS(rc)) 140 return VINF_SUCCESS; 141 } 142 143 RTLdrClose(gVBoxSt.hLdrModWTSAPI32); 144 } 145 else 146 LogFlowFunc(("WTSAPI32 load failed, rc = %Rrc\n", rc)); 142 return VINF_SUCCESS; 143 } 144 else 145 { 146 LogRel(("WtsApi32.dll APIs are not available (%Rrc)\n", rc)); 147 gVBoxSt.pfnWTSRegisterSessionNotification = NULL; 148 gVBoxSt.pfnWTSUnRegisterSessionNotification = NULL; 149 gVBoxSt.pfnWTSQuerySessionInformationA = NULL; 150 } 147 151 148 152 RT_ZERO(gVBoxSt); … … 154 158 void vboxStTerm(void) 155 159 { 156 if (!gVBoxSt.hWTSAPIWnd) 157 { 158 LogFlowFunc(("vboxStTerm called for non-initialized St\n")); 159 return; 160 } 160 AssertReturnVoid(gVBoxSt.hWTSAPIWnd); 161 161 162 162 if (gVBoxSt.idDelayedInitTimer) … … 170 170 if (!gVBoxSt.pfnWTSUnRegisterSessionNotification(gVBoxSt.hWTSAPIWnd)) 171 171 { 172 LogFlowFunc(("WTSAPI32 load failed, error = %08X\n", GetLastError())); 173 } 174 } 175 176 RTLdrClose(gVBoxSt.hLdrModWTSAPI32); 172 LogWarnFunc(("WTSAPI32 unload failed, error = %08X\n", GetLastError())); 173 } 174 } 175 177 176 RT_ZERO(gVBoxSt); 178 177 } 179 178 180 #define VBOXST_DBG_MAKECASE(_val) case _val: return #_val;181 182 179 static const char* vboxStDbgGetString(DWORD val) 183 180 { 184 181 switch (val) 185 182 { 186 VBOXST_DBG_MAKECASE(WTS_CONSOLE_CONNECT);187 VBOXST_DBG_MAKECASE(WTS_CONSOLE_DISCONNECT);188 VBOXST_DBG_MAKECASE(WTS_REMOTE_CONNECT);189 VBOXST_DBG_MAKECASE(WTS_REMOTE_DISCONNECT);190 VBOXST_DBG_MAKECASE(WTS_SESSION_LOGON);191 VBOXST_DBG_MAKECASE(WTS_SESSION_LOGOFF);192 VBOXST_DBG_MAKECASE(WTS_SESSION_LOCK);193 VBOXST_DBG_MAKECASE(WTS_SESSION_UNLOCK);194 VBOXST_DBG_MAKECASE(WTS_SESSION_REMOTE_CONTROL);183 RT_CASE_RET_STR(WTS_CONSOLE_CONNECT); 184 RT_CASE_RET_STR(WTS_CONSOLE_DISCONNECT); 185 RT_CASE_RET_STR(WTS_REMOTE_CONNECT); 186 RT_CASE_RET_STR(WTS_REMOTE_DISCONNECT); 187 RT_CASE_RET_STR(WTS_SESSION_LOGON); 188 RT_CASE_RET_STR(WTS_SESSION_LOGOFF); 189 RT_CASE_RET_STR(WTS_SESSION_LOCK); 190 RT_CASE_RET_STR(WTS_SESSION_UNLOCK); 191 RT_CASE_RET_STR(WTS_SESSION_REMOTE_CONTROL); 195 192 default: 196 Log FlowFunc(("invalid WTS state %d\n", val));193 LogWarnFunc(("invalid WTS state %d\n", val)); 197 194 return "Unknown"; 198 195 } … … 212 209 else 213 210 { 214 Log FlowFunc(("timer WTSRegisterSessionNotification failed, error = %08X\n", GetLastError()));211 LogWarnFunc(("timer WTSRegisterSessionNotification failed, error = %08X\n", GetLastError())); 215 212 Assert(gVBoxSt.fIsConsole == TRUE); 216 213 Assert(gVBoxSt.enmConnectState == WTSActive); … … 228 225 { 229 226 RT_NOREF(wEvent); 230 LogF lowFunc(("WTS Event: %s\n", vboxStDbgGetString(wEvent)));227 LogFunc(("WTS Event: %s\n", vboxStDbgGetString(wEvent))); 231 228 BOOL fOldIsActiveConsole = vboxStIsActiveConsole(); 232 229
Note:
See TracChangeset
for help on using the changeset viewer.