Jump to content

AutoIT hard crashes... tolerated?


Spiff59
 Share

Recommended Posts

I'm not sure what the policy here is towards AutoIT3.exe abends.

Whether people doing stupid things that crash AutoIT is chalked up to people just being stupid, or, whether the intent is to have AutoIT bulletproof from abnormal terminations.

Anyway, I (ignorantly) tried tacking a third parm, one that is valid for the .NET SetEnvironmentVariable method, onto the Kernal32 SetEnvironmentVariable function.

$ret = DllCall("Kernel32.dll", "int", "SetEnvironmentVariable", "str", "TestVar", "str", "Value123", "int", 2)

Autoit3.exe didn't respond well.

Whether it's something that ought to be fixed or not, I don't know (or particularily care).

But a quick search in Bug Track on "DllCall" didn't turn up anything closely related, so I thought I'd report it.

Link to comment
Share on other sites

@Spiff59,

Save as _EnvUpdate.au3

#include-once
#include <APIConstants.au3>
; #INDEX# =======================================================================================================================
; Title .........: Environment Update
; AutoIt Version.: 3.2.12++
; Language.......: English
; Description ...: Refreshes the OS environment.
; Author ........: João Carlos (jscript)
; Support .......: trancexx, PsaltyDS, KaFu
; ===============================================================================================================================
 
; #CURRENT# =====================================================================================================================
;_EnvUpdate
; ===============================================================================================================================
 
; #INTERNAL_USE_ONLY# ===========================================================================================================
; ===============================================================================================================================
 
; #VARIABLES# ===================================================================================================================
Global $MAX_VALUE_NAME = 1024
Global $HWND_BROADCAST = 0xffff
;Global $WM_SETTINGCHANGE = 0x001A; In APIConstants.au3
;Global $SMTO_ABORTIFHUNG = 0x0002; In APIConstants.au3
;Global $SMTO_NORMAL = 0x0000; In APIConstants.au3
Global $MSG_TIMEOUT = 5000
 
; #Example# =====================================================================================================================
;_EnvUpdate("VERSION", "7.07.0110.2600")
;MsgBox(4096, @error, EnvGet("VERSION"))
;_EnvUpdate("VERSION", "", True, True)
;MsgBox(4096, @error, EnvGet("VERSION"))
; ===============================================================================================================================
 
; #FUNCTION# ====================================================================================================================
; Name...........: _EnvUpdate
; Description ...: Refreshes the OS environment.
; Syntax.........: _EnvUpdate( ["envvariable" [, "value" [, CurrentUser [, Machine ]]]] )
; Parameters ....: envvariable  - [optional] Name of the environment variable to set. If no variable, refreshes all variables.
;                 value     - [optional] Value to set the environment variable to. If a value is not used the environment
;                                  variable will be deleted.
;                 CurrentUser  - [optional] Sets the variable in current user environment.
;                 Machine     - [optional] Sets the variable in the machine environment.
; Return values .: Success    - None
;                 Failure     - Sets @error to 1.
; Author ........: João Carlos (jscript)
; Support .......: trancexx, PsaltyDS, KaFu
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _EnvUpdate("TEMP", @SystemDir & "TEMP", True, True)
; ===============================================================================================================================
Func _EnvUpdate($sEnvVar = "", $vValue = "", $fCurrentUser = True, $fMachine = False)
    Local $sREG_TYPE = "REG_SZ", $iRet1, $iRet2
 
    If $sEnvVar <> "" Then
        If StringInStr($sEnvVar, "") Then $sREG_TYPE = "REG_EXPAND_SZ"
        If $vValue <> "" Then
            If $fCurrentUser Then RegWrite("HKCUEnvironment", $sEnvVar, $sREG_TYPE, $vValue)
            If $fMachine Then RegWrite("HKLMSystemCurrentControlSetControlSession ManagerEnvironment", $sEnvVar, $sREG_TYPE, $vValue)
        Else
            If $fCurrentUser Then RegDelete("HKCUEnvironment", $sEnvVar)
            If $fMachine Then RegDelete("HKLMSystemCurrentControlSetControlSession ManagerEnvironment", $sEnvVar)
        EndIf
        ; http://msdn.microsoft.com/en-us/library/ms686206%28VS.85%29.aspx
        $iRet1 = DllCall("Kernel32.dll", "BOOL", "SetEnvironmentVariable", "str", $sEnvVar, "str", $vValue)
        If $iRet1[0] = 0 Then Return SetError(1)
    EndIf
    ; http://msdn.microsoft.com/en-us/library/ms644952%28VS.85%29.aspx
    $iRet2 = DllCall("user32.dll", "lresult", "SendMessageTimeoutW", _
            "hwnd", $HWND_BROADCAST, _
            "dword", $WM_SETTINGCHANGE, _
            "ptr", 0, _
            "wstr", "Environment", _
            "dword", $SMTO_ABORTIFHUNG, _
            "dword", $MSG_TIMEOUT, _
            "dword_ptr*", 0)
 
    If $iRet2[0] = 0 Then Return SetError(1)
EndFunc   ;==>_EnvUpdate

João Carlos.

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • 2 weeks later...

Also irrelevant in the context of this thread.

Your comment isn't? :graduated:

DllCall allows uncontrolled access to the outside, hence it's the scripters responsibility to ensure compability. I dont think stack control should be added, however if desired, one could look at python code which does this.

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Link to comment
Share on other sites

Your comment isn't? :graduated:

DllCall allows uncontrolled access to the outside, hence it's the scripters responsibility to ensure compability. I dont think stack control should be added, however if desired, one could look at python code which does this.

My call about it being irrelevent was meant to indicate the fact that the .Net runtime and the Windows API being different was not the problem.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...