Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Trouble with Switch/Case

$
0
0
Hello,

I am having troubles with a case in my switch not triggering...

[ autoit ]         
#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1) ; This disables 32bit applications from being redirected to syswow64 instead of system32 by default ; #Region ### START Koda GUI section ### Form= $jLockFormWidth = 80 $jLockFormHeight = 115 $jLockForm = GUICreate("JLock",$jLockFormWidth, $jLockFormHeight, -$jLockFormWidth+2, (@DesktopHeight/2)-($jLockFormHeight/2), $WS_POPUP, $WS_EX_TOPMOST) $programs = GuiCtrlCreateButton("Programs",5,5,70,30,$BS_FLAT) $websites = GuiCtrlCreateButton("Websites",5,40,70,30,$BS_FLAT) $manageIE = GuiCtrlCreateButton("Manage IE",5,75,70,30,$BS_FLAT) $ieManagementWidth = 350 $ieManagementHeight = 200 $ieManagementForm = GuiCreate("Internet Explorer Management",$ieManagementWidth,$ieManagementHeight,(@DesktopWidth/2)-($ieManagementWidth/2),(@DesktopHeight/2)-($ieManagementHeight/2),"",$WS_EX_TOPMOST) $ieManagementClose = GuiCtrlCreateButton("Close",$ieManagementWidth-85,$ieManagementHeight-65,70,30,$BS_FLAT) #EndRegion ### END Koda GUI section ### AutoItSetOption("WinTitleMatchMode", -2) ;sets window title match mode to anykeyword upper and lowercase AutoItSetOption("TrayIconDebug", 1) ;debugging info Global $unlockPassword="topsecretpassword", $unlockPasswordArray = StringSplit(StringLower($unlockPassword),"",2), $unlockChar ;Password will be converted to lowercase if it is not already. Global $iniFile = "JLock.ini", $iniGAP = IniReadSection($iniFile,"GLOBALLYALLOWEDPROGRAMS"), $iniGBP = IniReadSection($iniFile,"GLOBALLYBLOCKEDPROGRAMS"), $iniGAW = IniReadSection($iniFile,"GLOBALLYALLOWEDWEBSITES"), $iniGBK = StringSplit(IniRead($iniFile,"GLOBALLYBLOCKEDKEYWORDS","keywords",""),",",1), $INIGBPSS ;Used in INI Functions$iniGBPSS Global $controlStartDummy, $controlEndDummy ;Used to encapsulate x number of controls. Global $programsDummy, $programsContext, $websitesDummy, $websitesContext ;Context Menus Global $menuExtended = False, $menuX = -$jLockFormWidth+2, $hotspotMargin = 20 ;Autohide Magics Global $ieStartDummy, $ieEndDummy lockSystem() popMenus() GUISetState(@SW_SHOW, $jLockForm) While 1 ; <======== BEGIN BLOCKED ELEMENTS ========> ;blocked programs loop For $i = 0 To UBound($iniGBP)-1 $iniGBPSS = StringSplit($iniGBP[$i][1],"\",2) while ProcessExists($iniGBPSS[UBound($iniGBPSS)-1]) taskKill($iniGBPSS[UBound($iniGBPSS)-1], True, False) ;~ Sleep(500) WEnd Next ;blocked keywords loops For $i = 0 To UBound($iniGBK)-1 while WinExists($iniGBK[$i], "") WinClose($iniGBK[$i], "") WEnd Next ; <======== END BLOCKED ELEMENTS ========> checkForIE() checkMouse() ; <======== BEGIN CONTROLS ========> $nMsg = GUIGetMsg() Switch $nMsg Case $controlStartDummy To $controlEndDummy MsgBox("","Test",$nMsg) Case $programs ShowMenu($jLockForm, $nMsg, $programsContext) Case $websites ShowMenu($jLockForm, $nMsg, $websitesContext) Case $manageIE listIEWindows() Case $ieManagementClose GuiSetState(@SW_HIDE,$ieManagementForm) EndSwitch ; <======== END CONTROLS ========> WEnd ; <======== BEGIN REGISTRY MODIFICATIONS ========> Func lockReg();clear ctrl alt del menus and task-manager RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "REG_DWORD", "00000001") ;remove task-manager RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "HideFastUserSwitching", "REG_DWORD", "00000001") ;remove switch user on ctrl alt del RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoLogoff", "REG_DWORD", "00000001") ;remove logoff from ctrl alt del RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoClose", "REG_DWORD", "00000001") ;remove shutdown from ctrl alt del RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableLockWorkstation", "REG_DWORD", "00000001") ;remove lock this computer from ctrl alt del RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableChangePassword", "REG_DWORD", "00000001") ;remove change a password from ctrl alt del RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoViewContextMenu", "REG_DWORD", "00000001") ;removes right click ability from explorer windows RegWrite("HKCU\Software\Policies\Microsoft\Internet Explorer\IEDevTools", "Disabled", "REG_DWORD", "00000001") ;disables IE Dev tools from F12 RegWrite("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions", "NoFileOpen", "REG_DWORD", "00000001") ;disables opening of new files within IE RegWrite("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions", "NoFileNew", "REG_DWORD", "00000001") ;disables opening of new browsers RegWrite("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions", "NoBrowserContextMenu", "REG_DWORD", "00000001") ;disables right click within IE RegWrite("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions", "NoViewSource", "REG_DWORD", "00000001") ;disables the viewing of website source code RegWrite("HKCU\Software\Policies\Microsoft\Internet Explorer\TabbedBrowsing", "Enabled", "REG_DWORD", "00000000") ;disables tabbed browsing RegWrite("HKCU\Software\Policies\Microsoft\Internet Explorer\TabbedBrowsing", "QuickTabsThreshold", "REG_DWORD", "00000000") ;sets max tabs to 0 RegWrite("HKCU\Software\Policies\Microsoft\Internet Explorer\ToolBars\Restrictions", "NoNavBar", "REG_DWORD", "00000001") ;disables navigation bar for all IE windows RegWrite("HKCU\Software\Microsoft\Internet Explorer\MINIE", "CommandBarEnabled", "REG_DWORD", "00000000") ;disables command bar EndFunc Func unlockReg();delete reg files RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr") RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "HideFastUserSwitching") RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoLogoff") RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoClose") RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableLockWorkstation") RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableChangePassword") RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoViewContextMenu") RegDelete("HKCU\Software\Policies\Microsoft\Internet Explorer\IEDevTools", "Disabled") RegDelete("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions", "NoFileOpen") RegDelete("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions", "NoFileNew") RegDelete("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions", "NoBrowserContextMenu") RegDelete("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions", "NoViewSource") RegDelete("HKCU\Software\Policies\Microsoft\Internet Explorer\TabbedBrowsing", "Enabled") RegDelete("HKCU\Software\Policies\Microsoft\Internet Explorer\TabbedBrowsing", "QuickTabsThreshold") RegDelete("HKCU\Software\Policies\Microsoft\Internet Explorer\ToolBars\Restrictions", "NoNavBar") RegDelete("HKCU\Software\Policies\Microsoft\Internet Explorer\ToolBars\Restrictions", "NoNavBar") RegDelete("HKCU\Software\Microsoft\Internet Explorer\MINIE", "CommandBarEnabled") EndFunc ; <======== END REGISTRY MODIFICATIONS ========> ; <======== BEGIN SYSTEM LOCK/UNLOCK ========> Func lockSystem() ;~ lockReg() ;~ While ProcessExists("explorer.exe") ;~ taskKill("explorer.exe", True, True) ;~ WEnd ;~ While ProcessExists("taskmgr.exe") ;~ taskKill("taskmgr.exe", True, True) ;~ WEnd HotKeySet("{f2}", "passEntry") EndFunc Func unlockSystem() ;~ unlockReg() ;~ Run("explorer.exe") EndFunc ; <======== END SYSTEM LOCK/UNLOCK ========> ; <======== BEGIN CONTEXT MENU ========> Func popMenus() $controlStartDummy = GuiCtrlCreateDummy() $programsDummy = GUICtrlCreateDummy() $programsContext = GUICtrlCreateContextMenu($programsDummy) For $i = 0 To UBound($iniGAP)-1 If $iniGAP[$i][1] <> "" Then Assign("mip"&$iniGAP[$i][0],GuiCtrlCreateMenuItem($iniGAP[$i][0],$programsContext)) EndIf Next $websitesDummy = GUICtrlCreateDummy() $websitesContext = GUICtrlCreateContextMenu($websitesDummy) For $i = 0 To UBound($iniGAW)-1 If $iniGAW[$i][1] <> "" Then Assign("miw"&$iniGAW[$i][0],GuiCtrlCreateMenuItem($iniGAW[$i][0],$websitesContext)) EndIf Next $controlEndDummy = GuiCtrlCreateDummy() EndFunc Func ShowMenu($hWnd, $CtrlID, $nContextID);Show a menu in a given GUI window which belongs to a given GUI ctrl Local $arPos, $x, $y Local $hMenu = GUICtrlGetHandle($nContextID) $arPos = ControlGetPos($hWnd, "", $CtrlID) $x = $arPos[0] $y = $arPos[1] + $arPos[3] ClientToScreen($hWnd, $x, $y) TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc Func ClientToScreen($hWnd, ByRef $x, ByRef $y);Convert the client (GUI) coordinates to screen (desktop) coordinates Local $stPoint = DllStructCreate("int;int") DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $y = DllStructGetData($stPoint, 2) $stPoint = 0; release Struct not really needed as it is a local EndFunc Func TrackPopupMenu($hWnd, $hMenu, $x, $y);Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc ; <======== END CONTEXT MENU ========> ; <======== BEGIN UNLOCK KEY SEQUENCE ========> Func passEntry() ;Seems Legit If @HotKeyPressed = "{f2}" Then $unlockChar = 0 HotKeySet($unlockPasswordArray[$unlockChar],"passEntry") Sleep(2000) HotKeySet($unlockPasswordArray[$unlockChar]) Else If $unlockChar < UBound($unlockPasswordArray) - 1 Then HotKeySet($unlockPasswordArray[$unlockChar]) $unlockChar += 1 HotKeySet($unlockPasswordArray[$unlockChar],"passEntry") Sleep(2000) HotKeySet($unlockPasswordArray[$unlockChar]) ElseIf $unlockChar = UBound($unlockPasswordArray) - 1 Then $unlockChar = 0 MsgBox(0, "", "UNLOCKED!") unlockSystem() Exit EndIf EndIf EndFunc ; <======== END UNLOCK KEY SEQUENCE ========> ; <======== BEGIN CUSTOM TASK KILLER FUNCTION ========> Func taskKill($procName, $force, $wait) If $wait Then If $force Then RunWait("taskkill /F /IM " & $procName, "", @SW_HIDE) Else RunWait("taskkill /IM " & $procName, "", @SW_HIDE) EndIf Else If $force Then Run("taskkill /F /IM " & $procName, "", @SW_HIDE) Else Run("taskkill /IM " & $procname, "", @SW_HIDE) EndIf EndIf EndFunc ; <======== END CUSTOM TASK KILLER FUNCTION ========> ; <======== BEGIN MENU ANIMATION FUNCTIONS ========> Func checkMouse() If MouseGetPos(0) <= 2 + $hotspotMargin And MouseGetPos(1) > (@DesktopHeight/2)-($jLockFormHeight/2) - $hotspotMargin And MouseGetPos(1) < (@DesktopHeight/2)-($jLockFormHeight/2) +$jLockFormHeight + $hotspotMargin And $menuExtended == False Then extendMenu() EndIf If MouseGetPos(0) >= $jLockFormWidth + $hotspotMargin Or MouseGetPos(1) < (@DesktopHeight/2)-($jLockFormHeight/2) - $hotspotMargin Or MouseGetPos(1) > (@DesktopHeight/2)-($jLockFormHeight/2) +$jLockFormHeight + $hotspotMargin And $menuExtended == True Then collapseMenu() EndIf EndFunc Func extendMenu() $menuExtended = True While $menuX < 0 $menuX += 2 WinMove("JLock","",$menuX,(@DesktopHeight/2)-($jLockFormHeight/2)) Sleep(5) WEnd EndFunc Func collapseMenu() $menuExtended = False While $menuX > -$jLockFormWidth+2 $menuX -= 2 WinMove("JLock","",$menuX,(@DesktopHeight/2)-($jLockFormHeight/2)) Sleep(5) WEnd EndFunc ; <======== BEGIN MENU ANIMATION FUNCTIONS ========> ; <======== BEGIN IE FUNCTIONS ========> Func checkForIE() If WinExists("[CLASS:IEFrame]") <> 0 And GUICtrlGetState($manageIE) == BitOR($GUI_DISABLE, $GUI_SHOW) Then GUICtrlSetState($manageIE, $GUI_ENABLE) ElseIf WinExists("[CLASS:IEFrame]") == 0 And GUICtrlGetState($manageIE) == BitOR($GUI_ENABLE, $GUI_SHOW) Then GUICtrlSetState($manageIE, $GUI_DISABLE) EndIf EndFunc Func listIEWindows() GUISetState(@SW_SHOW, $ieManagementForm) EndFunc ; <======== END IE FUNCTIONS ========>

The trouble lies in the first switch case. All the other switches cases work.  I am using an dummy controls to group an unknown number of controls.

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>