Usage of @winapi

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
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
Albuquerque, NM
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
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.
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:
v:\> type amilocked.btm
set hDesk=%@winapi[user32,OpenInputDesktop,0,0,0]
iff %hDesk == 0 then
  echo Locked
  echo Not locked
  set hDesk=%@winapi[user32,CloseDesktop,%hDesk]

v:\> amilocked.btm
Not locked

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

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".

v:\> echo %_iodesk

v:\> reboot /K & delay 5 & echo %_iodesk
TCC: (Sys) Access is denied.
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].
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
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
if "%@execstr[tasklist logonui]" NE ""