1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Usage of @winapi

Discussion in 'T&T - Functions' started by Christian Albaret, Apr 3, 2014.

  1. Christian Albaret

    Joined:
    Jul 1, 2008
    Messages:
    154
    Likes Received:
    1
    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.)
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,288
    Likes Received:
    39
    The built-in variable function @WINSYSTEM calls SystemParametersInfo(), so the easy way is to:
    Code:
    echo %@winsystem[114]
    or
    Code:
    echo %@winsystem[0x72]
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,288
    Likes Received:
    39
    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.
     
  4. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    564
    Likes Received:
    8
    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.
     
  5. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    564
    Likes Received:
    8
  6. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,885
    Likes Received:
    29
    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
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,885
    Likes Received:
    29
    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
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,885
    Likes Received:
    29
    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 ""
     

Share This Page