Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Running remote query on %LOGONSERVER%

894 views
Skip to first unread message

ITman

unread,
Dec 18, 2002, 5:10:59 AM12/18/02
to
Hi all

I want to query each computer on my network and
pull each computer environment variable %LOGONSERVER%. (see WSH code)

I tried the following WMI script too
(reading registery key - HKEY_CURRENT_USER\Volatile
Environment\LOGONSERVER),
but this isnt quit good for me since not all computers are online, and not
all of
them have the reg key (see WMI code).

i even tried to read the reg key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group
Policy\History\DCName

does anyone have a suggestion?


WSH Code
----------------------------------------------------------------------------
--------------------------

the WSH code is only for running the script on the local machine
or via login script.

Set shell = wscript.createobject ("WScript.Shell")
Set env = shell.environment ("Process")

logonServer = env.Item ("LOGONSERVER")
msgbox "logonServer " & logonServer

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

WMI Code
----------------------------------------------------------------------------
--------------------------
const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002


Dim arrMachines
arrMachines = Split(enumDomainMachines("MYDOMAIN"),";")

Dim i
Dim oReg,strKeyPath,strValueName,strValue

For i = 0 To UBound(arrMachines)-1
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
arrMachines (i) & "\root\default:StdRegProv")
strKeyPath = "Volatile Environment"
strValueName = "LOGONSERVER"
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
MsgBox "LogonServer on " & arrMachines (i) & " = " & strValue
Next


Function enumDomainMachines(domain)

Dim Container
Dim sComputer
Dim sComputers
sComputers = ""

Set Container = GetObject("WinNT://" & domain)
Container.Filter = Array("Computer")

For Each sComputer in Container
sComputers = sComputers & sComputer.Name & ";"
Next

enumDomainMachines = sComputers

End Function
----------------------------------------------------------------------------
--------------------------

Ivan Brugiolo [MSFT]

unread,
Dec 18, 2002, 10:21:14 AM12/18/02
to
I guess the proper way of doing this is to enumerate
the Interactive and RemoteInteractive Logon sessions on the remote machine,
and then retieve the user associated with the Logon session,
and get that information from the user instance.
The environment variables are a too volatile thing,
and they are not there if there is no user logged on.

There has been 2 thread in the past on this forum
about the "Logged on User" misleading concept,
and it's ramifications on the mapped network share and few other small
things.

--
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"ITman" <sh...@iaa.gov.il> wrote in message
news:#JucuznpCHA.2384@tk2msftngp13...

Daniel Pravat [MSFT]

unread,
Dec 18, 2002, 8:07:51 PM12/18/02
to
Another idea is to have a script on the machine to tell the current logon
server and report it,
using WMI, back to a admin location. The script can be deployed using Group
Policy.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Ivan Brugiolo [MSFT]" <ivan...@online.microsoft.com> wrote in message
news:uvkfLlqpCHA.2460@TK2MSFTNGP12...

ITman

unread,
Dec 19, 2002, 7:55:01 AM12/19/02
to
thats interesting...
can you offer a link or a code???


Ivan Brugiolo [MSFT]

unread,
Dec 19, 2002, 10:45:44 AM12/19/02
to
Actually,
I just realized that the interesting (for you) property of the
LsaEnumerateLogonSession API
is not re-exposed in the Win32_LogonSession class.

If you can get the logonsession.exe binary that I posted sometimes ago in
this forum,
you should be able to parse the output of that command.
Look for the Interactive/RemoteInteractive LogonType, and then the
LogonServer property.
I tought that the Win32_LogonSession would have exposed that property.

--
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"ITman" <sh...@iaa.gov.il> wrote in message

news:egRbD21pCHA.704@TK2MSFTNGP09...

0 new messages