set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "User Name: " & WshNetwork.UserName
WScript.Echo "User Domain: " & WshNetwork.UserDomain
根据UserDomain的值是否和域名称相等就可以判断计算机是否已经登录域。
也可以在HTML或者HTA应用中使用Javascript写.
<!—example1.hta-->
<html>
<head>
<title>test domain</title>
<style>
p {font-size:24;cursor:hand}
</style>
</head>
<body>
<center>
<script language="JavaScript">
var WshNetwork=new ActiveXObject("WScript.Network");
document.writeln("Domain = "+WshNetwork.UserDomain);
document.writeln("<br />");
document.writeln("Computer Name="+WshNetwork.ComputerName);
document.writeln("<br />");
document.writeln("User Name= "+WshNetwork.UserName);
</script>
</center>
</body>
</html>
保存成HTA文件即可执行