Jump to content
Sign in to follow this  
JScript

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

Recommended Posts

JScript

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!

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
KaFu

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: .

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
trancexx

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

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
trancexx

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).


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
JScript

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!

Share this post


Link to post
Share on other sites
KaFu

...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"))

Share this post


Link to post
Share on other sites
JScript

: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!

Share this post


Link to post
Share on other sites
KaFu
meomeo192

#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?

Share this post


Link to post
Share on other sites
meomeo192

Hi, anybody pls give me a example have a mesenger box appear to say result.

Thanks you very much.

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  

×