ekim415

BlockInput Not working when using as Windos Startup Script

8 posts in this topic

Cannot seem to find the answer to this anywhere.  This is a special case software deployment so we are adding the compiled script to the Windows 7 startup folder and when its done running it calls a file to delete itself.  Everything works great except BlockInput will not work when it runs as a windows login script.  If I go in and manually run the script BlockInput works just fine but it simply will not take as a login script. 

We need to block users from opening any office applications for the 30-40 seconds the entire script runs or package will fail so any other ideas are welcomed.

Here is the first part I have pulled for testing, the sleep parameter is just for testing purposes.

#RequireAdmin
#include <AutoItConstants.au3>
#include <Date.au3>
#include <MsgBoxConstants.au3>

block()

Func block()
    BlockInput(1)
    Sleep(5000)
    checknetwork()
EndFunc   ;==>block

Func checknetwork()
    $var = Ping("server")
    If Not @error Then
        BlockInput(0)
        MsgBox(0,"avail", "SERVER IS AVAIL")
        ;verify_8()
    Else
        ;MsgBox for testing purposes only
        BlockInput(0)
        MsgBox(0, "Error!", "SERVER Is Not Accessible!", 10)
        Exit
    EndIf
EndFunc   ;==>checknetwork

 

Share this post


Link to post
Share on other sites



Under what directory did you put your script?

There's the local, for the current user

Quote

C:\Users\Me\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

And then there's the startup for all users

Quote

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

It could just be a permissions issue and putting it in the other directory might make it work.

Share this post


Link to post
Share on other sites
Quote

Under what directory did you put your script?

That is a great question.  Before posting I tried both but current user and the all users folder.  It really needs to be in the all users folder for this to work easily as far as deployment goes but at this point neither current user or all users works. 

Share this post


Link to post
Share on other sites

Change 

Func block()
    BlockInput(1)
    Sleep(5000)
    checknetwork()
EndFunc   ;==>block

to 

Func block()
    Do
        $InputBlockedState = BlockInput(1)
        Sleep(1000)
    Until $InputBlockedState = 1
    Sleep(5000)
    checknetwork()
EndFunc   ;==>block

This will keep trying to BlockInput() until it returns success.


False Positive Reporter - Mass email all anti virus vendors with an attachment of your program for fast and easy whitelisting.

PortableApps.com App Creation Wizard  - A simple GUI-based Wizard for creating PortableApps.

SoundBoard - Play any song or sound you want at the press of a hotkey.

My GitHub Page: https://github.com/BetaLeaf

Share this post


Link to post
Share on other sites

It looks like when running the script, it is not fully elevated, which is what is needed for BlockInput.  Test using the IsAdmin function to see if the script is elevated.  

 

Adam

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

On 3/1/2016 at 7:30 PM, BetaLeaf said:
Func block()
    Do
        $InputBlockedState = BlockInput(1)
        Sleep(1000)
    Until $InputBlockedState = 1
    Sleep(5000)
    checknetwork()
EndFunc   ;==>block

With the above nothing happens, the script hangs presumably since blocked state never equals 1.

 

On 3/1/2016 at 11:20 PM, AdamUL said:

It looks like when running the script, it is not fully elevated, which is what is needed for BlockInput.  Test using the IsAdmin function to see if the script is elevated.

Thank you for this tip, it is not running as admin.

Given this information it looks like running a login script as an admin may not be possible in the startup folder.  I have even tried requireAdministrator as the execution level when compiling and nothing changes.  Looks like I may have to use the task scheduler to run at startup with admin privileges to achieve this.

Interestingly enough when I create a startup script that calls another script the second script will run as admin, just not the first. 

Edited by ekim415

Share this post


Link to post
Share on other sites

This may or may not be of help for running self scripts as an admin user:

Global $sAdminUser = "user"
Global $sAdminPassword = "password"
Global $sDomain = @ComputerName
Global $iLogOnFlag = 0


If @UserName <> $sAdminUser And Not IsAdmin() Then
    $sParameters = ""
    If Not @Compiled Then
        $sParameters = ' "' & @ScriptFullPath & '"'
    EndIf

    If RunAs($sAdminUser, $sDomain, $sAdminPassword, $iLogOnFlag, @AutoItExe & $sParameters & " " & $CmdLineRaw) Then
        Exit
    Else
        Exit MsgBox(16 + 262144, "ERROR!", "Unable to run under administrator account.")
    EndIf
EndIf

;Run with Admin Token in Windows Vista and Higher.
If @UserName = $sAdminUser And Not IsAdmin() And Not StringRegExp(@OSVersion, "_(XP|200(0|3))") Then
    $sParameters = ""
    If Not @Compiled Then
        $sParameters = '"' & @ScriptFullPath & '"'
    EndIf

    If ShellExecute(@AutoItExe, $sParameters & " " & $CmdLineRaw, "", "runas") Then
        Exit
    Else
        Exit MsgBox(16 + 262144, "ERROR!", "Unable to elevate to Admin due to UAC.")
   EndIf
EndIf

 

Share this post


Link to post
Share on other sites

Try this, no elevated privileges needed

#include <GUIConstants.au3>
#include <WinAPI.au3>

Global const $SLEEP_TIME = 41000
Global $timer

Global $frmBlock = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST), WinGetHandle(AutoItWinGetTitle()))
Global $lblTimer = GUICtrlCreateLabel("Going through login procedure, please wait" & @CRLF & $SLEEP_TIME / 1000 & " seconds remaining", 0, @DesktopHeight * .4, @DesktopWidth, @DesktopHeight * .4, $SS_CENTER)

Global $hMod = _WinAPI_GetModuleHandle(0)
Global $dll_block1 = DllCallbackRegister("_BlockInput", "long", "int;wparam;lparam")
Global $dll_block2 = DllCallbackRegister("_BlockInput", "long", "int;wparam;lparam")
GLobal $hook_ex_1 = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($dll_block1), $hMod)
GLobal $hook_ex_2 = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($dll_block2), $hMod)

GUICtrlSetFont(-1, 24, "", "", "Segoe UI")
GUICtrlSetColor(-1, 0xFF0000)
GUISetBkColor(0x000000, $frmBlock)

_WinAPI_SetLayeredWindowAttributes($frmBlock, 0x000000, 255)

GUISetState(@SW_SHOW, $frmBlock)
$timer = TimerInit()

While (Ceiling(($SLEEP_TIME - TimerDiff($timer)) / 1000) > 0)
    Sleep(200)
    GUICtrlSetData($lblTimer, "Going through login procedure, please wait" & @CRLF & Ceiling(($SLEEP_TIME - TimerDiff($timer)) / 1000) & " seconds remaining")
WEnd

GUIDelete($frmBlock)

_WinAPI_UnhookWindowsHookEx($hook_ex_1)
_WinAPI_UnhookWindowsHookEx($hook_ex_2)
DllCallbackFree($dll_block1)
DllCallbackFree($dll_block2)
Exit 0

Func _BlockInput($nCode, $wParam, $lParam)
    Return 1
EndFunc

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next  
    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake