JScript Posted June 29, 2010 Share Posted June 29, 2010 (edited) 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 July 1, 2010 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 30, 2010 Share Posted June 30, 2010 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. 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 More sharing options...
KaFu Posted June 30, 2010 Share Posted June 30, 2010 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 . Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 30, 2010 Share Posted June 30, 2010 (edited) 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? Edited June 30, 2010 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 More sharing options...
trancexx Posted June 30, 2010 Share Posted June 30, 2010 (edited) 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 June 30, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 30, 2010 Share Posted June 30, 2010 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? 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 More sharing options...
trancexx Posted June 30, 2010 Share Posted June 30, 2010 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?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 Link to comment Share on other sites More sharing options...
JScript Posted July 1, 2010 Author Share Posted July 1, 2010 Hello @all@,I'm still a bit dizzy... I'm trying to digest all this information... @KaFu - Still the same problem. @PsaltyDS - Isn't this just doing the same thing as EnvUpdate() though? Not in the environmental loading of XP (PE environment - BartPE)... @trancexx - I should not amaze me with you (any more) , congratulations, your example worked as expected. Thank you. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
KaFu Posted July 1, 2010 Share Posted July 1, 2010 ...Forget _opt suffix in AutoIt. , next time I'll do so, thanks for the heads up! your example worked as expected , 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")) Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
JScript Posted July 1, 2010 Author Share Posted July 1, 2010 (edited) , could you post your working code? expandcollapse popup#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 July 1, 2010 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
KaFu Posted July 1, 2010 Share Posted July 1, 2010 Excellent , thanks for posting . Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
meomeo192 Posted February 28, 2012 Share Posted February 28, 2012 expandcollapse popup#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 More sharing options...
meomeo192 Posted February 29, 2012 Share Posted February 29, 2012 Hi, anybody pls give me a example have a mesenger box appear to say result. Thanks you very much. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now