Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > vbscript - get workgroup name ?

Reply
Thread Tools Display Modes

vbscript - get workgroup name ?

 
 
Vilius Mockûnas
Guest
Posts: n/a

 
      07-12-2009
Hi,

How do I get computer workgroup(not domain) name in vbscript ?

thanks
Vilius


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      07-12-2009
Vilius wrote:

>
> 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
--


 
Reply With Quote
 
rusga
Guest
Posts: n/a

 
      07-12-2009
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 <>
wrote:

> Hi,
>
> How do I get computer workgroup(not domain) name in vbscript ?
>
> thanks
> Vilius
>
>


 
Reply With Quote
 
F. Dunoyer
Guest
Posts: n/a

 
      07-12-2009
Richard Mueller [MVP] a écrit :
> Vilius wrote:
>
>>
>> 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/


 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      07-12-2009

"F. Dunoyer" <wdunoyer-nimportequoi@laposte~.net> wrote in message
news:...
> Richard Mueller [MVP] a écrit :
>> Vilius wrote:
>>
>>>
>>> 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/
>


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
--


 
Reply With Quote
 
F. Dunoyer
Guest
Posts: n/a

 
      07-13-2009
Richard Mueller [MVP] a écrit :
> "F. Dunoyer" <wdunoyer-nimportequoi@laposte~.net> wrote in message
> news:...
>> Richard Mueller [MVP] a écrit :
>>> Vilius wrote:
>>>
>>>>
>>>> How do I get computer workgroup(not domain) name in vbscript ?
>>>>

> 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.

On my laptop PC (Workgroup PC), I have look all the envirronnement vars
and no mark of workgroup ID.

> I also do not know what
> IADsWinNTSystemInfo.DomainName returns when the computer belongs to a
> workgroup.

test ...
On laptop (Workgroup) IADsWinNTSystemInfo.DomainName ) %computername%


> 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


regards

--
François Dunoyer
Quelques textes qui m'ont séduit : http://fdunoyer.free.fr/textes.htm
Site perso : http://fds.mvps.org
Blog perso : http://fdunoyer.spaces.live.com/
Blog : http://fds34.spaces.live.com/


 
Reply With Quote
 
Alex K. Angelopoulos
Guest
Posts: n/a

 
      07-14-2009
"F. Dunoyer" <wdunoyer-nimportequoi@laposte~.net> wrote in message
news:...
> Richard Mueller [MVP] a écrit :


>> I also do not know what IADsWinNTSystemInfo.DomainName returns when the
>> computer belongs to a workgroup.

> test ...
> On laptop (Workgroup) IADsWinNTSystemInfo.DomainName ) %computername%


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
 
Renato Pereira
Guest
Posts: n/a

 
      09-21-2009
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:

> 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 <>
> wrote:
>
> > Hi,
> >
> > How do I get computer workgroup(not domain) name in vbscript ?
> >
> > thanks
> > Vilius
> >
> >

>
>

 
Reply With Quote
 
asdf
Guest
Posts: n/a

 
      12-06-2009
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.

Nice

---------------

Yes, you were born before Sept. 2009 and you mind is fresh
for challenges in Dec. 2009.






"Renato Pereira" <Renato > wrote in message
news:5EFAFF50-6041-422B-9248-...
>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:
>
>> 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
>> <>
>> wrote:
>>
>> > Hi,
>> >
>> > How do I get computer workgroup(not domain) name in vbscript ?
>> >
>> > thanks
>> > Vilius
>> >
>> >

>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows 2003 server in workgroup event id 8009 in workgroup server ray3d84 Windows Server 0 02-11-2008 07:15 PM
Home and Work workgroup - how can I set up both Workgroup names? jimsurfin Windows Media Center 0 01-20-2007 04:16 PM
Re: Please Help !! VBscript convert my image/music file into VBscript file Dave Patrick Scripting 0 12-10-2006 01:37 PM
VBscript John Scripting 0 11-09-2004 07:57 PM
Can I call a VBscript from another VBscript? Wesley Scripting 4 05-26-2004 06:34 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59