Klu*_*uge 23 windows citrix terminal-services
我的程序有没有办法确定它何时在远程桌面(终端服务)上运行?
我想在程序在远程桌面会话上运行时启用"不活动超时".由于用户因打开远程桌面会话而臭名昭着,我希望我的程序在指定的不活动时间后终止.但是,我不希望为非RD用户启用非活动超时.
Fra*_*nov 19
GetSystemMetrics(SM_REMOTESESSION)(如http://msdn.microsoft.com/en-us/library/aa380798.aspx中所述)
Ian*_*oyd 13
这是我使用的C#托管代码:
/// <summary>
/// Indicates if we're running in a remote desktop session.
/// If we are, then you MUST disable animations and double buffering i.e. Pay your taxes!
///
/// </summary>
/// <returns></returns>
public static Boolean IsRemoteSession
{
//This is just a friendly wrapper around the built-in way
get
{
return System.Windows.Forms.SystemInformation.TerminalServerSession;
}
}
Run Code Online (Sandbox Code Playgroud)
如果您想了解在您的会话中运行的应用程序,以下内容有效:
BOOL IsRemoteSession(void)
{
return GetSystemMetrics( SM_REMOTESESSION );
}
Run Code Online (Sandbox Code Playgroud)
但不是一般的任何进程ID.
如果您想知道任何可以在任意会话中运行的任意进程,那么您可以使用以下方法.
您可以通过调用ProcessIdToSessionId将进程ID转换为会话ID .获得会话ID后,您可以使用它来调用:WTSQuerySessionInformation.您可以指定WTSInfoClass为值WTSIsRemoteSession,这将为您提供有关该应用程序是否是远程桌面连接的信息.
BOOL IsRemoteSession(DWORD sessionID)
{
//In case WTSIsRemoteSession is not defined for you it is value 29
return WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, sessionID, WTSIsRemoteSession, NULL, NULL);
}
Run Code Online (Sandbox Code Playgroud)