Sign in to follow this  
Followers 0
MrChris

CPU is @ 100% when App/GUI is opened

6 posts in this topic

I searched and found the below code to use for HIGH cpu usage but not sure if its really what I need let alone where in my code to put it.

While 1
    $msg = GuiGetMsg()
if $msg = 0 then sleep(250) ; or as long as I dare, nothing to do anyway
WEnd

And is this affecting me from being able to close my app/gui. I have to use task manager.

MrChris

Share this post


Link to post
Share on other sites



But where in my code does this code go? Iv tried putting it in diff areas but some areas my GUI wont even load I click on exe and nothing.

MrChris

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I did try that code LARRY noted but still didnt work.

MrChris

Edited by MrChris

Share this post


Link to post
Share on other sites

post what you have so far and that can help

Share this post


Link to post
Share on other sites

Im making a Portable OpenVPN Launcher

#include <GUIConstants.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)

; == GUI generated with Koda ==
$Form1 = GUICreate("GUI", 177, 236, 445, 349)
$Group1 = GUICtrlCreateGroup("Portable OpenVPN Launcher", 8, 8, 161, 225)

$Button1 = GUICtrlCreateButton("Add NIC", 24, 32, 57, 33)
    GUICtrlSetOnEvent (-1, "AddNic")

$Button2 = GUICtrlCreateButton("Del NIC", 96, 32, 57, 33)
    GUICtrlSetOnEvent (-1, "DelNic")

$Group2 = GUICtrlCreateGroup("Downloads", 16, 72, 145, 153)

$Button3 = GUICtrlCreateButton("Download GUI", 32, 96, 113, 33)
    GUICtrlSetOnEvent (-1, "downloadgui")

$Button4 = GUICtrlCreateButton("Download OVPN", 32, 136, 113, 33)
    GUICtrlSetOnEvent (-1, "downloadovpn")

$Button5 = GUICtrlCreateButton("Launch GUI", 32, 176, 113, 33)
    GUICtrlSetOnEvent (-1, "RunGUI")

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

Func AddNIC()
    RunWait( @ScriptDir & '\bin\addtap.bat')

EndFunc

Func DelNIC()
    RunWait( @ScriptDir & '\bin\deltapall.bat')

EndFunc

Func RunGUI()
    RunWait( @ScriptDir & '\gui.exe')

EndFunc

Func downloadovpn()
    InetGet ( "http://openvpn.net/beta/openvpn-2.1_beta9-install.exe", @ScriptDir , 0 , 0 )

EndFunc

Func downloadgui()
    InetGet ( "http://openvpn.se/files/binary/openvpn-gui-1.0.4.exe", @ScriptDir , 0 , 0 )

EndFunc

FileInstall ("openvpn-gui-1.0.4.exe", @ScriptDir & '\gui.exe',1 )

; The below are the Registry entries required by OpenVPN v2.1 
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "", "REG_SZ", @ScriptDir )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "config_dir", "REG_SZ", @ScriptDir & '\Config' )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "config_ext", "REG_SZ", "ovpn" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "exe_path", "REG_SZ", @ScriptDir & '\bin' & '\openvpn.exe' )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "log_append", "REG_SZ", "0" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "log_dir", "REG_SZ" , @ScriptDir & '\Log' )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "priority", "REG_SZ" , "NORMAL_PRIORITY_CLASS" )

; The below are the Registry entries required by OpenVPN GUI v1.0x
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "", "REG_SZ", "" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "allow_edit", "REG_SZ", "1" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "allow_password", "REG_SZ", "1" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "allow_proxy", "REG_SZ", "1" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "allow_service", "REG_SZ", "0" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "config-dir", "REG_SZ", @ScriptDir & '\Config' )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "config_ext", "REG_SZ", "ovpn" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "connectscript_timeout", "REG_SZ", "15" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "disconnectscript_timeout", "REG_SZ", "10" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "disconnect_on_timeout", "REG_SZ", "1" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "editor", "REG_SZ", @SystemDir & '\notepad.exe' )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "exe_path", "REG_SZ", @ScriptDir & '\bin' & '\openvpn.exe' )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "log_append", "REG_SZ", "0" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "log_dir", "REG_SZ", @ScriptDir & '\log' )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "log_viewer", "REG_SZ", @SystemDir & '\notepad.exe' )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "passphrase_attempts", "REG_SZ", "3" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "preconnectscript_timeout", "REG_SZ", "10" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "priority", "REG_SZ", "NORMAL_PRIORITY_CLASS" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "service_only", "REG_SZ", "0" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "show_script_window", "REG_SZ", "1" )
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "silent_connection", "REG_SZ", "0" )

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ok, you are using OnEventMode...

