Jump to content

[Solved] AutoIt3 encountered a problem and needs to close.


Recommended Posts

Hello,

I'm trying the code below and returns the message: AutoIt3 encountered a problem and needs to close.

Global $MAX_VALUE_NAME = 1024
Global $HWND_BROADCAST = 0xffff
Global $WM_SETTINGCHANGE = 0x001A
Global $SMTO_ABORTIFHUNG = 0x0002
Global $TIMEOUT = 5000

#cs
LRESULT WINAPI SendMessageTimeout(
  __in       HWND hWnd,
  __in       UINT Msg,
  __in       WPARAM wParam,
  __in       LPARAM lParam,
  __in       UINT fuFlags,
  __in       UINT uTimeout,
  __out_opt  PDWORD_PTR lpdwResult
);
#ce
RegWrite("HKLM\System\ControlSet001\Control\Session Manager\Environment", "VERSION", "REG_SZ", "7.07.0110.2600")

$iRet2 = DllCall("user32.dll", "lresult", "SendMessageTimeoutW", "hwnd", $HWND_BROADCAST, "uint", $WM_SETTINGCHANGE, "wparam", "NULL", "lparam", "Environment", _
        "uint", $SMTO_ABORTIFHUNG, "uint", $TIMEOUT)

MsgBox(4096, @error, $iRet2 &@CRLF& EnvGet("VERSION"))
Someone could tell me where did I go wrong? 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

I don't think "NULL" should be used as a string for your wparam.

Also, lparam is an integer (32 or 64 bit as applicable) so even though the MSDN: WM_SETTINGCHANGE Message is a little vague on the point, that should be a pointer to the string, not the string "Environment" itself.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

So it should be more something like this?

Global $MAX_VALUE_NAME = 1024
Global $HWND_BROADCAST = 0xffff
Global $WM_SETTINGCHANGE = 0x001A
Global $SMTO_ABORTIFHUNG = 0x0002
Global $TIMEOUT = 5000

#cs
    LRESULT WINAPI SendMessageTimeout(
    __in       HWND hWnd,
    __in       UINT Msg,
    __in       WPARAM wParam,
    __in       LPARAM lParam,
    __in       UINT fuFlags,
    __in       UINT uTimeout,
    __out_opt  PDWORD_PTR lpdwResult
    );
#ce
RegWrite("HKLM\System\CurrentControlSet\Control\Session Manager\Environment", "VERSION", "REG_SZ", "7.07.0110.2600")

$strLPARAM = DllStructCreate("str;")
DllStructSetData($strLPARAM, 1, "Environment")
$iRet2 = DllCall("user32.dll", "lresult", "SendMessageTimeoutW", "hwnd", $HWND_BROADCAST, "uint", $WM_SETTINGCHANGE, "wparam", 0, "lparam", DllStructGetPtr($strLPARAM), _
        "uint", $SMTO_ABORTIFHUNG, "uint", $TIMEOUT)

MsgBox(4096, @error, $iRet2[0] & @CRLF & EnvGet("VERSION"))

Though this still does not set the Env Var :mellow: .

Link to comment
Share on other sites

Good question. That's exactly what I meant about lparam, but looking at the description of wparam on the in MSDN link, "null" is clearly differentiated from wparam being zero (or one). The only way I can think of providing that condition in a wparam type would be a pointer to a null string? I have no idea if that's right, but in my guess it would look like:

$strWPARAM = DllStructCreate("str;")
$strLPARAM = DllStructCreate("str;")
DllStructSetData($strLPARAM, 1, "Environment")
$iRet2 = DllCall("user32.dll", "lresult", "SendMessageTimeoutW", _
        "hwnd", $HWND_BROADCAST, _
        "uint", $WM_SETTINGCHANGE, _
        "wparam", DllStructGetPtr($strLPARAM), _
        "lparam", DllStructGetPtr($strLPARAM), _
        "uint", $SMTO_ABORTIFHUNG, "uint", $TIMEOUT)

This could easily be wrong, but I don't know how you send a "null" wparam DLL value that is distinguishable from simply zero.

Isn't this just doing the same thing as EnvUpdate() though?

