Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , ,

Sponsored Links



vbscript - get workgroup name ?

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 12-07-2009
Vilius Mockûnas
 
Posts: n/a
vbscript - get workgroup name ?

How do I get computer workgroup(not domain) name in vbscript ?
Reply With Quote
  #2  
Old 12-07-2009
Richard Mueller [MVP]
 
Posts: n/a
Re: vbscript - get workgroup name ?

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 retrieve any
environment variable. For example, to retrieve USERDOMAIN:

Set objShell = CreateObject("Wscript.Shell")
Wscript.Echo objShell.Environment("PROCESS").Item("USERDOMAIN")
Reply With Quote
  #3  
Old 12-07-2009
rusga
 
Posts: n/a
Re: vbscript - get workgroup name ?

I guess the fastest way is to read it from the registry with .regread from
the shell object.

If you know one of the workgroups name, you can search for it using the
registry just to track down the key to read from.

Once you know the key to read from, it's a breeze.

Otherwise you can use the WMI, but this way the script must have WMI perms
and it's a lot heavier and slow.
Reply With Quote
  #4  
Old 13-07-2009
F. Dunoyer
 
Posts: n/a
Re: vbscript - get workgroup name ?

hum (sorry for the poor english)
Not realy the right way.
if you are not on domain, USERDOMAIN is COMPUTERNAME

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
Reply With Quote
  #5  
Old 13-07-2009
Richard Mueller [MVP]
 
Posts: n/a
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.
Reply With Quote
  #6  
Old 14-07-2009
Alex K. Angelopoulos
 
Posts: n/a
Re: vbscript - get workgroup name ?

By the way, on reflection it seems to me that the userdomain variable value
and the result from IADsWinNTSystemInfo are logical; the naming is just a
bit weak. A better name would be SecurityDomain.
Reply With Quote
  #7  
Old 21-09-2009
Renato Pereira
 
Posts: n/a
Re: vbscript - get workgroup name ? I found the answer

I found the answer!

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
Reply With Quote
  #8  
Old 06-12-2009
asdf
 
Posts: n/a
Re: vbscript - get workgroup name ? I found the answer

News Server Retention time tried to make us followers of 'numbers'.

Congratulation to your persistence to leading up to an acceptable
solution, by beating the corporate "hiding the decline" attitude.
Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "vbscript - get workgroup name ?"
Thread Thread Starter Forum Replies Last Post
Workgroup between Vista & XP DWC101 Networking & Security 1 26-07-2010 12:49 PM
Workgroup DannyR2811 Windows Vista Network 1 28-12-2008 07:36 PM
Cannot see workgroup computers by ''view workgroup computers'' - important! kimiraikkonen Windows XP Support 1 07-02-2007 09:35 PM
IAS and workgroup computers. Guy Melamed Windows Server Help 6 12-01-2007 05:30 AM
Cannot see workgroup computers wrtbd Windows Vista Network 3 07-01-2007 02:52 AM


All times are GMT +5.5. The time now is 08:44 PM.