Questions

determine what user is logged in remotely (command line)

+
0 Votes
Locked

determine what user is logged in remotely (command line)

knowledgebased
Windows XP:
I'd like to perform an audit on the office by pinging an IP address (known) and resolving it to a hostname (unknown). I am using ping -a xxx.xxx.xxx.xxx

Is there another command or parameter I can use that will tell me what user is logged in to a particular hostname/IP address?

I have a feeling the %username% variable might be involved.

Any ideas?
  • +
    2 Votes
    scott_heath

    Try "WMIC /NODE:<COMPUTERNAME> COMPUTERSYSTEM GET USERNAME" and see how that works out.

    If you will be doing this on multiple systems I suggest using either PowerShell or VBScript (or even .NET if you like) and make a script that pulls all computernames from Active Directory and uses WMI to contact each computer and get the username.

    Regards,
    Scott

    http://scottisageek.spaces.live.com

    +
    0 Votes
    knowledgebased

    thanks for those suggestions. I'm looking for a more automated approach. I'll have to look into those things.

    +
    0 Votes
    Bizzo

    Create a file called IP.txt which has a list of the IP addresses you want to look at, then create a batch file with the following:

    for /f %%a in (IP.txt) do WMIC /NODE:%%a computersystem GET name, username

    It will go through each of the IP addresses in the file and return the name of the machine and the user currently logged in.

    +
    0 Votes
    mikesmobile

    Worked great. Good advice!

    +
    0 Votes
    scott_heath

    Command line automation is possible, but has clunky error trapping and such.

    That's why I recommend using VBScript for automation. You can pull the list of computers from your domain using ADO and use WMI to ping before attempting to connect and then use WMI to retrieve the logged on user name (as well as other useful stuff) and write it all to a log file.

    If you need help I can give you a basic example. Or you can go to my blog, look at my SkyDrive for my Server Inventory script. It's overkill for what you are needing but it covers the basics. if you don't have a SMS platform you could use the Server Invintory for PCs, it just needs a tweak or two.

    Regards,
    Scott

    http://scottisageek.spaces.live.com

    +
    0 Votes
    Churdoo

    I believe Scott's suggestion will do exactly what you're asking for. For example, the command:

    WMIC /NODE: xxx.xxx.xxx.xxx COMPUTERSYSTEM GET USERNAME
    Will return the username currently logged into xxx.xxx.xxx.xxx

    or
    WMIC /NODE: "workstation_name" COMPUTERSYSTEM GET USERNAME
    will return the username currently logged into "workstation_name"

    +
    0 Votes
    Slayer_

    Gotta remember this :)

    +
    0 Votes
    Kelly2121

    Thanks for this extremely useful tip!!! never knew about wmic.

  • +
    2 Votes
    scott_heath

    Try "WMIC /NODE:<COMPUTERNAME> COMPUTERSYSTEM GET USERNAME" and see how that works out.

    If you will be doing this on multiple systems I suggest using either PowerShell or VBScript (or even .NET if you like) and make a script that pulls all computernames from Active Directory and uses WMI to contact each computer and get the username.

    Regards,
    Scott

    http://scottisageek.spaces.live.com

    +
    0 Votes
    knowledgebased

    thanks for those suggestions. I'm looking for a more automated approach. I'll have to look into those things.

    +
    0 Votes
    Bizzo

    Create a file called IP.txt which has a list of the IP addresses you want to look at, then create a batch file with the following:

    for /f %%a in (IP.txt) do WMIC /NODE:%%a computersystem GET name, username

    It will go through each of the IP addresses in the file and return the name of the machine and the user currently logged in.

    +
    0 Votes
    mikesmobile

    Worked great. Good advice!

    +
    0 Votes
    scott_heath

    Command line automation is possible, but has clunky error trapping and such.

    That's why I recommend using VBScript for automation. You can pull the list of computers from your domain using ADO and use WMI to ping before attempting to connect and then use WMI to retrieve the logged on user name (as well as other useful stuff) and write it all to a log file.

    If you need help I can give you a basic example. Or you can go to my blog, look at my SkyDrive for my Server Inventory script. It's overkill for what you are needing but it covers the basics. if you don't have a SMS platform you could use the Server Invintory for PCs, it just needs a tweak or two.

    Regards,
    Scott

    http://scottisageek.spaces.live.com

    +
    0 Votes
    Churdoo

    I believe Scott's suggestion will do exactly what you're asking for. For example, the command:

    WMIC /NODE: xxx.xxx.xxx.xxx COMPUTERSYSTEM GET USERNAME
    Will return the username currently logged into xxx.xxx.xxx.xxx

    or
    WMIC /NODE: "workstation_name" COMPUTERSYSTEM GET USERNAME
    will return the username currently logged into "workstation_name"

    +
    0 Votes
    Slayer_

    Gotta remember this :)

    +
    0 Votes
    Kelly2121

    Thanks for this extremely useful tip!!! never knew about wmic.