none
How to determine the originally logged in user from VBScript when it is run as admin RRS feed

  • General discussion

  • We have a vbscript that needs to pull the username of the person who logged in while the script is running as admin. I've looked everywhere. The HKEY_CURRENT_USER mirrors the admin's HKEY_USERS SID, not the originally logged in user SID. This make the task very difficult.

    Any suggestions would be very much appreciated.

    • Moved by CoolDadTx Wednesday, July 25, 2018 9:52 PM Not a C# question
    • Moved by Reed KimbleMVP Thursday, July 26, 2018 12:15 AM VBS in VB.Net
    • Changed type Bill_Stewart Tuesday, December 11, 2018 9:23 PM
    • Moved by Bill_Stewart Tuesday, December 11, 2018 9:23 PM Not a question
    Wednesday, July 25, 2018 8:50 PM

All replies

  • Hello,

    We don't support VBScript in this forum (sorry) BUT you could post in the following forum dedicated to scripting.

    https://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, July 26, 2018 12:02 AM
  • @Karen,

    Why didn't you just move this there instead of telling them to repost?

    I'll  do it...


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Thursday, July 26, 2018 12:15 AM
  • The current user on a workstation is found with WMI.

    in PowerShell:

    ([wmi]"root\CIMV2:Win32_ComputerSystem.Name='$env:COMPUTERNAME'").Username

    In VBScript:

    Set sh = CreateObject("WScript.Shell")
    computername = sh.ExpandEnvironmentStrings("%COMPUTERNAME%")
    Set cs = GetObject("winmgmts:Win32_ComputerSystem.Name='" & computername & "'")
    WScript.Echo cs.Username

    Or:

    Set sh = CreateObject("WScript.Shell")
    computername = sh.ExpandEnvironmentStrings("%COMPUTERNAME%")
    strUsername = GetObject("winmgmts:Win32_ComputerSystem.Name='" & computername & "'").UserName


    \_(ツ)_/




    • Edited by jrv Thursday, July 26, 2018 8:51 AM
    Thursday, July 26, 2018 8:48 AM
  • Why do you need to do that?

    What does the script do?


    -- Bill Stewart [Bill_Stewart]

    Thursday, July 26, 2018 1:42 PM