I want to check if other users are logged into the machine.
How best can I do this?
I guess I need to make a DOS command and grab text - this is fine.
But... what DOS command?
I know there are a few ways.
Currently I just launch Task Manager and look at the User Tab.
Thanks.
Windows: how to detect if other users logged in
Re: Windows: how to detect if other users logged in
QUSER.EXE
Will show you all OTHER users that are logged on OR "Nobody else logged on"
quser.exe | findstr.exe /v /i /B /C:" USERNAME" /C:">%USERNAME%"
Will exit with ERRORLEVEL 1 if no one else is logged on;
ERRORLEVEL 0 when someone else is logged on.
HTH ..
Code: Select all
quser.exe | findstr.exe /v /i /B /C:" USERNAME" /C:">%USERNAME%" || Echo Nobody else logged on
quser.exe | findstr.exe /v /i /B /C:" USERNAME" /C:">%USERNAME%"
Will exit with ERRORLEVEL 1 if no one else is logged on;
ERRORLEVEL 0 when someone else is logged on.
HTH ..
Re: Windows: how to detect if other users logged in
Aha!
I was just about to ask the same question
Thanks for the replies.
Can you tell me how I execute in AHK and then get the output and make a decision what to do in AHK?
Thanks.
I was just about to ask the same question
Thanks for the replies.
Can you tell me how I execute in AHK and then get the output and make a decision what to do in AHK?
Thanks.
Re: Windows: how to detect if other users logged in
Code: Select all
MsgBox % StdOut("quser")
ExitApp
StdOut(CmdString)
{
dhw := A_DetectHiddenWindows
DetectHiddenWindows, On
Run, %ComSpec%,, Hide, cPid
WinWait, ahk_pid %cPid%
DetectHiddenWindows, %dhw%
DllCall("AttachConsole", "uint", cPid)
objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec(CmdString)
while, !objExec.StdOut.AtEndOfStream
strStdOut := objExec.StdOut.ReadAll()
DllCall("FreeConsole")
Process, Close, %cPid%
Return strStdOut
}
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Re: Windows: how to detect if other users logged in
@Odlanir
I tried that code
The PC went mad.
Tried opening loooads of files
Took me 10 minutes to get back control.
Isn't there a way to execute the DOS command: quser.exe | findstr.exe /v /i /B /C:" USERNAME" /C:">%USERNAME%" || Echo Nobody else logged on
And feed that back to AHK?
Thanks.
I tried that code
The PC went mad.
Tried opening loooads of files
Took me 10 minutes to get back control.
Isn't there a way to execute the DOS command: quser.exe | findstr.exe /v /i /B /C:" USERNAME" /C:">%USERNAME%" || Echo Nobody else logged on
And feed that back to AHK?
Thanks.
Re: Windows: how to detect if other users logged in
Anyone? Still stuck on this one
quser.exe - is this a standard windows program?
It's not in my Windows 10.
Thanks
quser.exe - is this a standard windows program?
It's not in my Windows 10.
Thanks
Re: Windows: how to detect if other users logged in
E.g.
Code: Select all
; ===========================================================================================================================
; Function .....: NetWkstaUserEnum
; Link .........: https://docs.microsoft.com/en-us/windows/win32/api/lmwksta/nf-lmwksta-netwkstauserenum
;
; Description ..: The NetWkstaUserEnum function lists information about all users currently logged on to the workstation.
; This list includes interactive, service and batch logons.
; ===========================================================================================================================
NetWkstaUserEnum(ServerName := "127.0.0.1")
{
static NERR_SUCCESS := 0
static MAX_PREFERRED_LENGTH := -1
static WKSTA_USER_INFO_1 := 1
if (NET_API_STATUS := DllCall("netapi32\NetWkstaUserEnum", "wstr", ServerName
, "uint", WKSTA_USER_INFO_1
, "ptr*", buf
, "uint", MAX_PREFERRED_LENGTH
, "uint*", EntriesRead
, "uint*", TotalEntries
, "uint*", 0
, "uint") != NERR_SUCCESS) {
throw Exception("NetWkstaUserEnum failed: " NET_API_STATUS, -1), DllCall("netapi32\NetApiBufferFree", "ptr", buf, "uint")
}
addr := buf, WKSTA_USER_INFO := []
loop % EntriesRead
{
WKSTA_USER_INFO[A_Index, "username"] := StrGet(NumGet(addr + A_PtrSize * 0, "uptr"), "utf-16")
WKSTA_USER_INFO[A_Index, "logon_domain"] := StrGet(NumGet(addr + A_PtrSize * 1, "uptr"), "utf-16")
WKSTA_USER_INFO[A_Index, "oth_domains"] := StrGet(NumGet(addr + A_PtrSize * 2, "uptr"), "utf-16")
WKSTA_USER_INFO[A_Index, "logon_server"] := StrGet(NumGet(addr + A_PtrSize * 3, "uptr"), "utf-16")
addr += A_PtrSize * 4
}
return WKSTA_USER_INFO, DllCall("netapi32\NetApiBufferFree", "ptr", buf, "uint")
}
; ===========================================================================================================================
GetWkstaUser := NetWkstaUserEnum()
for i, v in GetWkstaUser {
for k, v in GetWkstaUser[i]
output .= k ": " v "`n"
MsgBox % output
output := ""
}
; ===========================================================================================================================
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Windows: how to detect if other users logged in
WOW!
Is that AHK code?
Is that AHK code?
Re: Windows: how to detect if other users logged in
@jNizM need some help with your code.
I've now tested fully. It's a promising start.
I simply need to know if the number of users logged in is more than 1.
If I can get a list of the logged in users, that would be amazing.
Your code gives a popup for every used logged in.
If I have 3 users logged in, then I'll get 3 popups.
This is OK, I can just read the length of the array.
PROBLEM: when JUST one user is logged in, I get 2 popups.
The same popup comes up twice.
When 2 users logged in - 2 popups.
When 3 users logged in - 3 popups.
I'm completely confused about the code to get the user information in the first place!
>> https://docs.microsoft.com/en-us/windows/win32/api/lmwksta/nf-lmwksta-netwkstauserenum
That shows C++ code??
>> ServerName := "127.0.0.1"
What's that about? (I guess if I understood the rest, maybe it would be clearer!)
Really stuck on this one. Would be great to hear what you (or anyone else) say.
Thanks.
I've now tested fully. It's a promising start.
I simply need to know if the number of users logged in is more than 1.
If I can get a list of the logged in users, that would be amazing.
Your code gives a popup for every used logged in.
If I have 3 users logged in, then I'll get 3 popups.
This is OK, I can just read the length of the array.
PROBLEM: when JUST one user is logged in, I get 2 popups.
The same popup comes up twice.
When 2 users logged in - 2 popups.
When 3 users logged in - 3 popups.
I'm completely confused about the code to get the user information in the first place!
>> https://docs.microsoft.com/en-us/windows/win32/api/lmwksta/nf-lmwksta-netwkstauserenum
That shows C++ code??
>> ServerName := "127.0.0.1"
What's that about? (I guess if I understood the rest, maybe it would be clearer!)
Really stuck on this one. Would be great to hear what you (or anyone else) say.
Thanks.
Re: Windows: how to detect if other users logged in
It also shows your local computername as logged in. (e.g. MYCOMPUTER$)
Yes it shows the C++ Exampleomar wrote: ↑31 Dec 2019, 21:58>> https://docs.microsoft.com/en-us/windows/win32/api/lmwksta/nf-lmwksta-netwkstauserenum
That shows C++ code??
127.0.0.1 is the local IP-Address from your local computer. (see: https://en.wikipedia.org/wiki/Localhost)
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Who is online
Users browsing this forum: No registered users and 184 guests