Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'GetLoggedInUserName v1.0.1, January 18th 2024.
- 'https://www.reddit.com/user/jcunews1
- 'https://pastebin.com/u/jcunews
- 'https://greasyfork.org/en/users/85671-jcunews
- '
- 'Display the user name of the oldest user account which was logged into
- 'interactive session. This script is intended to be run by a different
- 'user account in any logon session.
- '
- 'If there no user account logged into the interactive session,
- 'nothing will be displayed, and the script ends with exit code 1.
- set wm = getobject("winmgmts:")
- 'get oldest interactive logon session ID
- set rs = wm.execquery("select * from win32_logonsession")
- lsid = 0
- lsst = 1e300
- for each ls in rs
- if ls.logontype = 2 then 'interactive session
- st = cdbl(left(ls.starttime, 21))
- if st < lsst then
- lsid = ls.logonid
- lsst = st
- end if
- end if
- next
- 'get first user name logged into oldest interactive session
- set rs = wm.execquery("select * from win32_loggedonuser")
- username = ""
- for each lu in rs
- if instr(lu.dependent, """" & lsid & """") > 0 then
- username = mid(lu.antecedent, instr(lu.antecedent, "Name=") + 6)
- username = left(username, len(username) - 1)
- exit for
- end if
- next
- if username <> "" then
- wsh.echo username
- else
- wsh.quit 1
- end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement