Jump to content
Sign in to follow this  

IniRead works in editor, not after running compiled on target PC?

Recommended Posts


I've got an odd one here. I've updated some old code that ran file previously. The update primarily just added the window title identification string to the INI file instead of being hardcoded in the script. I'm compiling the code on Windows 8.1 x64 and running it on Windows 8.1 x32 (previously ran fine on WinXP x32). There are restrictions on this PC. Through group policy, the C drive is hidden/inaccessible. This program is being run via the registry upon boot and is found in C:sspl_stuffkiosk. The INI file is located in the same directory as the executable.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <BlockInputEx.au3>         ; Attempts to block ALT+TAB from working (works in XP, sort of mimics it in >= Vista
#include <GDIPlus.au3>              ; Fixes issue with odd transparent pixels w/normal AutoIt image/background methods

Opt('TrayIconDebug', 0);    Set to 1 to view current line in tray icon via tooltip
Opt('TrayIconHide', 1);     Set to 1 to hide the tray icon
Opt("GUIOnEventMode", 1);   Can call an event on action (like button click)

$minutes_until_display = IniRead("settings.ini", "TimerScreenSettings", "minutes_until_display", 10);
$seconds_to_display    = IniRead("settings.ini", "TimerScreenSettings", "time_delay_secs", 20);
$background_color      = IniRead("settings.ini", "TimerScreenSettings", "background_color", "000000");
$splash_image          = IniRead("settings.ini", "TimerScreenSettings", "splash_image", "splash.jpg")
$text_color            = IniRead("settings.ini", "TimerScreenSettings", "text_color", "CCCCCC");
$font_size             = IniRead("settings.ini", "TimerScreenSettings", "font_size", 24);
$font_weight           = IniRead("settings.ini", "TimerScreenSettings", "font_weight", 600);
$close_msg             = IniRead("settings.ini", "TimerScreenSettings", "close_msg", "I Understand");
$font_family           = IniRead("settings.ini", "TimerScreenSettings", "font_family", "Verdana");
$message_text          = IniRead("settings.ini", "TimerScreenSettings", "message_text", "You have a little over 10 minutes remaining." & @CRLF & "Please save your work.");
$button_width          = IniRead("settings.ini", "TimerScreenSettings", "button_width", 100);
$button_height         = IniRead("settings.ini", "TimerScreenSettings", "button_height", 30);
$button_left           = IniRead("settings.ini", "TimerScreenSettings", "button_left", 1024 - $button_width);
$button_top            = IniRead("settings.ini", "TimerScreenSettings", "button_top", 768 - $button_height);
$window_width          = IniRead("settings.ini", "TimerScreenSettings", "window_width", @DesktopWidth);
$window_height         = IniRead("settings.ini", "TimerScreenSettings", "window_height", @DesktopHeight);
$image_width           = IniRead("settings.ini", "TimerScreenSettings", "image_width", @DesktopHeight);
$image_height          = IniRead("settings.ini", "TimerScreenSettings", "image_height", @DesktopHeight);
$window_class          = IniRead("settings.ini", "TimerScreenSettings", "window_class", "[REGEXPTITLE:(.* minutes)]");
$left = (@DesktopWidth - $image_width) / 2;         Image centering placement
$top  = (@DesktopHeight - $image_height) / 2;       Image centering placement
;$left = (1024 - $image_width) / 2;     Image centering placement
;$top  = (768 - $image_height) / 2;     Image centering placement

; Create newlines from the settings.ini file information
$message_text = StringReplace($message_text,'\n',@CRLF);

$window = WinWait($window_class, "", 1);            Pauses script execution until the Cassie timer/application toolbar window is created and active
While 1
    $time_remaining = WinGetTitle($window_class);   Cassie displays time remaining in title of window
    $time_remaining = StringReplace($time_remaining, " minutes", "");   Replace "X minutes" with "X"
    If $time_remaining = $minutes_until_display Then

