Re: match machine name to user name

From: PaulD (nospam)
Date: 01/26/05


Date: Wed, 26 Jan 2005 11:48:59 -0500


"Roland Hall" <nobody@nowhere> wrote in message
news:e4WZSHxAFHA.3708@TK2MSFTNGP14.phx.gbl...
> "PaulD" wrote in message news:OA0DQBwAFHA.1296@TK2MSFTNGP10.phx.gbl...
> : the machine logged in is from some code I found - I don't remember where
> it
> : came from
> :
> : Set cn = CreateObject("ADODB.Connection")
> : cn.Provider = "Microsoft.Jet.OLEDB.4.0"
> : cn.Open "Data Source=\\Server\database.mdb"
> :
> : Set rs = CreateObject("ADODB.Recordset")
> : Set rs = cn.OpenSchema(-1, ,"{947bb102-5d43-11d1-bdbf-00c04fb92675}")
> :
> : So it basically uses an OpenSchema to determine the machines logged into
> it.
> : The returned recordset has the machine name logged in as one of the
> fields.
> : The database I'm connecting to does not store the machine name or user
> names
> : in it. I know our server (running SBS 2003) has the machine name linked
> to
> : a user name, but I was trying to keep this simple and I'm not sure how
to
> : query the server from a client for a username based on a machine name.
> : Thanks for your help
> : Paul D
>
> Paul...
>
> It reads better if you post inline or at the bottom.
>
> Ok, I have one more question. Does the person running this have domain
> admin rights? If you have the workstation name, you can always query the
> workstation for the logged on user.
>
> Someone may correct my error but I think username and password are
optional
> and only needed if current user running this does not have logon
> credentials.
>
> I save this file as getuser.vbs and call for it with: getuser
> <computername>. You could always extend it and pass username and/or
> password with oArgs(1), oArgs(2) and then set:
> sUser = oArgs(1)
> sPass = oArgs(2)
> These would pass in plain text so not recommended.
>
> Option Explicit
> dim strComputer, oConn, colComputer, oComputer, oLocator, sUser, sPass
> dim oArgs
> set oArgs = wscript.arguments
> sUser = "yourdomain\administrator"
> sPass = "adminpassword"
> if oArgs.length > 0 then
> strComputer = oArgs(0)
> Set oLocator = CreateObject("WbemScripting.SWbemLocator")
> Set oConn = oLocator.ConnectServer(strComputer, "root\cimv2", sUser,
> sPass)
> oConn.Security_.ImpersonationLevel = 3
> Set colComputer = oConn.ExecQuery ("Select * from Win32_ComputerSystem")
> For Each oComputer in colComputer
> Wscript.Echo oComputer.UserName
> Next
> else
> wscript.echo "Error" & vbCrLf & _
> "Syntax: getuser computername"
> end if
> set oArgs = nothing
> set oLocator = nothing
> set oConn = nothing
> set colComputer = nothing
>
> HTH...
>
> --
> Roland Hall
> /* This information is distributed in the hope that it will be useful, but
> without any warranty; without even the implied warranty of merchantability
> or fitness for a particular purpose. */
> Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
> WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
> MSDN Library - http://msdn.microsoft.com/library/default.asp
>
>

I will be running the script from my machine. I don't think I have domain
rights but I do have access to the server by remote and can change security
levels as needed. Is it better to use the script to poll the server or to
poll each machine?

I am going to try your script and see how it works.

While I GREATLY appreciate your help and do not want to argue with you but
your comment
>>It reads better if you post inline or at the bottom<<
Is merely your opinion. I personally feel it reads better to post the
newest comments at top. This way I don't have to scroll all over the place
trying to find a response (I do us inline on occasion when it makes sense
for answering multiple questions). Or when using the readers, clicking on
each message shows the most current information typed first, again without
having to scroll. In our office, all notes are entered newest on top for
ease of viewing, so I guess I am used to reading 'bottom up'.

As the saying goes 'to each his own' and thanks again, while posting
comments for you I will post at the bottom :)

Paul D



Relevant Pages

  • Re: match machine name to user name
    ... :>: query the server from a client for a username based on a machine name. ... :> It reads better if you post inline or at the bottom. ... Is it better to use the script to poll the server or to ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem with WMI.
    ... I am running a script to get the logged on user on a remote machine ... administrator is logged on to remote machine. ... For Each objComputer in colComputer ... computername as an argument. ...
    (microsoft.public.scripting.vbscript)
  • Re: chopping off the last few lines.
    ... > various pre-processing actions upon it via a ksh script. ... bottom of a file. ... ## The bufarray is a rotating buffer which contains the last N lines ...
    (comp.unix.shell)
  • Re: random selection
    ... > rows - not from the top or bottom. ... I'm also surprised that you're joining on posteddate... ... I have written the following script to select the ... > t.PMIDNAME from tablecates t (nolock) inner join eRecords ...
    (microsoft.public.sqlserver.server)
  • Re: Drawing origin
    ... manual intervention for each drawing. ... What defines the 'bottom left of each drawing'? ... script on several files. ... I am using "Batch Script Processor v3.0.11" as a batch processor and I ...
    (comp.cad.autocad)