![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | vbscript - get workgroup name ? Hi, How do I get computer workgroup(not domain) name in vbscript ? thanks Vilius |
My System Specs![]() |
| | #2 (permalink) |
| | Re: vbscript - get workgroup name ? Vilius wrote: Quote: > > How do I get computer workgroup(not domain) name in vbscript ? > 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") -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: vbscript - get workgroup name ? Hi 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. idle, rusga On Sun, 12 Jul 2009 16:53:22 +0100, Vilius Mockûnas <v_mockunas@xxxxxx> wrote: Quote: > Hi, > > How do I get computer workgroup(not domain) name in vbscript ? > > thanks > Vilius > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: vbscript - get workgroup name ? "F. Dunoyer" <wdunoyer-nimportequoi@xxxxxx~.net> wrote in message news:mn.650c7d9762d95303.104508@xxxxxx Quote: > Richard Mueller [MVP] a écrit : Quote: >> Vilius wrote: >> Quote: >>> >>> How 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 >> retrieve any environment variable. For example, to retrieve USERDOMAIN: >> >> 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/libr...3f(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/ > 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 -- |
My System Specs![]() |
| | #5 (permalink) |
| | Re: vbscript - get workgroup name ? "F. Dunoyer" <wdunoyer-nimportequoi@xxxxxx~.net> wrote in message news:mn.6b3f7d97a6918e31.104508@xxxxxx Quote: > Richard Mueller [MVP] a écrit : Quote: Quote: >> I also do not know what IADsWinNTSystemInfo.DomainName returns when the >> computer belongs to a workgroup. > On laptop (Workgroup) IADsWinNTSystemInfo.DomainName ) %computername% ![]() and the result from IADsWinNTSystemInfo are logical; the naming is just a bit weak. A better name would be SecurityDomain. |
My System Specs![]() |
| | #6 (permalink) |
| | 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 * Source: http://www.robvanderwoude.com/vbstec...mes_domain.php "rusga" wrote: Quote: > Hi > > 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. > > idle, > rusga > > > On Sun, 12 Jul 2009 16:53:22 +0100, Vilius Mockûnas <v_mockunas@newsgroup> > wrote: > Quote: > > Hi, > > > > How do I get computer workgroup(not domain) name in vbscript ? > > > > thanks > > Vilius > > > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Workgroup Computers | Vista General | |||
| Workgroup | Vista networking & sharing | |||
| How to do No hang up VBScript (nohup for VBScript) | VB Script | |||
| Workgroup name | Vista networking & sharing | |||
| How to brows more then one workgroup | Vista networking & sharing | |||