Google Groupes n'accepte plus les nouveaux posts ni abonnements Usenet. Les contenus de l'historique resteront visibles.

Get user Name

9 vues
Accéder directement au premier message non lu

Gus

non lue,
28 août 2002, 00:16:2528/08/2002
à
How do I get the name of a user logged on to a NT
workstation?
I need to be able to get this information from a different
workstation, preffrably using a VB Script.

The PDC and all workstations are all running WINNT

Michael Harris (MVP)

non lue,
28 août 2002, 00:30:0228/08/2002
à

You need WMI on the local *and* remote machine and you must be in the remote machine's Administrators group.

computer = "."
'"." means local machine...
'use the netbios name, full dns name,
'or ip address of the remote machine...

set wmi = getobject("winmgmts://" & computer)
wql = "select username from win32_computersystem "
set results = wmi.execquery(wql)
for each win32_computersystem in results
msgbox win32_computersystem.username
next

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Gus

non lue,
28 août 2002, 01:18:3528/08/2002
à
IS there any way to get this information without using WMI
and also without being an admin?

>.
>

Lee Derbyshire

non lue,
28 août 2002, 06:48:4428/08/2002
à
"Gus" <gba...@gesb.wa.gov.au> wrote in message
news:afde01c24e49$aca3f2c0$9ae62ecf@tkmsftngxa02...

Do you want the actual name, or just the network logon?

Lee.

--
___________________________________

Outlook Web Access for PDA and WAP:
www.leederbyshire.com
___________________________________


TomD

non lue,
28 août 2002, 13:45:1928/08/2002
à
"Lee Derbyshire" <LeeDerbyshire@(no-effin'-spam)CSI.Com> wrote in message
news:1030531603.13044....@oldnews.demon.co.uk...
<SNIPPED>

> Do you want the actual name, or just the network logon?

I'm not the original poster, but I'm looking for a way to get the network
logon name. I was looking WSH, but I'm a little confused on how exactly
that works in HTML. I tried a couple of examples with no success to this
point. (I didn't yet find out how to verify that WSH is installed)


Lee Derbyshire

non lue,
28 août 2002, 15:56:5628/08/2002
à

TomD <dcbne...@nospam.stargate.net> wrote in message
news:efYhPtrTCHA.1836@tkmsftngp12...

You can get the network logon with something like:

logonID = Request.ServerVariables("REMOTE_USER")

or

logonID = Request.ServerVariables("LOGON_USER")

which also gives the domain name (or vice versa, can't remember right now)

Lee.

--

Gurgen

non lue,
28 août 2002, 17:18:0728/08/2002
à
You can parse output of either nbtstat -a [host] or 3-rd party tool - psloggedon.exe from www.systeminternals.com
Neither require admin. rights.

Bellow is an "nbtstat" solution:
---------------------- getuser.vbs------------------------
If Wscript.Arguments.Count <> 1 then
Wscript.Echo "Syntax: getuser.vbs [valid_host_name]"
Wscript.Quit
End If
Wscript.Echo GetUserName(Wscript.Arguments(0))

Function GetUserName(host)
On error resume next
Set wShell=CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
tempFile = wShell.ExpandEnvironmentStrings("%TEMP%") & "\~$$uname$$"
cmdLine = "%comspec% /c for /f ""tokens=1 skip=1"" %I in ('nbtstat -a " & _
host & " ^|find ""<03>""') do Echo %I>" & chr(34) & tempFile & chr(34)
wShell.run cmdLine, 0, True
Set hFile = fso.OpenTextFile(tempFile, 1, False)
If err.number <> 0 then
Wscript.Echo host & " - The host is down or have no user logged on!"
Wscript.Quit 1
End If
GetUserName = hFile.ReadLine
hFile.Close
fso.DeleteFile tempFile
End Function
----------------------------------------------------------

regards,
--
Gurgen Alaverdian
http://www.gurgensvbstuff.com
"Gus" <gba...@gesb.wa.gov.au> wrote in message news:9ca701c24e52$5be2a4e0$9ee62ecf@tkmsftngxa05...

Gurgen

non lue,
28 août 2002, 19:13:3428/08/2002
à
And this one will also work from W9x:

---------------------------getuser.vbs----------------------
If Wscript.Arguments.Count <> 1 then
Wscript.Echo "Syntax: getuser.vbs [valid_host_name or IP]"
Wscript.Quit 1
End If
host = Wscript.Arguments(0)
UserName = GetUserName(host)

If UserName = "" then
Wscript.Echo host & " - User is not logged on!"
Wscript.Quit 3
Else: Wscript.Echo UserName
End If

Function GetUserName(host)
On error resume next

If InStr(host, ".") <> 0 then
opt = " -A " & host
Else: opt = " -a " & host
End If


Set wShell=CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
tempFile = wShell.ExpandEnvironmentStrings("%TEMP%") & "\~$$uname$$"

cmdLine = "%comspec% /c nbtstat" & opt & ">" & chr(34) & tempFile & chr(34)


wShell.run cmdLine, 0, True
Set hFile = fso.OpenTextFile(tempFile, 1, False)

i = 0
Do while not hFile.AtEndOfStream
nameStr = hFile.ReadLine
If instr(nameStr, "Host not found.") <> 0 then
Wscript.Echo host & " - The host is not found or down!"
Wscript.Quit 2
End If
If InStr(nameStr, "<03>") <> 0 then uName = nameStr : i = i + 1
If i > 1 then
'Strip leading spaces for W2K output
Do While Left(uName, 1) = chr(32)
uName = Right(uName, Len(uName) - 1)
Loop
GetUserName = Split(uName, " ")(0)
Exit Function
End If
Loop


hFile.Close
fso.DeleteFile tempFile
End Function

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

"Gurgen" <gur...@bellatlantic.net> wrote in message news:j6bb9.153$EB3...@nwrddc03.gnilink.net...

Gurgen

non lue,
28 août 2002, 19:21:2928/08/2002
à

A bug fixed --- inline :"Gurgen" <gur...@bellatlantic.net> wrote in message news:yOcb9.509$EB3...@nwrddc03.gnilink.net...

------- begin insert ----------------
hFile.Close
fso.DeleteFile tempFile
------- end insert -------------------

gus

non lue,
29 août 2002, 01:39:0129/08/2002
à
YOur a bloody marvel, works a treat. THanks heaps
>.
>
0 nouveau message