随笔 - 89  文章 - 118  trackbacks - 0
<2011年9月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

留言簿(16)

随笔分类(56)

随笔档案(89)

文章分类

推荐博客

搜索

  •  

最新随笔

最新评论

阅读排行榜

判断用户登陆的是域还是工作组

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://okhelper.blog.51cto.com/313500/197249
Set objshell = CreateObject("wscript.shell")

strDomainDnsName = LCase(objshell.ExpandEnvironmentStrings("%USERDNSDOMAIN%"))

If strDomainDnsName = "%USERDNSDOMAIN%" Then    
  WScript.Echo "workgroup"
    
Else
  WScript.Echo "Domain"
    
End if

本文出自 “okhelper” 博客,请务必保留此出处http://okhelper.blog.51cto.com/313500/197249


注意:下面的链接提供了7种方法


http://www.robvanderwoude.com/vbstech_network_names_domain.php

Environment Variable
VBScript Code:
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserDomain = wshShell.ExpandEnvironmentStrings( "%USERDOMAIN%" )
WScript.Echo "User Domain: " & strUserDomain
Requirements:
Windows version: NT 4, 2000, XP, Server 2003, Vista or Server 2008
Network: Stand-alone, workgroup, NT domain, or AD
Client software: N/A
Script Engine: WSH
Summarized: Works in Windows NT 4 or later, *.vbs with CSCRIPT.EXE or WSCRIPT.EXE only.
Doesn't work in Windows 95, 98 or ME, nor in Internet Explorer (HTAs).
 
[Back to the top of this page]
 
WshNetwork
VBScript Code:
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
strUserDomain = wshNetwork.UserDomain
WScript.Echo "User Domain: " & strUserDomain
Requirements:
Windows version: Windows 98, ME, NT 4, 2000, XP, Server 2003, Vista, Server 2008
Network: Stand-alone, workgroup, NT domain, or AD
Client software: Windows Script 5.6 for Windows 98, ME, and NT 4 (no longer available for download?)
Script Engine: WSH
Summarized: Works in Windows 98 or later, *.vbs with CSCRIPT.EXE or WSCRIPT.EXE only.
Doesn't work in Windows 95, nor in Internet Explorer (HTAs).
 
[Back to the top of this page]
 
ADSI (WinNTSystemInfo)
VBScript Code:
Set objSysInfo = CreateObject( "WinNTSystemInfo" )
strUserDomain = objSysInfo.DomainName
WScript.Echo "User Domain: " & strUserDomain
Requirements:
Windows version: 2000, XP, Server 2003, Vista or Server 2008 (95, 98, ME, NT 4 with Active Directory client extension)
Network: Stand-alone, workgroup, NT domain, or AD
Client software: Active Directory client extension for Windows 95, 98, ME or NT 4
Script Engine: any
Summarized: Can work in any Windows version, but Active Directory client extension is required for Windows 95, 98, ME or NT 4.
Can be used in *.vbs with CSCRIPT.EXE or WSCRIPT.EXE, as well as in HTAs.
 
[Back to the top of this page]
 
ADSI (ADSystemInfo)
VBScript Code:
Set objSysInfo = CreateObject( "ADSystemInfo" )
strUserDomain = objSysInfo.DomainName
WScript.Echo "User Domain: " & strUserDomain
Requirements:
Windows version: 2000, XP, Server 2003, Vista or Server 2008 (95, 98, ME, NT 4 with Active Directory client extension)
Network: Only AD domain members
Client software: Active Directory client extension for Windows 95, 98, ME or NT 4
Script Engine: any
Summarized: For AD domain members only.
Can work in any Windows version, but Active Directory client extension is required for Windows 95, 98, ME or NT 4 SP4.
Can be used in *.vbs with CSCRIPT.EXE or WSCRIPT.EXE, as well as in HTAs.
Doesn't work on stand-alones, workgroup members or members of NT domains.
 
[Back to the top of this page]
 
WMI (Win32_ComputerSystem)
VBScript Code:
Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
    strComputerDomain = objItem.Domain
    If objItem.PartOfDomain Then
        WScript.Echo "Computer Domain: " & strComputerDomain
    Else
        WScript.Echo "Workgroup: " & strComputerDomain
    End If
Next
Requirements:
Windows version: XP, Server 2003, Vista or Server 2008
Network: Stand-alone, workgroup, NT domain, or AD
Client software: N/A
Script Engine: any
Summarized: Works in Windows XP and later.
Can be used in *.vbs with CSCRIPT.EXE or WSCRIPT.EXE, as well as in HTAs.
 
[Back to the top of this page]
 
WMI (Win32_NTDomain)
VBScript Code:
Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_NTDomain", , 48 )
For Each objItem in colItems
    strComputerDomain = objItem.DomainName
    WScript.Echo "Computer Domain: " & strComputerDomain
Next
Requirements:
Windows version: XP, Server 2003, Vista or Server 2008
Network: NT domain, or AD
Client software: N/A
Script Engine: any
Summarized: Will work only on AD or NT domain members running Windows XP or later.
Can be used in *.vbs with CSCRIPT.EXE or WSCRIPT.EXE, as well as in HTAs.
Doesn't work in Windows 95, 98, ME, NT 4, or 2000.
Doesn't work on stand-alones or workgroup members.
 
[Back to the top of this page]
 
System Scripting Runtime
VBScript Code:
Set objIP = CreateObject( "SScripting.IPNetwork" )
strComputerDomain = objIP.Domain
WScript.Echo "Computer Domain: " & strComputerDomain
Requirements:
Windows version: any
Network: TCP/IP
Client software: System Scripting Runtime
Script Engine: any
Summarized: Works in any Windows version with System Scripting Runtime is installed, with any script engine.


posted on 2011-09-26 10:09 胡满超 阅读(749) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理