Spiff59 Posted October 1, 2011 Share Posted October 1, 2011 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 More sharing options...
Valik Posted October 1, 2011 Share Posted October 1, 2011 The crash is your fault, not AutoIt's. Link to comment Share on other sites More sharing options...
JScript Posted October 1, 2011 Share Posted October 1, 2011 (edited) @Spiff59, Save as _EnvUpdate.au3expandcollapse popup#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 ;==>_EnvUpdateJoão Carlos. Edited October 1, 2011 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...
Valik Posted October 1, 2011 Share Posted October 1, 2011 jscript, I think you missed the point of this thread. Link to comment Share on other sites More sharing options...
JScript Posted October 1, 2011 Share Posted October 1, 2011 jscript, I think you missed the point of this thread.You're right, I'm sorry for that!João Carlos. 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...
Shaggi Posted October 10, 2011 Share Posted October 10, 2011 .net runtime != windows api Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 10, 2011 Share Posted October 10, 2011 .net runtime != windows apiAlso irrelevant in the context of this thread. Link to comment Share on other sites More sharing options...
Shaggi Posted October 11, 2011 Share Posted October 11, 2011 Also irrelevant in the context of this thread.Your comment isn't? 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 More sharing options...
Richard Robertson Posted October 11, 2011 Share Posted October 11, 2011 Your comment isn't? 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 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