The goal is to make a change to the registry regarding proxy settings (turn on/off) and it take effect without reloading the browser. The following code seems to return a valid response and there are no errors so I like to think I am doing it right. The problem is that it doesn't accomplish the goal. Some possible reasons are:
- This change is not considered a "top-level window" change.
- I'm doing it wrong.
- Something else I'm not considering.
Anyone have a suggestion? Thanks.
Jim
GoSub Load_Routines
Load_SetChange()
SetChangeLoader = ObjectClrNew( 'SetChange.User32Utils' )
msg = SetChangeLoader.Notify_SettingChange
Message("HEY",msg)
:LOAD_ROUTINES
#DefineSubRoutine Load_SetChange()
;***************************************************************************
;** Run C# in memory using WinBatch - Use Namespace.Class defined in CSharpeSource
;**
;** Purpose: Run C# in memory using WinBatch - Using Namespace.Class defined in CSharpeSource
;** Inputs:
;** Outputs: Results in message
;**
;** Developer: Deana Falk 2014.04.14
;***************************************************************************
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Load assemblies into the WinBatch process.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; mscorlib assembly is automatically loaded by WinBatch when the CLR is loaded.
ObjectClrOption("use","System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Compiles the c# code in Memory
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
objCSharp = ObjectClrNew('Microsoft.CSharp.CSharpCodeProvider')
objParams = ObjectClrNew('System.CodeDom.Compiler.CompilerParameters')
objParams.GenerateInMemory = ObjectType( "VT_BOOL", 1 ) ;TRUE
objParams.ReferencedAssemblies.Add("System.dll")
;Make sure the cSharp code includes both namepspace and class that can be later used by ObjectCLRNew
cSharpSource = `using System; `:@LF
cSharpSource = cSharpSource :`using System.Runtime.InteropServices; `:@LF
cSharpSource = cSharpSource :`namespace SetChange `:@LF
cSharpSource = cSharpSource :`{ `:@LF
cSharpSource = cSharpSource :`public static class User32Utils `:@LF
cSharpSource = cSharpSource :` { `:@LF
cSharpSource = cSharpSource :` static IntPtr HWND_BROADCAST = new IntPtr(0xffffL); `:@LF
cSharpSource = cSharpSource :` static IntPtr WM_SETTINGCHANGE = new IntPtr(0x1a); `:@LF
cSharpSource = cSharpSource :` enum SendMessageTimeoutFlags : uint `:@LF
cSharpSource = cSharpSource :` { `:@LF
cSharpSource = cSharpSource :` SMTO_NORMAL = 0x0000, `:@LF
cSharpSource = cSharpSource :` SMTO_BLOCK = 0x0001, `:@LF
cSharpSource = cSharpSource :` SMTO_ABORTIFHUNG = 0x2, `:@LF
cSharpSource = cSharpSource :` SMTO_NOTIMEOUTIFNOTHUNG = 0x0008 `:@LF
cSharpSource = cSharpSource :` } `:@LF
cSharpSource = cSharpSource :` [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] `:@LF
cSharpSource = cSharpSource :` static extern IntPtr SendMessageTimeout(IntPtr hWnd, `:@LF
cSharpSource = cSharpSource :` uint Msg, `:@LF
cSharpSource = cSharpSource :` UIntPtr wParam, `:@LF
cSharpSource = cSharpSource :` UIntPtr lParam, `:@LF
cSharpSource = cSharpSource :` SendMessageTimeoutFlags fuFlags, `:@LF
cSharpSource = cSharpSource :` uint uTimeout, `:@LF
cSharpSource = cSharpSource :` out UIntPtr lpdwResult); `:@LF
cSharpSource = cSharpSource :` internal static IntPtr Notify_SettingChange() `:@LF
cSharpSource = cSharpSource :` { `:@LF
cSharpSource = cSharpSource :` UIntPtr result; `:@LF
cSharpSource = cSharpSource :` IntPtr sresult; `:@LF
cSharpSource = cSharpSource :` sresult = SendMessageTimeout(HWND_BROADCAST, (uint)WM_SETTINGCHANGE, UIntPtr.Zero, UIntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, 1000, out result); `:@LF
cSharpSource = cSharpSource :` return sresult; `:@LF
cSharpSource = cSharpSource :` } `:@LF
cSharpSource = cSharpSource :` } `:@LF
cSharpSource = cSharpSource :`} `:@LF
objResult = objCSharp.CompileAssemblyFromSource(objParams,cSharpSource)
;Compiler Output
If objResult.Output.Count > 0 Then
strOutput = ''
For x = 0 to objResult.Output.Count-1
If strOutput == "" Then
strOutput = objResult.Output.Item(x)
Else
strOutput = strOutput:@LF:objResult.Output.Item(x)
EndIf
Next
Pause('Compiler Output',strOutput)
Endif
; Compiler Errors
If objResult.Errors.Count > 0 Then
strErrors = ''
ForEach ce In objResult.Errors
;Pause("Error", ce.ToString())
If strErrors == "" Then
strErrors = ce.ToString()
Else
strErrors = strErrors:@LF:ce.ToString()
EndIf
Next
Pause('Compiler Errors',strErrors)
Exit
EndIf
#EndSubRoutine
Return