如何从javascript获取终端服务客户端计算机名称? [英] How can you get the terminal service client machine name from javascript?
问题描述
是否可以从运行Internet Explorer的javascript中获取机器名称,IP或MAC地址(主要是客户端网络信息)?
Is it possible to get the machine name, or IP, or MAC address (basically client network information) from javascript running Internet Explorer?
我发现以下代码似乎可以做到这一点:
I found the following code that seems to accomplish this:
function Button1_onclick() {
var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
var e = new Enumerator (properties);
document.write("<table border=1>");
dispHeading();
for (;!e.atEnd();e.moveNext ())
{
var p = e.item ();
document.write("<tr>");
document.write("<td>" + p.Caption + "</td>");
document.write("<td>" + p.IPFilterSecurityEnabled + "</td>");
document.write("<td>" + p.IPPortSecurityEnabled + "</td>");
document.write("<td>" + p.IPXAddress + "</td>");
document.write("<td>" + p.IPXEnabled + "</td>");
document.write("<td>" + p.IPXNetworkNumber + "</td>");
document.write("<td>" + p.MACAddress + "</td>");
document.write("<td>" + p.WINSPrimaryServer + "</td>");
document.write("<td>" + p.WINSSecondaryServer + "</td>");
document.write("</tr>");
}
document.write("</table>");
}
因此它使用的是ActiveX似乎已随操作系统安装的对象来完成此操作。在终端服务会话中是否可以执行类似的操作?要获取终端服务客户端的网络信息? (不是终端服务器网络信息,这是从终端服务会话运行时上面的代码将执行的操作。)
So it's using an ActiveX Object that seems to be installed with the OS to accomplish this. Is something similar like this possible to do from a terminal service session? To get the terminal service client network information? (Not the terminal server network information which is what the above code would do when run from a terminal service session).
我在想,也许还有另一个Active X对象
I'm thinking maybe there is another Active X object available to accomplish this?
推荐答案
基本上,有两种方法可以想到客户名称/地址:
Basically, there are two possibilities to get hold of the client name/address that come to mind:
- 使用MFCOM,即
MetaFrameSession
对象。 - 使用WMI,
root\Citrix
中的MetaFrame_ICA_Client
类看起来很有希望。
- Use MFCOM, namely the
MetaFrameSession
object. - Use WMI, the
MetaFrame_ICA_Client
class inroot\Citrix
looks promising.
这两种解决方案的市长缺点是,它们需要的用户权限超出了您可能愿意提供的权限。根据我的阅读,Citrix至少需要帐户查看权限,但是我目前无法对其进行测试。我不能以普通用户的身份工作。
Mayor drawback of both solutions is, that they require more user permissions than you might be willing to give. From what I read, at least "Account View" permissions are required within Citrix, but I have no way to test it right now. I could not get either to work as a normal user.
为了给您一个想法,使用MFCOM访问信息看起来像这样:
To give you an idea, accessing the info with MFCOM would look something like this:
var MetaFrameSessionObject = 6;
var oShell = new ActiveXObject("WScript.Shell");
var oSession = new ActiveXObject("MetaFrameCOM.MetaFrameSession");
oSession.Initialize(
MetaFrameSessionObject,
oShell.ExpandEnvironmentStrings("%COMPUTERNAME%"),
oShell.ExpandEnvironmentStrings("%SESSIONNAME%"),
-1
);
alert(oSession.ClientAddress);
这篇关于如何从javascript获取终端服务客户端计算机名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!