Here's the function that I use (typically in a While... Wend loop, which should suit your requested usage well):
Global Const $DESKTOP_SWITCHDESKTOP = 0x100
Func _CheckLocked()
$hLockedDLL = DllOpen("user32.dll")
$hDesktop = DllCall($hLockedDLL, "int", "OpenDesktop", "str", "Default", "int", 0, "int", 0, "int", $DESKTOP_SWITCHDESKTOP)
$ret = DllCall($hLockedDLL, "int", "SwitchDesktop", "int", $hDesktop[0])
DllCall($hLockedDLL, "int", "CloseDesktop", "int", $hDesktop[0])
If $ret[0] = 0 Then
$iLocked = 1
ElseIf $ret[0] = 1 Then
$iLocked = 0
EndIf
DllClose($hLockedDLL)
If $iLocked Then
Return 1
Else
Return 0
EndIf
EndFunc
Edit: Added the Global Constant needed by the function