:mellow:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

In all examples call to SendMessageTimeout is wrong, missing the last parameter thus causing the crash. It should be something like:

DllCall("user32.dll", "lresult", "SendMessageTimeoutW", _
        "hwnd", $HWND_BROADCAST, _
        "dword", $WM_SETTINGCHANGE, _
        "ptr", 0, _
        "wstr", "Environment", _
        "dword", $SMTO_ABORTIFHUNG, _
        "dword", $TIMEOUT, _
        "dword_ptr*", 0)

...Forget _opt suffix in AutoIt.

Edited by trancexx
Link to comment
Share on other sites

New goodies for the brain.

I didn't know AutoIt had an issue with "optional" parameters. And the substitution of parameter types ("wstr" for "lparam") is generally OK, or is this a special case?

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

New goodies for the brain.

I didn't know AutoIt had an issue with "optional" parameters. And the substitution of parameter types ("wstr" for "lparam") is generally OK, or is this a special case?

:mellow:

MSDN says in this case - lParam set to the string "Environment".

That means pointer to "Environment" ...and that means "wstr" or "ptr" (to manually created buffer).

Link to comment
Share on other sites

Hello @all@,

I'm still a bit dizzy... :party: I'm trying to digest all this information... :party:

@KaFu - Still the same problem. :party:

@PsaltyDS -

Isn't this just doing the same thing as EnvUpdate() though?

Not in the environmental loading of XP (PE environment - BartPE)... :P

@trancexx - I should not amaze me with you (any more) :mellow: , congratulations, your example worked as expected. Thank you. :ILA::party:

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

...Forget _opt suffix in AutoIt.

:P, next time I'll do so, thanks for the heads up!

your example worked as expected

:mellow:, could you post your working code? This one doesn't return a success for me.

Global $MAX_VALUE_NAME = 1024
Global $HWND_BROADCAST = 0xffff
Global $WM_SETTINGCHANGE = 0x001A
Global $SMTO_ABORTIFHUNG = 0x0002
Global $TIMEOUT = 5000

RegWrite("HKLM\System\CurrentControlSet\Control\Session Manager\Environment", "VERSION", "REG_SZ", "7.07.0110.2600")

$iRet2 = DllCall("user32.dll", "lresult", "SendMessageTimeoutW", _
        "hwnd", $HWND_BROADCAST, _
        "dword", $WM_SETTINGCHANGE, _
        "ptr", 0, _
        "wstr", "Environment", _
        "dword", $SMTO_ABORTIFHUNG, _
        "dword", $TIMEOUT, _
        "dword_ptr*", 0)

MsgBox(4096, @error, $iRet2[1] & @CRLF & EnvGet("VERSION"))
Link to comment
Share on other sites

:mellow:, could you post your working code?

#include-once
; #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
Global $SMTO_ABORTIFHUNG = 0x0002
Global $SMTO_NORMAL = 0x0000
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("HKCU\Environment", $sEnvVar, $sREG_TYPE, $vValue)
            If $fMachine Then RegWrite("HKLM\System\CurrentControlSet\Control\Session Manager\Environment", $sEnvVar, $sREG_TYPE, $vValue)
        Else
            If $fCurrentUser Then RegDelete("HKCU\Environment", $sEnvVar)
            If $fMachine Then RegDelete("HKLM\System\CurrentControlSet\Control\Session Manager\Environment", $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
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

  • 1 year later...

#include-once
; #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
Global $SMTO_ABORTIFHUNG = 0x0002
Global $SMTO_NORMAL = 0x0000
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("HKCU\Environment", $sEnvVar, $sREG_TYPE, $vValue)
            If $fMachine Then RegWrite("HKLM\System\CurrentControlSet\Control\Session Manager\Environment", $sEnvVar, $sREG_TYPE, $vValue)
        Else
            If $fCurrentUser Then RegDelete("HKCU\Environment", $sEnvVar)
            If $fMachine Then RegDelete("HKLM\System\CurrentControlSet\Control\Session Manager\Environment", $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

Hi, anyone can explane JScript's code. If have Window Firefox noreponding, what will happen?
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...