Post by F. DunoyerPost by Richard Mueller [MVP]Post by Vilius MockûnasHow do I get computer workgroup(not domain) name in vbscript ?
I don't have a workgroup, but I assume there is an environment variable
with the information you need. You can use the wshShell object to
Set objShell = CreateObject("Wscript.Shell")
Wscript.Echo objShell.Environment("PROCESS").Item("USERDOMAIN")
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
hum (sorry for the poor english)
Not realy the right way.
if you are not on domain, USERDOMAIN is COMPUTERNAME
Try wshNetwork Object (
http://msdn.microsoft.com/en-us/library/s6wt333f(VS.85).aspx )
Something lik that
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Domain = " & WshNetwork.UserDomain
WScript.Echo "Computer Name = " & WshNetwork.ComputerName
WScript.Echo "User Name = " & WshNetwork.UserName
But not good :( because it's alway the same isue : DOMAIN is %USERDOMAIN%
A good way is to use WMI
set wmi = getobject("winmgmts:")
wql = "select * from win32_computersystem"
set results = wmi.execquery(wql)
For each compsys in results
WScript.Echo "DOMAIN / WORKGROUP : " & compsys.domain
Next
--
François Dunoyer
Astuces pour Windows : http://fds.mvps.org/ta/
Site perso : http://www.fdunoyer.net
Blog : http://fds34.spaces.live.com/
Documentation states that if the computer is not joined to a domain, the
domain property of the Win32_ComputerSystem class is the name of the
workgroup. So the above code will work, but WMI should be slower than other
methods. Also, WMI is not available before Windows 2000 (unless it is
installed separately).
I don't know if there is an environment variable for this, but if there is,
reading it would be faster. I also do not know what
IADsWinNTSystemInfo.DomainName returns when the computer belongs to a
workgroup. I'm surprised I cannot find how to retrieve this, other than with
WMI. I know there is a registry setting in Win9x, but that doesn't work
after Windows 98.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--