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

    • sree161
      By sree161
      Hi,
      i have a code which generates two numeric outputs.i have to save them in excel.
      Is there any way to export them to specific cells in excel???
    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • hugomito
      By hugomito
      Hi all,
      I built an AutoIt application that interacts with several other applications/software. Now, it's turn to interfact with Visual Studio Team Services (VSTS).
      Does anyone has a blog, demo, script to share?
      Thanks!
    • Viki
      By Viki
      This is my first time here so please dont bombard me that what a silly question I am asking!!
      I have 500 rows (A1:A500) in a spreadsheet and I just want to copy one by one row and then paste into another application and then press enter, loop should repeat this until finishes all 500 rows.
      I have looked at clipget(), clip(put() but dont know how to select next row in next turn. I also looked at Array to store but again no luck. Can some guide me please..
    • DineshPawar
      By DineshPawar
      0down votefavorite   In my current project, Excel macro open AutoIt script using a function Call Shell("location of autoit script").
      For proper functioning of AutoIt script it's need to be close parent Excel workbook, so this closing Excel action is written in AutoIt script itself.
      But as soon as AutoIt script close parent Excel workbook then script get pause and it do nothing.
      How open the AutoIt script from Excel workbook and after that parent Workbook get close?