| Classic Shell http://www.classicshell.net/forum/ |
|
| Remote session graceful disconnect before suspend/shutdown http://www.classicshell.net/forum/viewtopic.php?f=13&t=1252 |
Page 1 of 1 |
| Author: | dfdf [ Sat Sep 14, 2013 11:44 am ] |
| Post subject: | Remote session graceful disconnect before suspend/shutdown |
Hello, i'm using CS for long ago, and this is amazing product. I have a suggestion to add a graceful remote session disconnect before doing suspend/shutdown/hibernate the machine if it's initiated from remote session. This prevents from long waiting/force disconnection when PC is controlled over RDP. Unfortunately, i was not able to download beta sources, just stable one, but i suppose it's not hard to understand what i mean. here is the code (pretty simple): this goes to ClassicStartMenuDLL\MenuCommands.cpp: Code: #define _freeWTS(x) (((x) ? WTSFreeMemory(x):TRUE), (x)=NULL, TRUE)
USHORT getSessionProto() { LPVOID wtsProto=NULL; DWORD wtsInfoSize; USHORT res=USHRT_MAX; if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientProtocolType, (LPTSTR *)&wtsProto, &wtsInfoSize)) res=*(PUSHORT)wtsProto; _freeWTS(wtsProto); return res; } BOOL isConsoleSession() { DWORD id1, id2; USHORT proto; proto=getSessionProto(); if (proto!=USHRT_MAX) return (proto==0); if ((id1=getSessionId())!=ULONG_MAX && (id2=WTSGetActiveConsoleSessionId())!=ULONG_MAX) return (id1==id2); return FALSE; } static DWORD WINAPI SleepThread(LPVOID state) { static LONG inThread=FALSE; if (!InterlockedCompareExchange(&inThread, TRUE, FALSE)) { Sleep(250); if (!isConsoleSession()) { WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, TRUE); Sleep(250); } SetSuspendState((state ? TRUE:FALSE), FALSE, FALSE); InterlockedExchange(&inThread, FALSE); } return 0; } |
|
| Author: | Ivo [ Sat Sep 14, 2013 11:59 am ] |
| Post subject: | Re: Remote session graceful disconnect before suspend/shutdo |
Probably a much simpler solution is: Code: case MENU_SLEEP: if (GetSystemMetrics(SM_REMOTESESSION)) { WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE,WTS_CURRENT_SESSION,FALSE); Sleep(250); } CreateThread(NULL,0,SleepThread,(void*)FALSE,0,NULL); break; Not sure if it is a good idea though. What if the sleep or shutdown fails for some reason? You'll be disconnected and never know. |
|
| Author: | dfdf [ Sat Sep 14, 2013 12:09 pm ] |
| Post subject: | Re: Remote session graceful disconnect before suspend/shutdo |
Ivo wrote: Probably a much simpler solution is: Code: (GetSystemMetrics(SM_REMOTESESSION)) Not sure if it is a good idea though. What if the sleep or shutdown fails for some reason? You'll be disconnected and never know. GetSystemMetrics(SM_REMOTESESSION) fails if session was initially console and later switched to rdp (but this may happen on XP, not W7 and should be checked - as I remember there was a reason for me to disregard GetSystemMetrics...) Yes, if sleep or shutdown fails you wouldn't know, but we can rewrite in this way (SetSuspendState is async): Code: if (SetSuspendState()) WTSDisconnectSession(); IMHO, it's better than freezing remote session silently due to suspend. |
|
| Author: | Ivo [ Sat Sep 14, 2013 1:14 pm ] |
| Post subject: | Re: Remote session graceful disconnect before suspend/shutdo |
OK, the next version 3.9.5 will try to disconnect before sleep/hibernate. It will most likely be released tomorrow. |
|
| Author: | dfdf [ Sat Sep 14, 2013 1:53 pm ] |
| Post subject: | Re: Remote session graceful disconnect before suspend/shutdo |
Ivo wrote: OK, the next version 3.9.5 will try to disconnect before sleep/hibernate. It will most likely be released tomorrow. Cool! But forget to mention/ask about another related issue: what if i SHUTDOWN pc from RDP session via Shutdown command menu ("shutdown" menu command, not "shutdownbox")? Will Windows (or CS) will ask me " If you shut down this remote computer, no one can use it until someone at the remote location manually restarts it? Do you want to continue shutting down?". This happens with standard shell, but what about CS? UPD: Just checked this up (have to dig remote "victim"), and yes, all is fine |
|
| Author: | Ivo [ Sun Sep 15, 2013 10:23 am ] |
| Post subject: | Re: Remote session graceful disconnect before suspend/shutdo |
Version 3.9.5 RC is out. It disconnects the remote session before suspending. |
|
| Page 1 of 1 | All times are UTC - 8 hours [ DST ] |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|