Usage of @winapi

I was looking for a way to know if the screen is locked. I found SystemParametersInfo(…) with SPI_GETSCREENSAVERRUNNING=0x0072=114 and tried calls like: %@winapi[user32.dll,SystemParametersInfo,114,0,PINT=%%var,0] (tried with 0, 1, or 2 '%'-percent, with PINT, PLONG, PVOID), but could not figure out how to use these PINT etc. arguments and get something returned to a TCC environment variable.

(If I understand well, %@WINSYSTEM[16] gives information whether the screen saver is configured, and not whether it is active/locking.)
(I found %_idleticks, which is anyway better suited to my original problem.)
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,791
48
Albuquerque, NM
prospero.unm.edu
To answer the question you actually asked: I don't think you can do that. The pointer arguments expect a constant value; they put the value in a memory location of the appropriate size and pass a pointer to the called function, but ignore any value returned in that location.

It might be possible to bodge up something using binary buffers -- I haven't tried it.
 
Jan 19, 2011
581
10
Norman, OK
Screen locked does not necessarily mean the screensaver is running. For instance, on this computer if I type WindowsKey+L, the computer "locks" and requires a password to unlock, but the screen saver doesn't start.
 
May 20, 2008
9,184
60
Syracuse, NY, USA
The failure of OpenInputDesktop() might an indication that the desktop is locked. [Does anyone know of another reason it might fail?]. In simple tests, this works:
Code:
v:\> type amilocked.btm
set hDesk=%@winapi[user32,OpenInputDesktop,0,0,0]
iff %hDesk == 0 then
  echo Locked
else
  echo Not locked
  set hDesk=%@winapi[user32,CloseDesktop,%hDesk]
endiff

v:\> amilocked.btm
Not locked

v:\> reboot /K & delay 5 & amilocked.btm
Locked

v:\>
FWIW, my SYSUTILS plugin has _IODESK which might be used to do the same thing. As it is, it invokes an error when OpenInputDesktop fails but I could change that to, for example, the string "N/A".

Code:
v:\> echo %_iodesk
Default

v:\> reboot /K & delay 5 & echo %_iodesk
TCC: (Sys) Access is denied.
ECHO is OFF
 
May 20, 2008
9,184
60
Syracuse, NY, USA
FWIW, with a little kludging, the OP's original approach could work. Put SPI's (BOOL) value into a BUFFER (or aBUFFER) and compare it to %@CHAR[1].
Code:
v:\> if "%@winapi[user32,SystemParametersInfo,114,0,abuffer,0]" == "%@char[1]" (echo ss is running) else (echo ss is not running)
ss is not running

v:\> ss & delay 2 & if "%@winapi[user32,SystemParametersInfo,114,0,abuffer,0]" == "%@char[1]" (echo ss is running) else (echo ss is not running)
ss is running
 
May 20, 2008
9,184
60
Syracuse, NY, USA
To determine whether the workstation is locked, you might also look for the LOGONUI.EXE process. I don't know why, but I can't do that with "IF ISAPP ...". But I can do it with
Code:
if "%@execstr[tasklist logonui]" NE ""