; --- Set the Form Controls --- ;
; Window
$kiosk = GUICreate("", $window_width, $window_height, 0, 0, $WS_POPUP);
WinSetOnTop($kiosk, "", 1);                     Set the window to show up above all other windows
GuiSetBkColor("0x" & $background_color);
; Background image
$hBitmap  = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\" & $splash_image);    load bitmap as GDI+ bitmap
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap);                   convert it to a GDI bitmap
$iPic = GUICtrlCreatePic("", $left, $top, 640, 480);
$hB   = GUICtrlSendMsg($iPic, 0x0172, 0, $hHBITMAP);                            copy GDI bitmap to picture control
If $hB Then _WinAPI_DeleteObject($hB);
; Close button
$close = GUICtrlCreateButton($close_msg, $button_left, $button_top, $button_width, $button_height);
GUICtrlSetDefColor("0x" & $text_color);
GUISetFont($font_size, $font_weight, '', $font_family);
GUICtrlSetFont($close, $font_size, $font_weight, 0, $font_family);
GUICtrlSetOnEvent($close,"Remove");             Close the window early
; Dummy button for use with blocking key commands
$dummyCtrl1 = GUICtrlCreateDummy();
$dummyCtrl2 = GUICtrlCreateDummy();
; Label text
GUICtrlCreateLabel($message_text, 15, 15);      Place the text in the GUI

;--- Block certain keys/combos for XP machines ---;
Local  $AccelKeys[3][2] = [["{ENTER}", $dummyCtrl1], ["{SPACE}", $dummyCtrl1], ["!{TAB}|#{TAB}|!+{TAB}|#+{TAB}", $dummyCtrl2]];

; --- Display the Coded Form --- ;

; Watch for key accelerators and perform an action while window open, or close window after set time expires
$timer = TimerInit();
    $msg = GUIGetMsg();
        Case $msg = $dummyCtrl1
            ; DO NOTHING
        Case $msg = $dummyCtrl2
            ; DO NOTHING
        Case $msg = $close
Until $msg = $close or TimerDiff($timer) > $seconds_to_display * 1000

Func Remove ()
Func blocked ()

Lines 49-57 can be commented out to see the program run and what it's doing (it waits for a window title to update to an appropriate value, then runs - it's for a public library computer reservation system).

Settings file:


close_msg="I Understand"
font_family="Cambria Bold"
message_text="\nYou have under 10 minutes remaining.\nContents saved *ON THE COMPUTER* will be *ERASED* at the end of your session.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n                                                       To prevent loss of work, please save externally now.\n                                                                    Please see the clerk for any assistance."
button_left=493 ;1024 -> 1280 = 256 / 2 = 128 + 365 = 493 | old 365
button_top=836  ;768  -> 1024 = 256 / 2 = 128 + 708 = 836 | old 768
window_class="[REGEXPTITLE:(.* minutes)]"

Unfortunately my customized settings are not being read, only the alternate default settings (hardcoded in the application) are being used. The application and settings.ini file are both in the same folder. A different application is using the settings file as expected (compiled from an older build of AutoIt, I'm currently running v3.3.10.2 - which doesn't seem to use the AutoIt icon for compiled executables?)

Any ideas on why the INI might not be getting read on the target PC? It runs as expected when in the editor on my local dev PC.

EDIT: Just in case you're being curious and are examining every single line, note that the variable $window_class is a misnomer. I simply didn't update the variable name when I switched from class to REGEXTITLE (the class kept dynamically changing on each run).

Edited by BrendonKoz

Share this post

Link to post
Share on other sites

Try giving the script the full path and file name to the ini file instead of the relative path.

Use @ScriptDir if it's in the same folder as the script.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post

Link to post
Share on other sites

That did seem to solve the issue. I thought @ScriptDir was a default when IniRead was run though?

Share this post

Link to post
Share on other sites

I never change the directory in my script, and running the example code associated with the FileChangeDir method (prior to actually running FileChangeDir) to determine currently working directory shows that I'm in the same directory on my development machine.

I guess I can't just assume a default working directory and should explicitly state it in the future.

Thank you all!

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
Sign in to follow this