My setup should behave slightly differently when the program is installed on a Terminal Server. I know about GetSystemMetrics(SM_REMOTESESSION)
but as far as I understood that will only tell me whether I'm running inside a RDP session. It would not catch the case where the server admin is logged on locally to install software, or would it?
当程序安装在终端服务器上时,我的设置应该略有不同。我知道GetSystemMetrics(SM_REMOTESESSION),但据我所知,这只会告诉我我是否在RDP会话中运行。它不会捕获服务器管理员在本地登录以安装软件的情况,或者它会吗?
Checking for the Terminal Server service does not appear to be viable either as that also runs on workstations when Remote Desktop has been enabled. I need to differentiate this from a true TS that allows multiple concurrent logon sessions.
检查终端服务器服务似乎不可行,因为在启用远程桌面时,它也在工作站上运行。我需要将它与允许多个并发登录会话的真正TS区分开来。
Isn't there any other service or registry key that I check for?
我检查没有任何其他服务或注册表项吗?
3 个解决方案
#1
This is exactly what you need:
这正是您所需要的:
Detecting Whether Terminal Services Is Installed
检测是否安装了终端服务
Note that in addition to this you can use the value of GetVersion() to determine if you are at all running NT. If not NT then bail out.
请注意,除此之外,您还可以使用GetVersion()的值来确定您是否完全运行NT。如果不是NT,那么就拯救出来。
// Are we running Windows NT?
DWORD dwVersion = GetVersion();
if (!(dwVersion & 0x80000000)) {
// Is it Windows 2000 or greater?
if (LOBYTE(LOWORD(dwVersion)) > 4) {
// Check with VerSetConditionMask() and VerifyVersionInfo()
return ..;
}
else {
// Windows NT 4.0 or earlier. Check ProductSuite value in
// HKLM\\System\\CurrentControlSet\\Control\\ProductOptions
return ..;
}
}
return false;
The link shows the code you need to query if the version is Win2k or later
该链接显示了如果版本是Win2k或更高版本,您需要查询的代码
#2
Thanks to the link provided by Magnus Skog I discovered that InnoSetup already supports the GetWindowsVersionEx
API function. Therefore all I had to do was this:
感谢Magnus Skog提供的链接,我发现InnoSetup已经支持GetWindowsVersionEx API函数。所以我所要做的就是:
function IsRunningOnTS: Boolean;
var
lWinVer: TWindowsVersion;
begin
GetWindowsVersionEx(lWinVer);
Result := (lWinVer.SuiteMask and VER_SUITE_TERMINAL) <> 0;
end;
I have successfully tested this for the following scenarios:
我已成功测试了以下场景:
- logged on locally to an XP workstation with RDP enabled (returns
False
) - logged on remotely to a Terminal Server via RDP (returns
True
) - logged on remotely to a workstation via RDP (returns
False
)
本地登录到启用了RDP的XP工作站(返回False)
通过RDP远程登录到终端服务器(返回True)
通过RDP远程登录到工作站(返回False)
I did not yet have the opportunity to test while logged on locally on a TS. Will update this post when I have.
我在TS上本地登录时还没有机会进行测试。我有时会更新这篇文章。
#3
I'm guessing that this question has a potential for many answers, all of which will seem slightly unsatisfactory.
我猜这个问题有可能得到很多答案,所有这些答案似乎都不尽如人意。
For instance, what are the possible scenarios:
例如,可能的场景是什么:
- Workstation, with RDP enabled (ie. XP with remote help enabled)
- Server, with RDP enabled (easily distinguishable from a workstation by checking the OS type)
启用了RDP的工作站(即启用了远程帮助的XP)
启用了RDP的服务器(通过检查操作系统类型可以轻松区分工作站)
However, what about a server that has the RDP option enabled, but it isn't used? How about a server that has the RDP option enabled, but the administrator is installing your software at the console, at a time of day when nobody is logged in through RDP? You wouldn't be able to determine if the server is actually in use, RDP-wise, or not.
但是,启用了RDP选项的服务器怎么样,但是没有使用它?如果服务器启用了RDP选项,但管理员是在一天中没有人通过RDP登录时在控制台上安装您的软件?您将无法确定服务器是否实际使用,RDP方式。
The best way to give you a concrete answer is to ask why you need to determine this? What kind of functionality will you enable or disable if you were able to reliably detect this?
给你一个具体答案的最好方法是问你为什么需要确定这个?如果能够可靠地检测到这种功能,您将启用或禁用哪种功能?
#1
This is exactly what you need:
这正是您所需要的:
Detecting Whether Terminal Services Is Installed
检测是否安装了终端服务
Note that in addition to this you can use the value of GetVersion() to determine if you are at all running NT. If not NT then bail out.
请注意,除此之外,您还可以使用GetVersion()的值来确定您是否完全运行NT。如果不是NT,那么就拯救出来。
// Are we running Windows NT?
DWORD dwVersion = GetVersion();
if (!(dwVersion & 0x80000000)) {
// Is it Windows 2000 or greater?
if (LOBYTE(LOWORD(dwVersion)) > 4) {
// Check with VerSetConditionMask() and VerifyVersionInfo()
return ..;
}
else {
// Windows NT 4.0 or earlier. Check ProductSuite value in
// HKLM\\System\\CurrentControlSet\\Control\\ProductOptions
return ..;
}
}
return false;
The link shows the code you need to query if the version is Win2k or later
该链接显示了如果版本是Win2k或更高版本,您需要查询的代码
#2
Thanks to the link provided by Magnus Skog I discovered that InnoSetup already supports the GetWindowsVersionEx
API function. Therefore all I had to do was this:
感谢Magnus Skog提供的链接,我发现InnoSetup已经支持GetWindowsVersionEx API函数。所以我所要做的就是:
function IsRunningOnTS: Boolean;
var
lWinVer: TWindowsVersion;
begin
GetWindowsVersionEx(lWinVer);
Result := (lWinVer.SuiteMask and VER_SUITE_TERMINAL) <> 0;
end;
I have successfully tested this for the following scenarios:
我已成功测试了以下场景:
- logged on locally to an XP workstation with RDP enabled (returns
False
) - logged on remotely to a Terminal Server via RDP (returns
True
) - logged on remotely to a workstation via RDP (returns
False
)
本地登录到启用了RDP的XP工作站(返回False)
通过RDP远程登录到终端服务器(返回True)
通过RDP远程登录到工作站(返回False)
I did not yet have the opportunity to test while logged on locally on a TS. Will update this post when I have.
我在TS上本地登录时还没有机会进行测试。我有时会更新这篇文章。
#3
I'm guessing that this question has a potential for many answers, all of which will seem slightly unsatisfactory.
我猜这个问题有可能得到很多答案,所有这些答案似乎都不尽如人意。
For instance, what are the possible scenarios:
例如,可能的场景是什么:
- Workstation, with RDP enabled (ie. XP with remote help enabled)
- Server, with RDP enabled (easily distinguishable from a workstation by checking the OS type)
启用了RDP的工作站(即启用了远程帮助的XP)
启用了RDP的服务器(通过检查操作系统类型可以轻松区分工作站)
However, what about a server that has the RDP option enabled, but it isn't used? How about a server that has the RDP option enabled, but the administrator is installing your software at the console, at a time of day when nobody is logged in through RDP? You wouldn't be able to determine if the server is actually in use, RDP-wise, or not.
但是,启用了RDP选项的服务器怎么样,但是没有使用它?如果服务器启用了RDP选项,但管理员是在一天中没有人通过RDP登录时在控制台上安装您的软件?您将无法确定服务器是否实际使用,RDP方式。
The best way to give you a concrete answer is to ask why you need to determine this? What kind of functionality will you enable or disable if you were able to reliably detect this?
给你一个具体答案的最好方法是问你为什么需要确定这个?如果能够可靠地检测到这种功能,您将启用或禁用哪种功能?