Skip to content

Instantly share code, notes, and snippets.

@jay
Last active December 26, 2017 20:27
Show Gist options
  • Save jay/c0600cf31ab89721158c to your computer and use it in GitHub Desktop.
Save jay/c0600cf31ab89721158c to your computer and use it in GitHub Desktop.
Build RunAtWinlogon program
:: This batch file builds the RunAtWinlogon program.
:: http://reboot.pro/files/file/255-runatwinlogon/
::
:: BUG: Although this builds both x86 and x64 versions it looks as though
:: ServiceKick.au3 needs to be changed if using x64 version from RunAtWinlogon
:: to RunAtWinlogon64.
::
:: The include and Aut2Exe directories are needed from autoit-v3.zip
:: https://www.autoitscript.com/site/autoit/downloads/
::
:: The directory this batch file is in should have this layout:
:: Aut2Exe\
:: include\
:: RunAtWinlogon\
::
:: Public Domain: No License. Written by Jay Satiro <raysatiro@yahoo.com>
::
:: https://gist.github.com/jay/c0600cf31ab89721158c
::
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set EXITCODE=1
cd /d "%~dp0" || (echo Fatal: Failed cd to batch file dir & goto :EOF)
set AUT2EXE=Aut2Exe\Aut2Exe.exe
REM Aut2Exe optional:
REM /out <outfile.exe> /ico <iconfile.ico> /comp 0-4 /nopack /pack /ansi /unicode /x64 /console /gui
REM The source files already have a directive to use the console subsystem
REM so /console isn't needed.
for %%f in (RunAtWinlogon\*.au3) do (
for /L %%i in (1,1,2) do (
REM First pass x86, next x64
set "OUTFILE=RunAtWinlogon\%%~nf"
if %%i == 1 (
set "OUTFILE=!OUTFILE!.exe"
set X64=
) else (
set "OUTFILE=!OUTFILE!64.exe"
set X64=/x64
)
del "!OUTFILE!" 1>NUL 2>&1
if exist "!OUTFILE!" (
echo Error: Can't delete old "!OUTFILE!"
) else (
"%AUT2EXE%" /in "%%f" /out "!OUTFILE!" /nopack /comp 0 !X64!
if not exist "!OUTFILE!" (
echo Error: Can't find new "!OUTFILE!"
) else (
echo Processed "!OUTFILE!"
)
)
)
)
echo Done.
set EXITCODE=0
goto cleanup
:cleanup
:exitfunc
exit /b %EXITCODE%
@jay
Copy link
Author

jay commented Dec 23, 2014

@jschicht Thanks for writing RunAtWinlogon. This gist contains the build file I made for it. Also I have some questions.

I notice the archive I downloaded from reboot.pro is missing RunAtWinlogonExec and also in the directions you are using the x86 versions with a path typically found on x64 C:\Program Files (x86)\?

Here is how I'm rebuilding in Win7 x64, let me know if anything looks wrong:

taskkill /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM ServiceKick.exe
sc stop "RunAtWinlogonWrapper64"
sc stop "RunAtWinlogon64"
sc delete "RunAtWinlogonWrapper64"
sc delete "RunAtWinlogon64"

I make the modifications I want and then:

make_RunAtWinlogon.bat
sc create "RunAtWinlogonWrapper64" start= "auto" binpath= "X:\code\winlogon\RunAtWinlogon\RunAtWinlogon\RunAtWinlogonWrapper64.exe" DisplayName= "RunAtWinlogonWrapper64" obj= "LocalSystem"
sc create "RunAtWinlogon64" start= "demand" binpath= "X:\code\winlogon\RunAtWinlogon\RunAtWinlogon\RunAtWinlogon64.exe" DisplayName= "RunAtWinlogon64" obj= "LocalSystem"
sc start RunAtWinlogonWrapper64

The wrapper terminates immediately:

[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.

And I can see ServiceKick.exe is running as SYSTEM. It doesn't run ServiceKick64 as I expected. Also as I noted in the comments I changed RunAtWinlogon to RunAtWinlogon64 in ServiceKick.au3, although I don't know if it's necessary.

Does RunAtWinlogon work for you after going to the switch user screen? It only works for me at UAC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment