Seems I've run into a bit of a downer. I'm trying to determine whether or not a remote computer is locked (part of a domain, winXP, I have full admin rights to the machine). Now even though that might seem like a simple and often used function... Several weeks of scouring through google/msdn/technet/endless forums have come up blank.
I have found several pieces of code that do sort of work, but they all have to be run locally (which is not an option). However, I may have found an alternative, but don't know if it is possible.
By Steve Guettler
dill = strcat(dirwindows(1),"user32.dll") ;Set the path to the User32.dll
lock_state = @false ;Initialize variable (Default return value = @false)
dll_hand = dllload(dill) ;Retrieve handle to $dill
desktop_hand = dllcall(dll_hand,long:"OpenInputDesktop",word:0,word:0,word:0) ;Retrieve handle of current desktop
if desktop_hand < 1 ;If $desktop_hand < 1 (NULL or 0), then machine is locked.
lock_state = @true ;Set $lock_state to true if $desktop_hand > 0
dllfree(dll_hand) ;Free the DLL handle
return(lock_state) ;Return the lock state
Note: the success or failure of OpenInputDesktop is going to depend solely on the privileges of the user account calling the function and the effective permissions that exist on the desktop that currently has keyboard & mouse input attached to itself.
Keeping that in mind, in most the situations the method shown above will work provided that the "Winlogon" desktop has not had its security altered to allow the user's process to access it. When the workstation is locked, the "Winlogon" desktop will be the active desktop, and the user's process would normally not have permissions to access it so attempting to open it should fail, with the failure being interpreted as meaning that the workstation is locked.
This would seem like a proper solution, but since I can't run any code locally, and this might sound incredibly stupid if it is not possible but I'm not that advanced in programming and am shooting in the dark here... can I load the user32.dll through the windows admin share (\\<machinename>\C$\Windows\System32\user32.dll) and the use the same code (though converted and everything)? Or will that just result in an overly complicated way of loading a different user32.dll to be used on the computer running the code?
Any help would be much appreciated!