now you have some things running before and after your function declarations..usually functions go either at the begining or end of the code but anyways...

at the very bottom of your script add this

While 1

Sleep(1000)

Wend

or else your GUI will close at the end of your script...I'll try and fix that up here in a minute...

Edit: Here is the 'fixed' code if i understand what you're trying to do-

#include <GUIConstants.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)
; == GUI generated with Koda ==
GUICreate("GUI", 177, 236, 445, 349)
GUICtrlCreateGroup("Portable OpenVPN Launcher", 8, 8, 161, 225)
GUICtrlCreateButton("Add NIC", 24, 32, 57, 33)
GUICtrlSetOnEvent (-1, "AddNic")
GUICtrlCreateButton("Del NIC", 96, 32, 57, 33)
GUICtrlSetOnEvent (-1, "DelNic")
GUICtrlCreateGroup("Downloads", 16, 72, 145, 153)
GUICtrlCreateButton("Download GUI", 32, 96, 113, 33)
GUICtrlSetOnEvent (-1, "downloadgui")
GUICtrlCreateButton("Download OVPN", 32, 136, 113, 33)
GUICtrlSetOnEvent (-1, "downloadovpn")
GUICtrlCreateButton("Launch GUI", 32, 176, 113, 33)
GUICtrlSetOnEvent (-1, "RunGUI")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE,"MyExit")
While 1
    Sleep(1000)
WEnd
Func MyExit ()
    Exit
EndFunc
Func AddNIC()
    RunWait( @ScriptDir & '\bin\addtap.bat')
EndFunc
Func DelNIC()
    RunWait( @ScriptDir & '\bin\deltapall.bat')
EndFunc
Func downloadovpn()
    InetGet ( "http://openvpn.net/beta/openvpn-2.1_beta9-install.exe", @ScriptDir , 0 , 0 )
EndFunc
Func downloadgui()
    InetGet ( "http://openvpn.se/files/binary/openvpn-gui-1.0.4.exe", @ScriptDir , 0 , 0 )
EndFunc
Func RunGUI()
    FileInstall ("openvpn-gui-1.0.4.exe", @ScriptDir & '\gui.exe',1 )
; The below are the Registry entries required by OpenVPN v2.1 
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "", "REG_SZ", @ScriptDir )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "config_dir", "REG_SZ", @ScriptDir & '\Config' )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "config_ext", "REG_SZ", "ovpn" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "exe_path", "REG_SZ", @ScriptDir & '\bin' & '\openvpn.exe' )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "log_append", "REG_SZ", "0" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "log_dir", "REG_SZ" , @ScriptDir & '\Log' )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN", "priority", "REG_SZ" , "NORMAL_PRIORITY_CLASS" )
; The below are the Registry entries required by OpenVPN GUI v1.0x
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "", "REG_SZ", "" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "allow_edit", "REG_SZ", "1" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "allow_password", "REG_SZ", "1" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "allow_proxy", "REG_SZ", "1" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "allow_service", "REG_SZ", "0" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "config-dir", "REG_SZ", @ScriptDir & '\Config' )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "config_ext", "REG_SZ", "ovpn" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "connectscript_timeout", "REG_SZ", "15" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "disconnectscript_timeout", "REG_SZ", "10" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "disconnect_on_timeout", "REG_SZ", "1" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "editor", "REG_SZ", @SystemDir & '\notepad.exe' )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "exe_path", "REG_SZ", @ScriptDir & '\bin' & '\openvpn.exe' )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "log_append", "REG_SZ", "0" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "log_dir", "REG_SZ", @ScriptDir & '\log' )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "log_viewer", "REG_SZ", @SystemDir & '\notepad.exe' )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "passphrase_attempts", "REG_SZ", "3" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "preconnectscript_timeout", "REG_SZ", "10" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "priority", "REG_SZ", "NORMAL_PRIORITY_CLASS" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "service_only", "REG_SZ", "0" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "show_script_window", "REG_SZ", "1" )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI", "silent_connection", "REG_SZ", "0" )
    RunWait( @ScriptDir & '\gui.exe')
EndFunc
Edited by evilertoaster

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  
Followers 0