Classic Shell development was stopped in December 2017. For now the forum remains online as reference, but is read-only. Registration of new users is disabled.
It is currently Thu Sep 11, 2025 7:20 am

All times are UTC - 8 hours [ DST ]


Forum rules


Before posting a bug report or a feature request, search the forum for an older post on the same topic.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Sep 14, 2013 11:44 am 
Offline

Joined: Sat Sep 14, 2013 11:28 am
Posts: 23
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;
}



Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 14, 2013 11:59 am 
Offline
Site Admin
User avatar

Joined: Wed Jan 02, 2013 11:38 pm
Posts: 5333
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.


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 14, 2013 12:09 pm 
Offline

Joined: Sat Sep 14, 2013 11:28 am
Posts: 23
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.


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 14, 2013 1:14 pm 
Offline
Site Admin
User avatar

Joined: Wed Jan 02, 2013 11:38 pm
Posts: 5333
OK, the next version 3.9.5 will try to disconnect before sleep/hibernate. It will most likely be released tomorrow.


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 14, 2013 1:53 pm 
Offline

Joined: Sat Sep 14, 2013 11:28 am
Posts: 23
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 :)


Top
 Profile  
Reply with quote  
PostPosted: Sun Sep 15, 2013 10:23 am 
Offline
Site Admin
User avatar

Joined: Wed Jan 02, 2013 11:38 pm
Posts: 5333
Version 3.9.5 RC is out. It disconnects the remote session before suspending.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group, Almsamim WYSIWYG Classic Shell © 2010-2016, Ivo Beltchev.
All right reserved.