├── AddFolderShare.ahk ├── AddWindowsInboundFirewallRuleForhttpd.ahk ├── AdvanceToNextSlideshowWallpaper ├── README.txt ├── Windows7.ahk └── Windows8and10.ahk ├── BeepWhenPrintJobAddedForDefaultPrinter.ahk ├── CreateHardlinksFromSelectedExplorerFiles ├── CreateHardlinksFromSelectedExplorerFiles.ahk └── README.txt ├── GetPotPlayer64CurrentPlayingFilePath.ahk ├── GetResultsFromEverythingSearch.ahk ├── GetTaskbarVisibleWindows.ahk ├── GetWindowsMediaPlayerPlayState ├── GetWindowsMediaPlayerPlayState.ahk └── README.txt ├── GhostedMenuIconForHiddenFiles ├── GhostedMenuIconForHiddenFiles.ahk └── README.md ├── GoodbyeDPITray ├── GoodbyeDPITray.ahk ├── NoStdoutBuffering.dll ├── NoStdoutBuffering.zip ├── README.md └── off.ico ├── IFilterPDF ├── README.txt └── ifilter.ahk ├── InternetExplorerCaretBrowsingEnabledForPage.ahk ├── LICENSE ├── LaptopBrightnessSetter └── README.md ├── LoadAdBlockPlusForIEintoAHK.ahk ├── LogoffAllUsersExceptYou.ahk ├── MoveAHKGuiToDifferentWindows10VirtualDesktop.ahk ├── MultiFileProperties.ahk ├── OneDriveOnDemandSyncToggle ├── OneDriveOnDemandSyncToggle.ahk └── README.md ├── PopupMenuUtils.ahk ├── ProcessIsSuspended.ahk ├── README.md ├── SetGlobalWindowsTextToSpeechVoice.ahk ├── SetRestrictedProcessDacl.ahk ├── SetThemeFromdotThemeFile.ahk ├── SetWindows10LockScreenPicture ├── README.txt └── SetWindows10LockScreenPicture.ahk ├── ShowNetworkNames.ahk ├── ShowWindows10TrayClock.ahk ├── ThinkPadScripts ├── EnableTrackPointAndButtonsOnlyWhenFnIsHeld.ahk ├── LenovoBatterySetRegisterThresholds.ahk └── README.md ├── ToggleWindows10TabletMode.ahk ├── ToggleWindows10TabletOSK.ahk ├── WinHTTPFileDownloader ├── README.md └── WinHTTPFileDownloader.ahk ├── XPGetLeftAndRightChannelsVolume.ahk ├── XPSetLeftAndRightChannelsVolume.ahk └── startWindows10Calendar.ahk /AddFolderShare.ahk: -------------------------------------------------------------------------------- 1 | #NoTrayIcon 2 | #NoEnv 3 | Process, Priority, , A 4 | #SingleInstance Off 5 | NERR_Success := 0 6 | 7 | if (!A_IsAdmin) 8 | ExitApp 9 | 10 | ; This is the equivalent of "net share 1=C:\1 /GRANT:%USERNAME%,READ /GRANT:%USERNAME%,CHANGE /USERS:2 /CACHE:None" 11 | 12 | userName := A_UserName 13 | shi502_netname := "1" 14 | shi502_path := "C:\1" 15 | 16 | if (DllCall("Netapi32\NetShareCheck", "Ptr", 0, "WStr", shi502_netname, "UInt*", 0) == NERR_Success) ; if this succeeds, it means the folder is already shared 17 | ExitApp 18 | 19 | CSC_MASK_EXT := 0x2030, CSC_CACHE_NONE := 0x0030 20 | SECURITY_DESCRIPTOR_REVISION := 1, ACL_REVISION := 2 21 | ACCESS_READ := 0x01, ACCESS_WRITE := 0x02, ACCESS_CREATE := 0x04, ACCESS_EXEC := 0x08, ACCESS_DELETE := 0x10, ACCESS_ATRIB := 0x20 22 | ; thanks to ctusch: https://stackoverflow.com/a/17236838 23 | FILE_READ_DATA := FILE_LIST_DIRECTORY := 0x1 24 | FILE_EXECUTE := FILE_TRAVERSE := 0x20 25 | FILE_WRITE_DATA := FILE_ADD_FILE := 0x2 26 | FILE_APPEND_DATA := FILE_ADD_SUBDIRECTORY := 0x4 27 | SHARE_READ := FILE_LIST_DIRECTORY | FILE_READ_EA := 0x8 | FILE_TRAVERSE | FILE_READ_ATTRIBUTES := 0x80 | READ_CONTROL := 0x20000 | SYNCHRONIZE := 0x100000 28 | SHARE_CHANGE := FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_WRITE_EA := 0x10 | FILE_WRITE_ATTRIBUTES := 0x100 | DELETE := 0x10000 29 | SHARE_FULLCONTROL := FILE_DELETE_CHILD := 0x40 | WRITE_DAC := 0x40000 | WRITE_OWNER := 0x80000 30 | 31 | ; prepare SD with a DACL containing one ACE: your user gets Read and Change access to the share 32 | VarSetCapacity(SecurityDescriptor, 40, 0) 33 | if (!DllCall("advapi32\InitializeSecurityDescriptor", "Ptr", &SecurityDescriptor, "UInt", SECURITY_DESCRIPTOR_REVISION)) 34 | ExitApp 35 | cbAcl := 8 + (12 * 1) ; sizeof(ACL) + ((sizeof(ACCESS_ALLOWED_ACE)) * NUM_OF_ACES) 36 | DllCall("sechost\LookupAccountNameLocalW", "WStr", userName, "Ptr", 0, "UInt*", cbSid := 0, "Ptr", 0, "UInt*", cbDomain := 0, "UInt*", 0) 37 | if (A_LastError != 122) 38 | ExitApp 39 | VarSetCapacity(Sid, cbSid, 0), VarSetCapacity(domain, cbDomain) 40 | if (!DllCall("sechost\LookupAccountNameLocalW", "WStr", userName, "Ptr", &Sid, "UInt*", cbSid, "Ptr", &domain, "UInt*", cbDomain, "UInt*", 0)) 41 | ExitApp 42 | cbAcl += cbSid - 4 ; for (int i = 0; i < NUM_OF_ACES; i++) cbAcl += GetLengthSid(psids[i]) - sizeof(DWORD); // aka: - sizeof(ACE->SidStart) 43 | cbAcl := (cbAcl + (4 - 1)) & 0xfffffffc ; Align cbAcl to a DWORD 44 | if (VarSetCapacity(Acl, cbAcl, 0) != cbAcl) 45 | ExitApp 46 | if (!DllCall("advapi32\InitializeAcl", "Ptr", &Acl, "UInt", cbAcl, "UInt", ACL_REVISION)) 47 | ExitApp 48 | if (!DllCall("advapi32\AddAccessAllowedAce", "Ptr", &Acl, "UInt", ACL_REVISION, "UInt", SHARE_READ | SHARE_CHANGE, "Ptr", &Sid)) 49 | ExitApp 50 | if (!DllCall("advapi32\SetSecurityDescriptorDacl", "Ptr", &SecurityDescriptor, "Int", True, "Ptr", &Acl, "Int", False)) 51 | ExitApp 52 | 53 | ; prepare SHARE_INFO_502 struct 54 | VarSetCapacity(SHARE_INFO_502, 72, 0) 55 | NumPut(&shi502_netname, SHARE_INFO_502, 0, "Ptr") 56 | NumPut((shi502_permissions := ACCESS_READ | ACCESS_WRITE | ACCESS_CREATE | ACCESS_EXEC | ACCESS_DELETE | ACCESS_ATRIB), SHARE_INFO_502, 24, "UInt") 57 | NumPut((shi502_max_uses := 2), SHARE_INFO_502, 28, "UInt") 58 | NumPut(&shi502_path, SHARE_INFO_502, 40, "Ptr") 59 | NumPut(&(shi502_passwd := ""), SHARE_INFO_502, 48, "Ptr") 60 | NumPut(&SecurityDescriptor, SHARE_INFO_502, 64, "Ptr") 61 | 62 | if (DllCall("Netapi32\NetShareAdd", "Ptr", 0, "UInt", 502, "Ptr", &SHARE_INFO_502, "Ptr", 0, "UInt") == NERR_Success) { 63 | ; disable caching 64 | if (DllCall("Netapi32\NetShareGetInfo", "Ptr", 0, "WStr", shi502_netname, "UInt", 1005, "Ptr*", SHARE_INFO_1005, "UInt") == NERR_Success) { 65 | NumPut((shi1005_flags := (NumGet(SHARE_INFO_1005+0,, "UInt") & ~CSC_MASK_EXT) | CSC_CACHE_NONE), SHARE_INFO_1005+0,, "UInt") 66 | DllCall("Netapi32\NetShareSetInfo", "Ptr", 0, "WStr", shi502_netname, "UInt", 1005, "Ptr", SHARE_INFO_1005, "Ptr", 0, "UInt") 67 | DllCall("Netapi32\NetApiBufferFree", "Ptr", SHARE_INFO_1005) 68 | } 69 | } -------------------------------------------------------------------------------- /AddWindowsInboundFirewallRuleForhttpd.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | xammpPath := A_ScriptDir . "\xampp" 4 | httpd := xammpPath . "\apache\bin\httpd.exe" 5 | 6 | if (FileExist(httpd) && A_OSVersion != "WIN_XP" && A_IsAdmin) { 7 | try { 8 | FwPolicy2 := ComObjCreate("HNetCfg.FwPolicy2") 9 | ruleAlreadyExists := False 10 | Rules := FwPolicy2.Rules 11 | for rule in Rules 12 | if (rule.ApplicationName = httpd) { 13 | ruleAlreadyExists := True 14 | break 15 | } 16 | if (!ruleAlreadyExists) { 17 | NewRule := ComObjCreate("HNetCfg.FWRule"), NewRuleUdp := ComObjCreate("HNetCfg.FWRule") 18 | NewRule.Description := NewRule.Name := "httpd.exe" 19 | NewRule.ApplicationName := Format("{:L}", httpd) ; for some reason, the paths are made lower-case by Windows when it adds a firewall rule itself 20 | NewRule.Protocol := NET_FW_IP_PROTOCOL_TCP := 6 21 | NewRule.RemoteAddresses := NewRule.LocalAddresses := NewRule.RemoteAddresses := NewRule.RemotePorts := "*" 22 | NewRule.Direction := NET_FW_RULE_DIR_IN := 1 23 | NewRule.InterfaceTypes := "All" 24 | NewRule.Enabled := True 25 | NewRule.Profiles := NET_FW_PROFILE2_PRIVATE := 0x2 | NET_FW_PROFILE2_PUBLIC := 0x4 ; | NET_FW_PROFILE2_DOMAIN := 0x1 / NET_FW_PROFILE2_ALL := 0x7fffffff 26 | NewRule.Action := NET_FW_ACTION_ALLOW := 1 27 | 28 | NewRuleUdp.Description := NewRuleUdp.Name := NewRule.Name 29 | NewRuleUdp.ApplicationName := NewRule.ApplicationName 30 | NewRuleUdp.Protocol := NET_FW_IP_PROTOCOL_UDP := 17 31 | NewRuleUdp.RemoteAddresses := NewRuleUdp.LocalAddresses := NewRuleUdp.RemoteAddresses := NewRuleUdp.RemotePorts := NewRule.RemotePorts 32 | NewRuleUdp.Direction := NewRule.Direction 33 | NewRuleUdp.InterfaceTypes := NewRule.InterfaceTypes 34 | NewRuleUdp.Enabled := NewRule.Enabled 35 | NewRuleUdp.Profiles := NewRule.Profiles 36 | NewRuleUdp.Action := NewRule.Action 37 | 38 | Rules.Add(NewRule), Rules.Add(NewRuleUdp) 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /AdvanceToNextSlideshowWallpaper/README.txt: -------------------------------------------------------------------------------- 1 | Scripts to advance to next background slideshow picture in the background upon pressing Windows + n 2 | 3 | For Windows 8 and 10, this is a simple affair, thanks to the built-in interface for doing so. 4 | 5 | For Windows 7, this is a different matter entirely. As there is no documented interface for this, this uses ShellContextMenu to display the Desktop right-click menu invisibly in AutoHotkey's process where it selects the "next slideshow background" option. 6 | Far more resource consuming and slower. Because loading a ton of shell DLLs into AutoHotkey brings up the memory usage to at least 20 MB, the Windows 7 script is configured to restart 10 seconds after Windows + n was last pressed. -------------------------------------------------------------------------------- /AdvanceToNextSlideshowWallpaper/Windows7.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 3 | SetBatchLines, -1 4 | ListLines, Off 5 | #KeyHistory 0 6 | 7 | #n:: 8 | ShellContextMenu("Desktop", 1) 9 | SetTimer, EmptySet, -10000 10 | return 11 | 12 | EmptySet: 13 | Run "%A_AhkPath%" /restart "%A_ScriptFullPath%" 14 | return 15 | 16 | ; Remake for unicode of Sean's ShellContextMenu by Deo: http://www.autohotkey.com/board/topic/65563-ahk-l-shell-context-menu/ 17 | ; ANSI fixes and porting of fragman's additions of directly launching idn and debugging (http://www.autohotkey.com/board/topic/20376-invoking-directly-contextmenu-of-files-and-folders/page-4#entry303574) by qwerty12 18 | ShellContextMenu(sPath, idn := "", win_hwnd := 0, ShellContextMenuDebug := false) 19 | { 20 | if (!sPath) 21 | return 22 | pIShellFolder := 0 23 | pIContextMenu := 0 24 | idnValid := false 25 | if idn is Integer 26 | idnValid := true 27 | 28 | if (!idnValid && !win_hwnd) { 29 | Gui, SHELL_CONTEXT:New, +hwndwin_hwnd 30 | Gui, Show 31 | } 32 | 33 | if (spath == "Desktop") { 34 | DllCall("shell32\SHGetDesktopFolder", "PtrP", pIShellFolder) 35 | DllCall(VTable(pIShellFolder, 8), "Ptr", pIShellFolder, "Ptr", 0, "Ptr", GUID4String(IID_IContextMenu,"{000214E4-0000-0000-C000-000000000046}"), "PtrP", pIContextMenu) ; CreateViewObject 36 | } else { 37 | If sPath Is Not Integer 38 | DllCall("shell32\SHParseDisplayName", "WStr", A_IsUnicode ? sPath : StrGet(&sPath,, "utf-8"), "Ptr", 0, "PtrP", pidl, "UInt", 0, "UIntP", 0) ;This function is the preferred method to convert a string to a pointer to an item identifier list (PIDL). 39 | Else 40 | DllCall("shell32\SHGetFolderLocation", "Ptr", 0, "Int", sPath, "Ptr", 0, "Uint", 0, "PtrP", pidl) 41 | DllCall("shell32\SHBindToParent", "Ptr", pidl, "Ptr", GUID4String(IID_IShellFolder,"{000214E6-0000-0000-C000-000000000046}"), "PtrP", pIShellFolder, "PtrP", pidlChild) 42 | DllCall(VTable(pIShellFolder, 10), "Ptr", pIShellFolder, "Ptr", 0, "Uint", 1, "Ptr*", pidlChild, "Ptr", GUID4String(IID_IContextMenu,"{000214E4-0000-0000-C000-000000000046}"), "Ptr", 0, "Ptr*", pIContextMenu) ;IShellFolder->GetUIObjectOf 43 | CoTaskMemFree(pidl) 44 | } 45 | ObjRelease(pIShellFolder), pIShellFolder := 0 46 | 47 | hMenu := DllCall("CreatePopupMenu") 48 | idnMIN := 1 ;idnValid Or debug ? 1 : 3 49 | ;IContextMenu->QueryContextMenu 50 | ;http://msdn.microsoft.com/en-us/library/bb776097%28v=VS.85%29.aspx 51 | DllCall(VTable(pIContextMenu, 3), "Ptr", pIContextMenu, "Ptr", hMenu, "UInt", 0, "UInt", idnMIN, "UInt", 0x7FFF, "UInt", 0x100) ;CMF_EXTENDEDVERBS 52 | 53 | if (!idnValid) { 54 | ComObjError(0) 55 | global pIContextMenu2 := ComObjQuery(pIContextMenu, IID_IContextMenu2:="{000214F4-0000-0000-C000-000000000046}") 56 | global pIContextMenu3 := ComObjQuery(pIContextMenu, IID_IContextMenu3:="{BCFCE0A0-EC17-11D0-8D10-00A0C90F2719}") 57 | e := A_LastError ;GetLastError() 58 | ComObjError(1) 59 | if (e != 0) 60 | goTo, StopContextMenu 61 | global WPOld := DllCall(A_PtrSize == 8 ? "SetWindowLongPtr" : "SetWindowLong", "Ptr", win_hwnd ? win_hwnd : A_ScriptHwnd, "Int", -4, "Ptr", RegisterCallback("ShellContextMenuWindowProc"), "Ptr") 62 | DllCall("GetCursorPos", "Int64*", pt) 63 | DllCall("InsertMenu", "Ptr", hMenu, "UInt", 0, "UInt", 0x0400|0x800, "Ptr", 2, "Ptr", 0) 64 | DllCall("InsertMenu", "Ptr", hMenu, "UInt", 0, "UInt", 0x0400|0x002, "Ptr", 1, "Ptr", &sPath) 65 | 66 | idn := DllCall("TrackPopupMenuEx", "Ptr", hMenu, "Uint", 0x0100|0x0001, "Int", pt << 32 >> 32, "Int", pt >> 32, "Ptr", win_hwnd ? win_hwnd : A_ScriptHwnd, "Ptr", 0) 67 | } 68 | 69 | /* 70 | typedef struct _CMINVOKECOMMANDINFOEX { 71 | DWORD cbSize; 0 72 | DWORD fMask; 4 73 | HWND hwnd; 8 74 | LPCSTR lpVerb; 8+A_PtrSize 75 | LPCSTR lpParameters; 8+2*A_PtrSize 76 | LPCSTR lpDirectory; 8+3*A_PtrSize 77 | int nShow; 8+4*A_PtrSize 78 | DWORD dwHotKey; 12+4*A_PtrSize 79 | HANDLE hIcon; 16+4*A_PtrSize 80 | LPCSTR lpTitle; 16+5*A_PtrSize 81 | LPCWSTR lpVerbW; 16+6*A_PtrSize 82 | LPCWSTR lpParametersW; 16+7*A_PtrSize 83 | LPCWSTR lpDirectoryW; 16+8*A_PtrSize 84 | LPCWSTR lpTitleW; 16+9*A_PtrSize 85 | POINT ptInvoke; 16+10*A_PtrSize 86 | } CMINVOKECOMMANDINFOEX, *LPCMINVOKECOMMANDINFOEX; 87 | http://msdn.microsoft.com/en-us/library/bb773217%28v=VS.85%29.aspx 88 | */ 89 | struct_size := 16+11*A_PtrSize 90 | VarSetCapacity(pici, struct_size, 0) 91 | NumPut(struct_size, pici, 0, "Uint") ;cbSize 92 | NumPut((A_IsUnicode ? 0x00004000 : 0) | 0x20000000 | 0x00100000, pici, 4, "UInt") ;fMask 93 | NumPut(win_hwnd ? win_hwnd : A_ScriptHwnd, pici, 8, "UPtr") ;hwnd 94 | NumPut(1, pici, 8+4*A_PtrSize, "Uint") ;nShow 95 | NumPut(idn-idnMIN, pici, 8+A_PtrSize, "UPtr") ;lpVerb 96 | if (A_IsUnicode) 97 | NumPut(idn-idnMIN, pici, 16+6*A_PtrSize, "UPtr") ;lpVerbW 98 | if (!idnValid) 99 | NumPut(pt, pici, 16+10*A_PtrSize, "UPtr") ;ptInvoke 100 | 101 | DllCall(VTable(pIContextMenu, 4), "Ptr", pIContextMenu, "Ptr", &pici) ; InvokeCommand 102 | 103 | if (!idnValid) { 104 | if (ShellContextMenuDebug) { 105 | VarSetCapacity(sName, 522) 106 | DllCall(VTable(pIContextMenu, 5), "Ptr", pIContextMenu, "UInt", idn-idnMIN, "UInt", 0x00000000, "UIntP", 0, "Str", sName, "Uint", 260) ; GetCommandString 107 | if (A_IsUnicode) 108 | sName := StrGet(&sName,, "utf-8") 109 | OutputDebug, idn: %idn% command string: %sName% 110 | } 111 | DllCall("GlobalFree", "Ptr", DllCall("SetWindowLongPtr", "Ptr", win_hwnd ? win_hwnd : A_ScriptHwnd, "Int", -4, "Ptr", WPOld, "UPtr")) 112 | } 113 | StopContextMenu: 114 | DllCall("DestroyMenu", "Ptr", hMenu) 115 | if (!idnValid) { 116 | ObjRelease(pIContextMenu3), ObjRelease(pIContextMenu2) 117 | pIContextMenu3 := pIContextMenu2 := WPOld := 0 118 | } 119 | ObjRelease(pIContextMenu), pIContextMenu := 0 120 | Gui, SHELL_CONTEXT:Destroy 121 | VarSetCapacity(pici, 0) 122 | return idn 123 | } 124 | 125 | ShellContextMenuWindowProc(hWnd, nMsg, wParam, lParam) 126 | { 127 | Global pIContextMenu2, pIContextMenu3, WPOld 128 | If pIContextMenu3 { ;IContextMenu3->HandleMenuMsg2 129 | If !DllCall(VTable(pIContextMenu3, 7), "Ptr", pIContextMenu3, "Uint", nMsg, "Ptr", wParam, "Ptr", lParam, "Ptr*", lResult) 130 | return lResult 131 | } 132 | Else If pIContextMenu2 { ;IContextMenu2->HandleMenuMsg 133 | If !DllCall(VTable(pIContextMenu2, 6), "Ptr", pIContextMenu2, "Uint", nMsg, "Ptr", wParam, "Ptr", lParam) 134 | return 0 135 | } 136 | return DllCall("user32.dll\CallWindowProcW", "Ptr", WPOld, "Ptr", hWnd, "Uint", nMsg, "Ptr", wParam, "Ptr", lParam) 137 | } 138 | 139 | VTable(ppv, idx) 140 | { 141 | Return NumGet(NumGet(ppv+0)+A_PtrSize*idx) 142 | } 143 | 144 | GUID4String(ByRef CLSID, String) 145 | { 146 | VarSetCapacity(CLSID, 16, 0) 147 | return DllCall("ole32\CLSIDFromString", "WStr", String, "Ptr", &CLSID) >= 0 ? &CLSID : "" 148 | } 149 | 150 | CoTaskMemFree(pv) 151 | { 152 | return DllCall("ole32\CoTaskMemFree", "Ptr", pv) 153 | } 154 | -------------------------------------------------------------------------------- /AdvanceToNextSlideshowWallpaper/Windows8and10.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | #n:: 4 | if (pDesktopWallpaper && DllCall(NumGet(NumGet(pDesktopWallpaper+0)+16*A_PtrSize), "Ptr", pDesktopWallpaper, "Ptr", 0, "UInt", 0) != -2147023174) ; IDesktopWallpaper::AdvanceSlideshow - https://msdn.microsoft.com/en-us/library/windows/desktop/hh706947(v=vs.85).aspx 5 | return 6 | ObjRelease(pDesktopWallpaper) 7 | if ((pDesktopWallpaper := ComObjCreate("{C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD}", "{B92B56A9-8B55-4E14-9A89-0199BBB6F93B}"))) 8 | goto %A_ThisHotkey% 9 | return -------------------------------------------------------------------------------- /BeepWhenPrintJobAddedForDefaultPrinter.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv 2 | PRINTER_CHANGE_ADD_JOB := 0x00000100 ; FindFirstPrinterChangeNotification 3 | INVALID_HANDLE_VALUE := -1 4 | 5 | ; MsgWaitForMultipleObjectsEx constants: 6 | WAIT_OBJECT_0 := 0x00000000, WAIT_FAILED := INFINITE := 0xFFFFFFFF, MWMO_ALERTABLE := 0x0002, MWMO_INPUTAVAILABLE := 0x0004 7 | QS_INPUT := (QS_MOUSE := (QS_MOUSEMOVE := 0x0002 | QS_MOUSEBUTTON := 0x0004)) | QS_KEY := 0x0001 | QS_RAWINPUT := 0x0400 ; QS_TOUCH and QS_POINTER are included on Windows 8+ AFAIK in WinUser.h 8 | QS_ALLINPUT := QS_INPUT | QS_POSTMESSAGE := 0x0008 | QS_TIMER := 0x0010 | QS_PAINT := 0x0020 | QS_HOTKEY := 0x0080 | QS_SENDMESSAGE := 0x0040 9 | 10 | hModWinspool := DllCall("LoadLibrary", "Str", "winspool.drv", "Ptr") 11 | 12 | ; Get default printer name 13 | if (DllCall("winspool.drv\GetDefaultPrinter", "Ptr", 0, "UInt*", cchDefPrinter)) 14 | ExitApp 1 15 | VarSetCapacity(defaultPrinterName, cchDefPrinter * (A_IsUnicode + 1)) 16 | DllCall("winspool.drv\GetDefaultPrinter", "Ptr", &defaultPrinterName, "UInt*", cchDefPrinter) 17 | 18 | if (!DllCall("winspool.drv\OpenPrinter", "Ptr", &defaultPrinterName, "Ptr*", hDefaultPrinter, "Ptr", 0)) 19 | ExitApp 1 20 | OnExit("cleanup") 21 | 22 | if ((hDefaultPrinterChange := DllCall("winspool.drv\FindFirstPrinterChangeNotification", "Ptr", hDefaultPrinter, "UInt", PRINTER_CHANGE_ADD_JOB, "UInt", PRINTER_NOTIFY_CATEGORY_2D := 0x000000, "Ptr", 0, "Ptr")) == INVALID_HANDLE_VALUE) 23 | ExitApp 1 24 | 25 | bKeepMonitoring := True 26 | while (bKeepMonitoring) { 27 | ; Bastardised from Lexikos' FileExtract 28 | r := DllCall("MsgWaitForMultipleObjectsEx", "UInt", 1, "Ptr*", hDefaultPrinterChange, "UInt", INFINITE, "UInt", QS_ALLINPUT, "UInt", MWMO_ALERTABLE | MWMO_INPUTAVAILABLE, "UInt"), Sleep 0 29 | if (!bKeepMonitoring || r == WAIT_FAILED) { 30 | break 31 | } else if (r == WAIT_OBJECT_0) { 32 | if ((DllCall("winspool.drv\FindNextPrinterChangeNotification", "Ptr", hDefaultPrinterChange, "UInt*", dwChange, "Ptr", 0, "Ptr", 0)) && dwChange & PRINTER_CHANGE_ADD_JOB) 33 | SoundBeep ; replace this for something stronger 34 | } 35 | } 36 | 37 | cleanup() 38 | { 39 | global watchPrinter, hDefaultPrinter, hDefaultPrinterChange, hModWinspool, bKeepMonitoring, INVALID_HANDLE_VALUE 40 | ;Critical On 41 | bKeepMonitoring := False 42 | ;PostMessage, 0x0000,,,, ahk_id %A_ScriptHwnd% 43 | ;Sleep -1 44 | if (hDefaultPrinterChange != INVALID_HANDLE_VALUE) 45 | DllCall("winspool.drv\FindClosePrinterChangeNotification", "Ptr", hDefaultPrinterChange), hDefaultPrinterChange := INVALID_HANDLE_VALUE 46 | if (hDefaultPrinter) 47 | DllCall("winspool.drv\ClosePrinter", "Ptr", hDefaultPrinter), hDefaultPrinter := 0 48 | if (hModWinspool) 49 | DllCall("FreeLibrary", "Ptr", hModWinspool), hModWinspool := 0 50 | ;Critical Off 51 | } -------------------------------------------------------------------------------- /CreateHardlinksFromSelectedExplorerFiles/CreateHardlinksFromSelectedExplorerFiles.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | ; #Warn ; Enable warnings to assist with detecting common errors. 3 | SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 4 | SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 5 | #SingleInstance Force 6 | 7 | ; apparently not needed for hard links 8 | /* 9 | ; From AutoHotkey's Process docpage 10 | Process, Exist ; sets ErrorLevel to the PID of this running script 11 | ; Get the handle of this script with PROCESS_QUERY_INFORMATION (0x0400) 12 | h := DllCall("OpenProcess", "UInt", 0x0400, "Int", false, "UInt", ErrorLevel, "Ptr") 13 | ; Open an adjustable access token with this process (TOKEN_ADJUST_PRIVILEGES = 32) 14 | DllCall("Advapi32.dll\OpenProcessToken", "Ptr", h, "UInt", 32, "PtrP", t) 15 | VarSetCapacity(ti, 16, 0) ; structure of privileges 16 | NumPut(1, ti, 0, "UInt") ; one entry in the privileges array... 17 | ; Retrieves the locally unique identifier of the debug privilege: 18 | DllCall("Advapi32.dll\LookupPrivilegeValue", "Ptr", 0, "Str", "SeCreateSymbolicLinkPrivilege", "Int64P", luid) 19 | NumPut(luid, ti, 4, "Int64") 20 | NumPut(2, ti, 12, "UInt") ; enable this privilege: SE_PRIVILEGE_ENABLED = 2 21 | ; Update the privileges of this process with the new access token: 22 | r := DllCall("Advapi32.dll\AdjustTokenPrivileges", "Ptr", t, "Int", false, "Ptr", &ti, "UInt", 0, "Ptr", 0, "Ptr", 0) 23 | DllCall("CloseHandle", "Ptr", t) ; close this access token handle to save memory 24 | DllCall("CloseHandle", "Ptr", h) ; close this process handle to save memory 25 | */ 26 | 27 | #If ((expWnd := validExplorerWindow(WinExist("A"), expWndType))) 28 | ^+c:: 29 | hardLinkSourceFiles := getExplorerSelectedFiles(expWnd, expWndType) 30 | if ((hardlinkSourceCount := hardLinkSourceFiles.MaxIndex())) 31 | TrayTip,, % hardlinkSourceCount . (hardlinkSourceCount == 1 ? " file" : " files") . " selected for hard linking" 32 | return 33 | 34 | ^+v:: 35 | if ((hardLinkSourceFiles.MaxIndex()) && (expPath := getExplorerWindowPath(expWnd, expWndType))) { 36 | expPath .= "\" 37 | for idx, file in hardLinkSourceFiles 38 | if (!DllCall("CreateHardLink", "Str", expPath . file.Name, "Str", file.Path, "Ptr", 0)) 39 | hardLinkSourceFiles.RemoveAt(idx) 40 | selectFilesInFolder(expWnd, expWndType, hardLinkSourceFiles) 41 | hardLinkSourceFiles := "" 42 | } 43 | #If 44 | return 45 | 46 | validExplorerWindow(hwnd, ByRef outType) 47 | { 48 | outType := 0 49 | if (hwnd) { 50 | WinGetClass wndClass, ahk_id %hwnd% 51 | if (wndClass == "CabinetWClass") 52 | outType := 1 53 | else if (wndClass == "Progman" || wndClass == "WorkerW") 54 | outType := 2 55 | 56 | if (outType) 57 | return hwnd 58 | } 59 | return 0 60 | } 61 | 62 | getExplorerWindowPath(hwnd, hwndType) 63 | { 64 | ; qwerty12's https://autohotkey.com/boards/viewtopic.php?f=5&t=31135 65 | static IID_IShellFolder, STRRET, path, SIGDN_FILESYSPATH := 0x80058000 66 | if (!VarSetCapacity(IID_IShellFolder)) 67 | VarSetCapacity(IID_IShellFolder, 16), DllCall("ole32\CLSIDFromString", "WStr", "{000214E6-0000-0000-C000-000000000046}", "Ptr", &IID_IShellFolder) 68 | ,VarSetCapacity(STRRET, 272), VarSetCapacity(path, 262 * (!!A_IsUnicode + 1)) 69 | 70 | if (hwndType == 2) 71 | return A_Desktop 72 | else if (hwndType == 1) { 73 | shellWindows := ComObjCreate("Shell.Application").Windows 74 | for window in shellWindows { 75 | if (window.hwnd == hwnd) { 76 | try { 77 | isp := ComObjQuery(window, "{6d5140c1-7436-11ce-8034-00aa006009fa}") 78 | tlb := ComObjQuery(isp, "{4C96BE40-915C-11CF-99D3-00AA004AE837}", "{000214E2-0000-0000-C000-000000000046}") 79 | if (DllCall(NumGet(NumGet(tlb+0)+15*A_PtrSize), "Ptr", tlb, "Ptr*", isv) < 0) 80 | throw 81 | ifv := ComObjQuery(isv, "{cde725b0-ccc9-4519-917e-325d72fab4ce}") 82 | if (DllCall(NumGet(NumGet(ifv+0)+5*A_PtrSize), "Ptr", ifv, "Ptr", &IID_IShellFolder, "Ptr*", isf) < 0) 83 | throw 84 | if (DllCall(NumGet(NumGet(isf+0)+11*A_PtrSize), "Ptr", isf, "Ptr", 0, "UInt", SIGDN_FILESYSPATH, "Ptr", &STRRET) < 0) 85 | throw 86 | if (DllCall("shlwapi\StrRetToBuf", "Ptr", &STRRET, "Ptr", 0, "Str", path, "UInt", 260)) 87 | throw 88 | return path 89 | } catch { 90 | return 0 91 | } finally { 92 | for _, obj in [isf, ifv, isv, tlb, isp] 93 | if (obj) 94 | ObjRelease(obj) 95 | } 96 | } 97 | } 98 | } 99 | 100 | return 0 101 | } 102 | 103 | getExplorerSelectedFiles(hwnd, hwndType) 104 | { 105 | ret := 0 106 | 107 | items := getFolderDocument(hwnd, hwndType).SelectedItems 108 | 109 | if (items.Count) { 110 | ret := [] 111 | for Item in items 112 | if (!Item.IsFolder) ; you can't hardlink folders 113 | ret.push({Path: Item.Path, Name: Item.Name}) 114 | } 115 | 116 | return ret 117 | } 118 | 119 | getFolderDocument(hwnd, hwndType) 120 | { 121 | ;Based on Rapte_of_Suzaku's https://autohotkey.com/board/topic/60985-get-paths-of-selected-items-in-an-explorer-window/ and Lexikos' https://autohotkey.com/boards/viewtopic.php?t=9618 122 | static _hwnd 123 | Document := 0 124 | shellWindows := ComObjCreate("Shell.Application").Windows 125 | 126 | if (hwndType == 1) { 127 | for window in shellWindows { 128 | if (window.hwnd == hwnd) { 129 | Document := window.Document 130 | break 131 | } 132 | } 133 | } else if (hwndType == 2) { 134 | if (!VarSetCapacity(_hwnd)) 135 | VarSetCapacity(_hwnd, 4, 0) 136 | desktop := shellWindows.FindWindowSW(0, "", 8, ComObj(0x4003, &_hwnd), 1) 137 | Document := desktop.Document 138 | } 139 | 140 | return Document 141 | } 142 | 143 | selectFilesInFolder(hwnd, hwndType, namesOfFiles) 144 | { 145 | ; Based on Lexikos' https://autohotkey.com/boards/viewtopic.php?t=9618 146 | 147 | Document := getFolderDocument(hwnd, hwndType) 148 | items := Document.SelectedItems 149 | Loop % items.Count 150 | Document.SelectItem(items.Item(A_Index-1), 0) 151 | for _, file in namesOfFiles 152 | Document.SelectItem(items.Item(file.Name), 1) 153 | } -------------------------------------------------------------------------------- /CreateHardlinksFromSelectedExplorerFiles/README.txt: -------------------------------------------------------------------------------- 1 | * Select files in an open Explorer window, press Ctrl + Shift + C 2 | * Open your destination window and press Ctrl + Shift + V to have hardlinks of your files placed there -------------------------------------------------------------------------------- /GetPotPlayer64CurrentPlayingFilePath.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | ; Play a file in PotPlayer and press q at the window 4 | ; Credits: 5 | ; * The Old New Thing & Lexikos for the MsgWaitForMultipleObjectsEx code 6 | ; * http://cafe.daum.net/pot-tool/N88T/65 for providing an English version of the SDK 7 | 8 | class PotPlayerCurrentFile 9 | { 10 | static _WM_COPYDATA := 0x004A, _POT_COMMAND := _WM_USER := 0x0400, _POT_GET_PLAYFILE_NAME := 0x6020 11 | 12 | GetFullPath(hwnd, dwTimeout) 13 | { 14 | static MsgWaitForMultipleObjectsEx := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "user32.dll", "Ptr"), "AStr", "MsgWaitForMultipleObjectsEx", "Ptr") 15 | fn := "" 16 | 17 | WinGetClass, clazz, ahk_id %hwnd% 18 | if (InStr(clazz, "PotPlayer")) { 19 | r := 0xFFFFFFFF 20 | ,this.hEvent := DllCall("CreateEvent", "Ptr", 0, "Int", True, "Int", False, "Ptr", 0, "Ptr") 21 | ,this.potPlayerHwnd := hwnd 22 | ,this.cdReceiver := ObjBindMethod(this, "_On_WM_COPYDATA") 23 | ,OnMessage(this._WM_COPYDATA, this.cdReceiver, -1) 24 | 25 | if (this._MessagePotPlayer(dwTimeout)) { 26 | dwStart := A_TickCount 27 | while ((dwElapsed := A_TickCount - dwStart) < dwTimeout) { 28 | r := DllCall(MsgWaitForMultipleObjectsEx, "UInt", 1, "Ptr*", this.hEvent, "UInt", dwTimeout - dwElapsed, "UInt", 0x4FF, "UInt", 0x4, "UInt") 29 | if (r == 0 || r == 0xFFFFFFFF || r == 258) 30 | break 31 | Sleep -1 32 | } 33 | ;OutputDebug % A_ThisFunc . ": " . (A_TickCount - dwStart) . " milliseconds have elapsed" 34 | } 35 | 36 | OnMessage(this._WM_COPYDATA, this.cdReceiver, 0) ,this.cdReceiver := "" 37 | ,DllCall("CloseHandle", "Ptr", this.hEvent), this.hEvent := 0 38 | if (r == 0) 39 | fn := this.PotPlayerFilename 40 | } 41 | 42 | this := "" 43 | return fn 44 | } 45 | 46 | _MessagePotPlayer(ByRef Timeout := 5000) 47 | { 48 | Critical On 49 | ;dwStart := A_TickCount 50 | PostMessage, % this._POT_COMMAND, % this._POT_GET_PLAYFILE_NAME, %A_ScriptHwnd%,, % "ahk_id " . this.potPlayerHwnd,,,, %Timeout% 51 | ;Timeout -= A_TickCount - dwStart 52 | ret := ErrorLevel == 0 53 | Critical Off 54 | return ret 55 | } 56 | 57 | _On_WM_COPYDATA(wParam, lParam, msg, hwnd) 58 | { 59 | if (lParam && hwnd == A_ScriptHwnd && wParam == this.potPlayerHwnd && NumGet(lParam+0,, "UPtr") == this._POT_GET_PLAYFILE_NAME) { 60 | StringLength := NumGet(lParam+0, A_PtrSize, "UInt") 61 | ,StringAddress := NumGet(lParam+0, 2*A_PtrSize, "Ptr") 62 | ,this.PotPlayerFilename := StrGet(StringAddress, StringLength, "UTF-8") 63 | ,DllCall("SetEvent", "Ptr", this.hEvent) 64 | return True 65 | } 66 | return False 67 | } 68 | } 69 | 70 | PotPlayer64_GetCurrentFilePath(hwnd, replyTimeout := 1100) 71 | { 72 | return PotPlayerCurrentFile.GetFullPath(hwnd, replyTimeout) 73 | } 74 | 75 | #If ((hwnd := WinActive("ahk_class PotPlayer64"))) 76 | q::MsgBox % PotPlayer64_GetCurrentFilePath(hwnd) 77 | #If -------------------------------------------------------------------------------- /GetResultsFromEverythingSearch.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | ; Copy of https://www.voidtools.com/support/everything/sdk/c/ 4 | ; Place Everything32.dll and Everything64.dll from the SDK (https://www.voidtools.com/downloads/) into the same directory as this script 5 | EverythingDll := "Everything" . (A_PtrSize == 8 ? "64" : "32") . ".dll" 6 | EverythingMod := DllCall("LoadLibrary", "Str", A_ScriptDir . "\" . EverythingDll, "Ptr") 7 | DllCall(EverythingDll . "\Everything_SetSearch", "Str", "Taskmgr.exe") 8 | DllCall(EverythingDll . "\Everything_Query", "Int", True) 9 | Loop % DllCall(EverythingDll . "\Everything_GetNumResults", "UInt") 10 | MsgBox % DllCall(EverythingDll . "\Everything_GetResultFileName", "UInt", A_Index - 1, "Str") . " [" . DllCall(EverythingDll . "\Everything_GetResultPath", "UInt", A_Index - 1, "Str") . "]" 11 | DllCall(EverythingDll . "\Everything_Reset") 12 | DllCall("FreeLibrary", "Ptr", EverythingMod) -------------------------------------------------------------------------------- /GetTaskbarVisibleWindows.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv 2 | #Include 3 | 4 | if (A_ScriptName == "GetTaskbarVisibleWindows.ahk") { 5 | Menu, Tray, NoIcon 6 | SetBatchLines -1 7 | ListLines, Off 8 | for _, hwnd in GetTaskbarVisibleWindows() { 9 | WinGetClass wndClass, ahk_id %hwnd% 10 | WinGetTitle wndTitle, ahk_id %hwnd% 11 | x .= wndClass . " - " . (wndTitle ? wndTitle : Format("{:x}", hwnd)) . "`n" 12 | /* ScClose("ahk_id " . hwnd) 13 | */ 14 | } 15 | MsgBox % x 16 | ExitApp 17 | } 18 | 19 | ; Based off code from the following projects: 20 | ; * https://sourceforge.net/projects/taskswitchxp/ 21 | ; * https://github.com/kvakulo/Switcheroo 22 | 23 | GetTaskbarVisibleWindows(limit:=0, checkDisabled:=True, checkEmptyTitle:=False 24 | ,checkNoActivate:=True, checkImmediateOwnerVisibility:=True 25 | ,checkITaskListDeleted:=True, useAudioRouterAlgo:=True) 26 | { 27 | static sevenOrBelow := A_OSVersion ~= "WIN_(7|XP|VISTA)", rect, PropEnumProcEx := 0, cleanup := {base: {__Delete: "GetTaskbarVisibleWindows"}} 28 | static WS_DISABLED := 0x08000000, WS_EX_TOOLWINDOW := 0x00000080, WS_EX_APPWINDOW := 0x00040000, WS_EX_CONTROLPARENT := 0x00010000, WS_EX_NOREDIRECTIONBITMAP := 0x00200000, WS_EX_NOACTIVATE := 0x08000000 29 | static GA_ROOTOWNER := 3, GW_OWNER := 4, DWMWA_CLOAKED := 14 30 | 31 | if (PropEnumProcEx && A_EventInfo == PropEnumProcEx && checkNoActivate >= 4096 && IsWindow(limit)) { 32 | if (checkDisabled && StrGet(checkDisabled) == "ApplicationViewCloakType") { 33 | NumPut(checkEmptyTitle != 1, checkNoActivate+0, "Int") 34 | return False 35 | } 36 | return True 37 | } 38 | 39 | if (!cleanup) { 40 | if (PropEnumProcEx) 41 | DllCall("GlobalFree", "Ptr", PropEnumProcEx, "Ptr"), PropEnumProcEx := 0 42 | return 43 | } 44 | 45 | if (!VarSetCapacity(rect)) { 46 | VarSetCapacity(rect, 16) 47 | if (!sevenOrBelow) 48 | PropEnumProcEx := RegisterCallback(A_ThisFunc, "Fast", 4) 49 | } 50 | 51 | shell := 0 ; DllCall("GetShellWindow", "Ptr") 52 | 53 | ret := [] 54 | prevDetectHiddenWindows := A_DetectHiddenWindows 55 | 56 | DetectHiddenWindows Off 57 | 58 | WinGet id, list,,, Program Manager 59 | Loop %id% { 60 | hwnd := id%A_Index% 61 | 62 | if (limit && limit == ret.MaxIndex()) 63 | break 64 | 65 | if (checkEmptyTitle) { 66 | WinGetTitle wndTitle, ahk_id %hwnd% 67 | if (!wndTitle) 68 | continue 69 | } 70 | 71 | if (checkDisabled) { 72 | WinGet dwStyle, Style, ahk_id %hwnd% 73 | if (dwStyle & WS_DISABLED) 74 | continue 75 | } 76 | 77 | if (checkITaskListDeleted && DllCall("GetProp", "Ptr", hwnd, "Str", "ITaskList_Deleted", "Ptr")) 78 | continue 79 | 80 | if (DllCall("GetWindowRect", "Ptr", hwnd, "Ptr", &rect) && !DllCall("IsRectEmpty", "Ptr", &rect)) { 81 | if (!shell) { 82 | hwndRootOwner := DllCall("GetAncestor", "Ptr", hwnd, "UInt", GA_ROOTOWNER, "Ptr") 83 | } else { 84 | hwndTmp := hwnd 85 | Loop { 86 | hwndRootOwner := hwndTmp 87 | hwndTmp := DllCall("GetWindow", "Ptr", hwndTmp, "UInt", GW_OWNER, "Ptr") 88 | } until (!hwndTmp || hwndTmp == shell) 89 | } 90 | 91 | WinGet dwStyleEx, ExStyle, ahk_id %hwndRootOwner% 92 | if (hwnd != hwndRootOwner) 93 | WinGet dwStyleEx2, ExStyle, ahk_id %hwnd% 94 | else 95 | dwStyleEx2 := dwStyleEx 96 | 97 | hasAppWindow := dwStyleEx2 & WS_EX_APPWINDOW 98 | if (checkNoActivate) 99 | if ((dwStyleEx2 & WS_EX_NOACTIVATE) && !hasAppWindow) 100 | continue 101 | 102 | if (checkImmediateOwnerVisibility) { 103 | hwndOwner := DllCall("GetWindow", "Ptr", hwnd, "UInt", GW_OWNER, "Ptr") 104 | if (!(!hwndOwner || !DllCall("IsWindowVisible", "Ptr", hwndRootOwner))) 105 | continue 106 | } 107 | 108 | if (!(dwStyleEx & WS_EX_TOOLWINDOW) || hasAppWindow || (!(dwStyleEx2 & WS_EX_TOOLWINDOW) && dwStyleEx2 & WS_EX_CONTROLPARENT)) { 109 | if (useAudioRouterAlgo && !is_main_window(hwnd)) 110 | continue 111 | if (!sevenOrBelow) { 112 | WinGetClass wndClass, ahk_id %hwnd% 113 | if (wndClass == "Windows.UI.Core.CoreWindow") 114 | continue 115 | if (wndClass == "ApplicationFrameWindow") { 116 | hasAppropriateApplicationViewCloakType := !PropEnumProcEx 117 | if (PropEnumProcEx) 118 | DllCall("EnumPropsEx", "Ptr", hwnd, "Ptr", PropEnumProcEx, "Ptr", &hasAppropriateApplicationViewCloakType) 119 | if (!hasAppropriateApplicationViewCloakType) 120 | continue 121 | } else { 122 | if (dwStyleEx & WS_EX_NOREDIRECTIONBITMAP) 123 | continue 124 | if (!DllCall("dwmapi\DwmGetWindowAttribute", "Ptr", hwndRootOwner, "UInt", DWMWA_CLOAKED, "UInt*", isCloaked, "Ptr", 4) && isCloaked) 125 | continue 126 | } 127 | } 128 | ret.push(hwnd) 129 | } 130 | } 131 | } 132 | 133 | DetectHiddenWindows %prevDetectHiddenWindows% 134 | return ret 135 | } 136 | 137 | ; Based off https://github.com/audiorouterdev/audio-router 138 | is_main_window(handle) 139 | { 140 | static WS_CHILD := 0x40000000, WS_OVERLAPPED := 0x00000000, WS_POPUP := 0x80000000 141 | static WS_EX_WINDOWEDGE := 0x00000100, WS_EX_CLIENTEDGE := 0x00000200, WS_EX_DLGMODALFRAME := 0x00000001, WS_EX_OVERLAPPEDWINDOW := WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE 142 | WinGet Style, Style, ahk_id %handle% 143 | WinGet Style, ExStyle, ahk_id %handle% 144 | 145 | if (Style & WS_CHILD) 146 | return FALSE 147 | 148 | i := 0 149 | if(Style & WS_OVERLAPPED) 150 | i++ 151 | if(Style & WS_POPUP) 152 | { 153 | i-- 154 | if(DllCall("GetParent", "Ptr", handle)) 155 | i-- 156 | } 157 | if(ExStyle & WS_EX_OVERLAPPEDWINDOW) 158 | i++ 159 | if(ExStyle & WS_EX_CLIENTEDGE) 160 | i-- 161 | if(ExStyle & WS_EX_DLGMODALFRAME) 162 | i-- 163 | return (i >= 0) 164 | } 165 | 166 | ; Based off https://stackoverflow.com/a/4688414 167 | GetTaskbarVisibleWindows_IsWindowVisible(m_hWnd) 168 | { 169 | static GetWindowRect := PopupMenuUtils_user32_handle("GetWindowRect"), rgn := 0, rtView, RectInRegion := DllCall("GetProcAddress", Ptr, DllCall("GetModuleHandle", Str, "gdi32.dll", "Ptr"), AStr, "RectInRegion", "Ptr"), cleanup := {base: {__Delete: "GetTaskbarVisibleWindows_IsWindowVisible"}} 170 | 171 | if (!cleanup) { 172 | if (rgn) 173 | DllCall("Gdi32\DeleteObject", "Ptr", rgn), rgn := 0 174 | return 175 | } 176 | 177 | if (!rgn) 178 | VarSetCapacity(rtView, 16), VarSetCapacity(rtDesktop, 16), DllCall(GetWindowRect, "Ptr", DllCall("GetDesktopWindow", "Ptr"), "Ptr", &rtDesktop), rgn := DllCall("Gdi32\CreateRectRgn", "Int", NumGet(rtDesktop, 0, "Int"), "Int", NumGet(rtDesktop, 4, "Int"), "Int", NumGet(rtDesktop, 8, "Int"), "Int", NumGet(rtDesktop, 12, "Int"), "Ptr") 179 | 180 | return DllCall(GetWindowRect, "Ptr", m_hWnd, "Ptr", &rtView) && DllCall(RectInRegion, "Ptr", rgn, "Ptr", &rtView) 181 | } 182 | -------------------------------------------------------------------------------- /GetWindowsMediaPlayerPlayState/GetWindowsMediaPlayerPlayState.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | #SingleInstance Off 3 | 4 | Process, Exist, wmplayer.exe 5 | if (!ErrorLevel) { 6 | MsgBox Run Windows Media Player first. Exiting 7 | ExitApp 8 | } 9 | 10 | wmp := ComObjCreate("WMPlayer.OCX") 11 | 12 | rms := IWMPRemoteMediaServices_CreateInstance() 13 | ocs := ComObjQuery(rms, "{00000118-0000-0000-C000-000000000046}") 14 | 15 | ole := ComObjQuery(wmp, "{00000112-0000-0000-C000-000000000046}") 16 | DllCall(NumGet(NumGet(ole+0)+3*A_PtrSize), "Ptr", ole, "Ptr", ocs) 17 | 18 | states := {0: "Undefined", 1: "Stopped", 2: "Paused", 3: "Playing"} 19 | state := states[wmp.playState] 20 | 21 | DllCall(NumGet(NumGet(ole+0)+3*A_PtrSize), "Ptr", ole, "Ptr", 0) 22 | for _, obj in [ole, ocs, rms] 23 | ObjRelease(obj) 24 | wmp := "" 25 | 26 | MsgBox %state% 27 | 28 | ; --- 29 | 30 | IWMPRemoteMediaServices_CreateInstance() 31 | { 32 | global IWMPRemoteMediaServices_size := ((A_PtrSize + 4) * 4) + 4 33 | static vtblUnk, vtblRms, vtblIsp, vtblOls 34 | , vtblPtrs := 0 35 | 36 | if (!VarSetCapacity(vtblUnk)) { 37 | extfuncs := ["QueryInterface", "AddRef", "Release"] 38 | 39 | VarSetCapacity(vtblUnk, extfuncs.Length() * A_PtrSize) 40 | 41 | for i, name in extfuncs 42 | NumPut(RegisterCallback("IUnknown_" . name), vtblUnk, (i-1) * A_PtrSize) 43 | } 44 | if (!VarSetCapacity(vtblRms)) { 45 | extfuncs := ["GetServiceType", "GetApplicationName", "GetScriptableObject", "GetCustomUIMode"] 46 | 47 | VarSetCapacity(vtblRms, (3 + extfuncs.Length()) * A_PtrSize) 48 | DllCall("ntdll\RtlMoveMemory", "Ptr", &vtblRms, "Ptr", &vtblUnk, "Ptr", A_PtrSize * 3) 49 | 50 | for i, name in extfuncs 51 | NumPut(RegisterCallback("IWMPRemoteMediaServices_" . name, "Fast"), vtblRms, (2+i) * A_PtrSize) 52 | } 53 | if (!VarSetCapacity(vtblIsp)) { 54 | VarSetCapacity(vtblIsp, 4 * A_PtrSize) 55 | DllCall("ntdll\RtlMoveMemory", "Ptr", &vtblIsp, "Ptr", &vtblUnk, "Ptr", A_PtrSize * 3) 56 | NumPut(RegisterCallback("IServiceProvider_QueryService", "Fast"), vtblIsp, A_PtrSize * 3) 57 | } 58 | if (!VarSetCapacity(vtblOls)) { 59 | extfuncs := ["SaveObject", "GetMoniker", "GetContainer", "ShowObject", "OnShowWindow", "RequestNewObjectLayout"] 60 | VarSetCapacity(vtblOls, (3 + extfuncs.Length()) * A_PtrSize) 61 | DllCall("ntdll\RtlMoveMemory", "Ptr", &vtblOls, "Ptr", &vtblUnk, "Ptr", A_PtrSize * 3) 62 | 63 | for i, name in extfuncs 64 | NumPut(RegisterCallback("IOleClientSite_" . name, "Fast"), vtblOls, (2+i) * A_PtrSize) 65 | } 66 | if (!vtblPtrs) 67 | vtblPtrs := [&vtblUnk, &vtblRms, &vtblIsp, &vtblOls] 68 | 69 | pObj := DllCall("GlobalAlloc", "UInt", 0x0000, "Ptr", IWMPRemoteMediaServices_size, "Ptr") 70 | for i, ptr in vtblPtrs { 71 | off := (A_PtrSize * (i - 1)) + (4 * (i - 1)) 72 | NumPut(ptr, pObj+0, off, "Ptr") 73 | NumPut(off, pObj+0, off + A_PtrSize, "UInt") 74 | } 75 | NumPut(1, pObj+0, IWMPRemoteMediaServices_size - 4, "UInt") 76 | 77 | return pObj 78 | } 79 | 80 | IUnknown_QueryInterface(this_, riid, ppvObject) 81 | { 82 | static IID_IUnknown, IID_IWMPRemoteMediaServices, IID_IServiceProvider, IID_IOleClientSite 83 | if (!VarSetCapacity(IID_IUnknown)) 84 | VarSetCapacity(IID_IUnknown, 16), VarSetCapacity(IID_IWMPRemoteMediaServices, 16), VarSetCapacity(IID_IServiceProvider, 16), VarSetCapacity(IID_IOleClientSite, 16) 85 | ,DllCall("ole32\CLSIDFromString", "WStr", "{00000000-0000-0000-C000-000000000046}", "Ptr", &IID_IUnknown) 86 | ,DllCall("ole32\CLSIDFromString", "WStr", "{CBB92747-741F-44FE-AB5B-F1A48F3B2A59}", "Ptr", &IID_IWMPRemoteMediaServices) 87 | ,DllCall("ole32\CLSIDFromString", "WStr", "{6d5140c1-7436-11ce-8034-00aa006009fa}", "Ptr", &IID_IServiceProvider) 88 | ,DllCall("ole32\CLSIDFromString", "WStr", "{00000118-0000-0000-C000-000000000046}", "Ptr", &IID_IOleClientSite) 89 | 90 | if (DllCall("ole32\IsEqualGUID", "Ptr", riid, "Ptr", &IID_IUnknown)) { 91 | off := NumGet(this_+0, A_PtrSize, "UInt") 92 | NumPut(this_ - off, ppvObject+0, "Ptr") 93 | IUnknown_AddRef(this_) 94 | return 0 ; S_OK 95 | } 96 | 97 | if (DllCall("ole32\IsEqualGUID", "Ptr", riid, "Ptr", &IID_IWMPRemoteMediaServices)) { 98 | off := NumGet(this_+0, A_PtrSize, "UInt") 99 | NumPut((this_ - off)+(A_PtrSize + 4), ppvObject+0, "Ptr") 100 | IUnknown_AddRef(this_) 101 | return 0 ; S_OK 102 | } 103 | 104 | if (DllCall("ole32\IsEqualGUID", "Ptr", riid, "Ptr", &IID_IServiceProvider)) { 105 | off := NumGet(this_+0, A_PtrSize, "UInt") 106 | NumPut((this_ - off)+((A_PtrSize + 4) * 2), ppvObject+0, "Ptr") 107 | IUnknown_AddRef(this_) 108 | return 0 ; S_OK 109 | } 110 | 111 | if (DllCall("ole32\IsEqualGUID", "Ptr", riid, "Ptr", &IID_IOleClientSite)) { 112 | off := NumGet(this_+0, A_PtrSize, "UInt") 113 | NumPut((this_ - off)+((A_PtrSize + 4) * 3), ppvObject+0, "Ptr") 114 | IUnknown_AddRef(this_) 115 | return 0 ; S_OK 116 | } 117 | 118 | NumPut(0, ppvObject+0, "Ptr") 119 | return 0x80004002 ; E_NOINTERFACE 120 | } 121 | 122 | IUnknown_AddRef(this_) 123 | { 124 | global IWMPRemoteMediaServices_size 125 | off := NumGet(this_+0, A_PtrSize, "UInt") 126 | iunk := this_-off 127 | NumPut((_refCount := NumGet(iunk+0, IWMPRemoteMediaServices_size - 4, "UInt") + 1), iunk+0, IWMPRemoteMediaServices_size - 4, "UInt") 128 | return _refCount 129 | } 130 | 131 | IUnknown_Release(this_) { 132 | global IWMPRemoteMediaServices_size 133 | off := NumGet(this_+0, A_PtrSize, "UInt") 134 | iunk := this_-off 135 | _refCount := NumGet(iunk+0, IWMPRemoteMediaServices_size - 4, "UInt") 136 | if (_refCount > 0) { 137 | NumPut(--_refCount, iunk+0, IWMPRemoteMediaServices_size - 4, "UInt") 138 | if (_refCount == 0) 139 | DllCall("GlobalFree", "Ptr", iunk, "Ptr") 140 | } 141 | return _refCount 142 | } 143 | 144 | IWMPRemoteMediaServices_GetServiceType(this_, pbstrType) 145 | { 146 | NumPut(DllCall("oleaut32\SysAllocString", "WStr", "Remote", "Ptr"), pbstrType+0, "Ptr") 147 | return 0 148 | } 149 | 150 | IWMPRemoteMediaServices_GetApplicationName(this_, pbstrName) 151 | { 152 | NumPut(DllCall("oleaut32\SysAllocString", "WStr", "qwerty12's long-ass AHK script for something that should've been simple: the case for using foobar2000", "Ptr"), pbstrName+0, "Ptr") 153 | return 0 154 | } 155 | 156 | IWMPRemoteMediaServices_GetScriptableObject(this_, pbstrName, ppDispatch) 157 | { 158 | return 0x80004001 159 | } 160 | IWMPRemoteMediaServices_GetCustomUIMode(this_, pbstrFile) 161 | { 162 | return 0x80004001 163 | } 164 | 165 | IServiceProvider_QueryService(this_, guidService, riid, ppvObject) 166 | { 167 | return IUnknown_QueryInterface(this_, riid, ppvObject) 168 | } 169 | 170 | IOleClientSite_SaveObject(this_) 171 | { 172 | return 0x80004001 173 | } 174 | 175 | IOleClientSite_GetMoniker(this_, dwAssign, dwWhichMoniker, ppmk) 176 | { 177 | return 0x80004001 178 | } 179 | 180 | IOleClientSite_GetContainer(this_, ppContainer) 181 | { 182 | NumGet(0, ppContainer+0, "Ptr") 183 | return 0x80004002 184 | } 185 | 186 | IOleClientSite_ShowObject(this_) 187 | { 188 | return 0x80004001 189 | } 190 | 191 | IOleClientSite_OnShowWindow(this_, fShow) 192 | { 193 | return 0x80004001 194 | } 195 | 196 | IOleClientSite_RequestNewObjectLayout(this_) 197 | { 198 | return 0x80004001 199 | } -------------------------------------------------------------------------------- /GetWindowsMediaPlayerPlayState/README.txt: -------------------------------------------------------------------------------- 1 | This script tells you the current playing state of a running Windows Media Player instance. I put this script here because of how complex WMP makes it to tell you its state. I hope this might help somebody. 2 | 3 | Resources used: 4 | * The "remoteHost" example of https://github.com/Microsoft/Windows-classic-samples 5 | * manuell's post here: https://stackoverflow.com/a/19571308 6 | 7 | Tested with Windows 10 1703 / WMP 12 / AutoHotkey x64 1.1.26.01 -------------------------------------------------------------------------------- /GhostedMenuIconForHiddenFiles/GhostedMenuIconForHiddenFiles.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | ; #Warn ; Enable warnings to assist with detecting common errors. 3 | SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 4 | SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 5 | 6 | ; Show a menu of the first n files matching a pattern, and their icons. 7 | pattern = %A_ScriptDir%\* 8 | n = 15 9 | 10 | VarSetCapacity(ICONINFO, (cbICONINFO := 32)), VarSetCapacity(BITMAP, 32) 11 | ; Allocate memory for a SHFILEINFOW struct. 12 | VarSetCapacity(fileinfo, fisize := A_PtrSize + 688) 13 | 14 | Loop, Files, %pattern%, FD 15 | { 16 | ; Add a menu item for each file. 17 | Menu F, Add, %A_LoopFileName%, donothing 18 | 19 | ; Get the file's icon. 20 | if DllCall("shell32\SHGetFileInfoW", "wstr", A_LoopFileFullPath 21 | , "uint", 0, "ptr", &fileinfo, "uint", fisize, "uint", 0x100 | SHGFI_ATTRIBUTES := 0x000000800) 22 | { 23 | hicon := NumGet(fileinfo, 0, "ptr") 24 | dwAttributes := NumGet(fileinfo, A_PtrSize + 4, "UInt") 25 | if (dwAttributes & SFGAO_GHOSTED := 0x00008000) { 26 | if (DllCall("GetIconInfo", "Ptr", hicon, "Ptr", &ICONINFO)) { 27 | hbmColor := NumGet(ICONINFO, cbICONINFO - A_PtrSize, "Ptr") 28 | hbmMask := NumGet(ICONINFO, cbICONINFO - (A_PtrSize * 2), "Ptr") 29 | 30 | if (DllCall("GetObject", "Ptr", hbmColor, "Int", A_PtrSize == 8 ? 32 : 24, "Ptr", &BITMAP)) { 31 | width := NumGet(BITMAP, 4, "Int") 32 | height := NumGet(BITMAP, 8, "Int") 33 | 34 | if ((im := IL_Create(1, 0, True))) { 35 | if ((idx := DllCall("ImageList_Add", "Ptr", im, "Ptr", hbmColor, "Ptr", hbmMask)) != -1) { 36 | rgbBk := DllCall("GetSysColor", "UInt", COLOR_MENU := 4, "UInt") 37 | rgbFg := RGB(255, 255, 255) 38 | scrdc := DllCall("GetDC", "Ptr", A_ScriptHwnd, "Ptr") 39 | hdc := DllCall("CreateCompatibleDC", "Ptr", scrdc, "Ptr") 40 | 41 | DllCall("SelectObject", "Ptr", hdc, "Ptr", hbmMask, "Ptr") 42 | if (DllCall("ImageList_DrawEx", "Ptr", im, "Int", idx, "Ptr", hdc, "Int", 2, "Int", 0, "Int", width, "Int", height, "UInt", rgbBk, "UInt", rgbFg, "UInt", ILD_MASK := 0x00000010 | ILD_BLEND50 := 0x00000004)) { 43 | DllCall("SelectObject", "Ptr", hdc, "Ptr", hbmColor, "Ptr") 44 | DllCall("ImageList_DrawEx", "Ptr", im, "Int", idx, "Ptr", hdc, "Int", 0, "Int", 0, "Int", width, "Int", height, "UInt", rgbBk, "UInt", rgbFg, "UInt", ILD_BLEND50 := 0x00000004) 45 | DllCall("SelectObject", "Ptr", hdc, "Ptr", 0, "Ptr") 46 | 47 | DllCall("DestroyIcon", "Ptr", hicon) 48 | hicon := DllCall("CreateIconIndirect", "Ptr", &ICONINFO, "Ptr") 49 | } 50 | DllCall("DeleteDC", "Ptr", hdc) 51 | DllCall("ReleaseDC", "Ptr", 0, "Ptr", scrdc) 52 | } 53 | IL_Destroy(im) 54 | } 55 | } 56 | 57 | if (hbmColor) 58 | DllCall("DeleteObject", "Ptr", hbmColor) 59 | 60 | if (hbmMask) 61 | DllCall("DeleteObject", "Ptr", hbmMask) 62 | } 63 | } 64 | ; Set the menu item's icon. 65 | Menu F, Icon, %A_Index%&, HICON:%hicon% 66 | ; Because we used ":" and not ":*", the icon will be automatically 67 | ; freed when the program exits or if the menu or item is deleted. 68 | } 69 | } 70 | until A_Index = n 71 | Menu F, Show 72 | donothing: 73 | return 74 | 75 | RGB(r,g,b) 76 | { 77 | return (r)|(g << 8)|(b << 16) 78 | } -------------------------------------------------------------------------------- /GhostedMenuIconForHiddenFiles/README.md: -------------------------------------------------------------------------------- 1 | NOTE: You should use iPhilip's script [here](https://autohotkey.com/boards/viewtopic.php?f=5&t=41587#p189771) which does the same thing with far less code. 2 | 3 | This script uses the code from https://autohotkey.com/docs/misc/ImageHandles.htm to show a list of files that are in the same folder it's running from, with the addition of applying a similar effect to hidden files' icons as Explorer does. -------------------------------------------------------------------------------- /GoodbyeDPITray/GoodbyeDPITray.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | SetBatchLines, -1 3 | ListLines, Off 4 | SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 5 | #KeyHistory 0 6 | #NoTrayIcon 7 | #SingleInstance Force 8 | 9 | main(), return 10 | 11 | main() 12 | { 13 | global exe := A_ScriptDir . "\goodbyedpi.exe", arguments := "-e 8 -s" 14 | , gdpiOutput, processHandleSwitch := " /procToTerminateHandle:", processWaitTimeout := 2000 15 | , startTorStr := "Start &Tor", stopTorStr := "Stop &Tor" 16 | 17 | cmdLine := DllCall("GetCommandLineW", "WStr") 18 | if (InStr(cmdLine, processHandleSwitch)) { 19 | ; I can't stop child processes from fucking inheriting the IGNORE_CTRL_C flag from the PEB, so have said flag set in a child process which is then summarily ended 20 | if ((hProcess := StrSplit(cmdLine, processHandleSwitch, " """"")[2])) { 21 | if ((gdpiPid := DllCall("GetProcessId", "Ptr", hProcess, "UInt"))) 22 | _StopGoodbyeDPI(hProcess, gdpiPid) 23 | DllCall("CloseHandle", "Ptr", hProcess) 24 | } 25 | 26 | ExitApp 27 | } 28 | 29 | if not (A_IsAdmin or RegExMatch(cmdLine, " /restart(?!\S)")) 30 | { 31 | try 32 | { 33 | if !A_IsCompiled 34 | Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%" 35 | else 36 | Run *RunAs "%A_ScriptFullPath%" /restart 37 | } 38 | ExitApp 39 | } 40 | 41 | if (!VarSetCapacity(gdpiOutput)) 42 | VarSetCapacity(gdpiOutput, 8192) 43 | 44 | Menu, Tray, NoStandard 45 | Menu, Tray, Add, &Start/Stop GoodbyeDPI, ToggleGoodbyeDPI 46 | Menu, Tray, Add, View GoodbyeDPI output, ShowGoodbyeDPIOutput 47 | Menu, Tray, Add 48 | Menu, Tray, Add, %startTorStr%, Tor 49 | Menu, Tray, Add 50 | Menu, Tray, Add, Edit This Script, Edit 51 | Menu, Tray, Add, E&xit, ExitApp 52 | Menu, Tray, Default, 2& 53 | OnMessage(0x404, "AHK_NOTIFYICON") 54 | 55 | setTrayState(False) 56 | ,OnExit("AtExit") 57 | Menu, Tray, Icon 58 | } 59 | 60 | AtExit(ExitReason, ExitCode) 61 | { 62 | global ctx, processWaitTimeout, stopTorStr 63 | OnExit(A_ThisFunc, 0) 64 | Tor(stopTorStr) 65 | if (IsObject(ctx)) 66 | if (DllCall("WaitForSingleObject", "Ptr", NumGet(ctx["pi"]+0,0,"Ptr"), "UInt", 0) == 258) { 67 | processWaitTimeout := 500 68 | ,ToggleGoodbyeDPI(True, False) 69 | } 70 | AHK_TERMNOTIFY(0) 71 | if (ExitReason == "Shutdown") 72 | UnloadWinDivert() 73 | return 0 74 | } 75 | 76 | ToggleGoodbyeDPI(useWTFMS := True, useTerminateSubprocess := True) 77 | { 78 | static cbStartupInfoEx := A_PtrSize == 8 ? 112 : 72 79 | global exe, arguments, ctx, twGlobal := 0, gdpiOutput, processHandleSwitch, processWaitTimeout 80 | 81 | if (IsObject(ctx)) { 82 | hProcess := NumGet(ctx["pi"]+0,0,"Ptr") 83 | if (useTerminateSubprocess) { 84 | useTerminateSubprocess := False 85 | ,DllCall("InitializeProcThreadAttributeList", "Ptr", 0, "UInt", 1, "UInt", 0, "Ptr*", size) 86 | if (size) { 87 | VarSetCapacity(AttributeList, size + A_PtrSize) 88 | 89 | if (DllCall("InitializeProcThreadAttributeList", "Ptr", &AttributeList, "UInt", 1, "UInt", 0, "Ptr*", size)) { 90 | NumPut(hProcess, AttributeList, size, "Ptr") 91 | if (DllCall("UpdateProcThreadAttribute", "Ptr", &AttributeList, "UInt", 0, "UPtr", 0x00020002, "Ptr", &AttributeList+size, "Ptr", A_PtrSize, "Ptr", 0, "Ptr", 0)) { 92 | if (DllCall("SetHandleInformation", "Ptr", hProcess, "UInt", 0x00000001, "UInt", 0x00000001)) { 93 | VarSetCapacity(pi, 24, 0) 94 | ,VarSetCapacity(info, cbStartupInfoEx, 0) 95 | ,NumPut(cbStartupInfoEx, info,, "UInt") 96 | ,NumPut(&AttributeList, info, cbStartupInfoEx - A_PtrSize, "Ptr") 97 | 98 | if (DllCall("CreateProcess", "Str", A_AhkPath, "Str", """" . A_AhkPath . """" . " /force """ . A_ScriptFullPath . """" . processHandleSwitch . hProcess, "Ptr", 0, "Ptr", 0, "Int", True, "UInt", 0x00080000, "Ptr", 0, "Ptr", 0, "Ptr", &info, "Ptr", &pi)) { 99 | Menu, Tray, Disable, 1& 100 | hSubProcess := NumGet(pi,, "Ptr") 101 | ,DllCall("CloseHandle", "Ptr", NumGet(pi, A_PtrSize, "Ptr")) 102 | ,MsgSleep(hSubProcess, processWaitTimeout) 103 | ,DllCall("CloseHandle", "Ptr", hSubProcess) 104 | ,useTerminateSubprocess := True 105 | } 106 | } 107 | } 108 | DllCall("DeleteProcThreadAttributeList", "Ptr", &AttributeList) 109 | } 110 | } 111 | } 112 | if (!useTerminateSubprocess) 113 | _StopGoodbyeDPI(hProcess, NumGet(ctx["pi"]+0, 2 * A_PtrSize, "UInt")) 114 | } else { 115 | Menu, Tray, Disable, 1& 116 | gdpiOutput := "" 117 | ,ctx := StdoutToVar_CreateProcess("""" . exe . """" . (arguments ? A_Space . arguments : ""),, A_ScriptDir . "\NoStdoutBuffering.dll") 118 | 119 | if (IsObject(ctx)) { 120 | twGlobal := TermWait_WaitForProcTerm(A_ScriptHwnd, NumGet(ctx["pi"]+0,0,"Ptr")) 121 | ,setTrayState(True) 122 | ,GetGoodbyeDPIOutput() 123 | } else { 124 | MsgBox Process creation failed 125 | Menu, Tray, Enable, 1& 126 | return 127 | } 128 | } 129 | if (useWTFMS) 130 | WTFMS() 131 | else 132 | WinActivate % "ahk_id " . GetTaskbarVisibleWindows(1)[1] 133 | } 134 | 135 | ; From kon 136 | AHK_NOTIFYICON(wParam, lParam) 137 | { 138 | global stopTorStr, startTorStr 139 | if (lParam == 0x205) { 140 | try Menu, Tray, Rename, 4&, % Tor("") ? stopTorStr : startTorStr 141 | } else if (lParam == 0x0207) { 142 | ToggleGoodbyeDPI(False) 143 | } 144 | } 145 | 146 | Tor(mode) 147 | { 148 | global stopTorStr, startTorStr 149 | static SERVICE_STATUS, SERVICE_NO_CHANGE := 0xffffffff 150 | if (!VarSetCapacity(SERVICE_STATUS)) 151 | VarSetCapacity(SERVICE_STATUS, 28) 152 | 153 | if (mode == stopTorStr) 154 | stopTor := True 155 | else if (mode == startTorStr) 156 | startTor := True 157 | else 158 | getStatus := True 159 | 160 | if ((HSC := DllCall("Advapi32.dll\OpenSCManager", "Ptr", 0, "Ptr", 0, "UInt", 0x000F0000 | 0x0001, "UPtr"))) { 161 | Loop { 162 | if ((HSV := DllCall("Advapi32.dll\OpenService", "Ptr", HSC, "Str", "tor", "UInt", 0x000F0000 | 0x0002 | 0x0004 | 0x0010 | 0x0020, "UPtr"))) { 163 | if (getStatus) { 164 | if (DllCall("Advapi32.dll\QueryServiceStatus", "Ptr", HSV, "Ptr", &SERVICE_STATUS)) 165 | dwCurrentState := NumGet(SERVICE_STATUS, 4, "UInt") 166 | } else { 167 | ; toggle: if (dwCurrentState == 0x00000004) 168 | if (stopTor) { 169 | DllCall("Advapi32.dll\ChangeServiceConfig", "Ptr", HSV, "UInt", SERVICE_NO_CHANGE, "UInt", 4, "UInt", SERVICE_NO_CHANGE, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0) 170 | DllCall("Advapi32.dll\ControlService", "Ptr", HSV, "UInt", 0x00000001, "Ptr", &SERVICE_STATUS) 171 | } 172 | else if (startTor) { 173 | if (A_Index == 1) { 174 | DllCall("Advapi32.dll\ChangeServiceConfig", "Ptr", HSV, "UInt", SERVICE_NO_CHANGE, "UInt", 3, "UInt", SERVICE_NO_CHANGE, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0) 175 | } else { 176 | DllCall("Advapi32.dll\StartService", "Ptr", HSV, "UInt", 0, "Ptr", 0) 177 | DllCall("Advapi32.dll\ChangeServiceConfig", "Ptr", HSV, "UInt", SERVICE_NO_CHANGE, "UInt", 4, "UInt", SERVICE_NO_CHANGE, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0) 178 | } 179 | } 180 | } 181 | DllCall("Advapi32.dll\CloseServiceHandle", "Ptr", HSV) 182 | } 183 | if (!startTor || A_Index != 1) 184 | break 185 | } 186 | DllCall("Advapi32.dll\CloseServiceHandle", "Ptr", HSC) 187 | } 188 | 189 | return dwCurrentState == 0x00000004 190 | } 191 | 192 | _StopGoodbyeDPI(hProcess, gdpiPid) 193 | { 194 | global processWaitTimeout 195 | 196 | shouldKill := True 197 | if (DllCall("AttachConsole", "UInt", gdpiPid)) { 198 | DllCall("SetConsoleCtrlHandler", "Ptr", 0, "Int", True) 199 | ,generated := DllCall("GenerateConsoleCtrlEvent", "UInt", 0, "UInt", 0) 200 | ,DllCall("FreeConsole") 201 | if (generated) 202 | shouldKill := DllCall("WaitForSingleObject", "Ptr", hProcess, "UInt", processWaitTimeout, "UInt") != 0 203 | } 204 | if (shouldKill) { 205 | if ((ExitProcess := ProcAddressFromRemoteProcess(hProcess, "kernel32.dll", "ExitProcess"))) { 206 | if ((hRemoteThread := DllCall("CreateRemoteThread", "Ptr", hProcess, "Ptr", 0, "Ptr", 0, "Ptr", ExitProcess, "Ptr", 1, "UInt", 0, "Ptr", 0, "Ptr"))) { 207 | DllCall("CloseHandle", "Ptr", hRemoteThread) 208 | shouldKill := DllCall("WaitForSingleObject", "Ptr", hProcess, "UInt", processWaitTimeout, "UInt") != 0 209 | } 210 | } 211 | } 212 | if (shouldKill) 213 | DllCall("TerminateProcess", "Ptr", hProcess, "UInt", 0) 214 | } 215 | 216 | setTrayState(on) 217 | { 218 | global exe, gdpiOutput 219 | static offIcon := A_ScriptDir . "\off.ico" 220 | try { 221 | Menu, Tray, Enable, 1& 222 | if (!on) { 223 | Menu, Tray, Icon, %offIcon% 224 | Menu, Tray, Tip, GoodbyeDPI stopped 225 | if (gdpiOutput) 226 | Menu, Tray, Rename, 2&, &View last GoodbyeDPI output 227 | else 228 | Menu, Tray, Disable, 2& 229 | Menu, Tray, Rename, 1&, &Start GoodbyeDPI 230 | } else { 231 | Menu, Tray, Icon, %exe% 232 | Menu, Tray, Tip, GoodbyeDPI started 233 | Menu, Tray, Rename, 1&, &Stop GoodbyeDPI 234 | Menu, Tray, Rename, 2&, &View GoodbyeDPI output 235 | Menu, Tray, Enable, 2& 236 | } 237 | } 238 | } 239 | 240 | AHK_TERMNOTIFY(pGlobal) 241 | { 242 | global ctx, twGlobal 243 | if (!pGlobal) 244 | pGlobal := twGlobal 245 | TermWait_StopWaiting(pGlobal) 246 | ,StdoutToVar_Cleanup(ctx) 247 | ,twGlobal := 0, ctx := "" 248 | ,setTrayState(False) 249 | } 250 | 251 | GetGoodbyeDPIOutput() 252 | { 253 | global ctx, gdpiOutput 254 | 255 | if (!DllCall("PeekNamedPipe", "Ptr", ctx.hStdOutRd, "Ptr", 0, "UInt", 0, "Ptr", 0, "UIntP", nTot, "Ptr", 0) || !nTot) 256 | return 257 | 258 | VarSetCapacity(sTemp, nTot+2) 259 | ,DllCall( "ReadFile", Ptr,ctx.hStdOutRd, Ptr,&sTemp, UInt,nTot, PtrP,nSize, Ptr,0 ) 260 | ,gdpiOutput .= StrGet(&sTemp, nSize, "CP0") 261 | } 262 | 263 | ShowGoodbyeDPIOutput() 264 | { 265 | global gdpiOutput 266 | 267 | GetGoodbyeDPIOutput() 268 | 269 | if (gdpiOutput) 270 | MsgBox %gdpiOutput% 271 | } 272 | 273 | ; --- 274 | 275 | StdoutToVar_CreateProcess(sCmd, sDir:="", dllPath:="") { 276 | ; https://autohotkey.com/boards/viewtopic.php?t=791 277 | ; Author .......: Sean (http://goo.gl/o3VCO8), modified by nfl and by Cyruz. Modified by qwerty12 to add quick and dirty DLL injection, and to abstract the pipe reading logic into its own function 278 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 279 | 280 | DllCall( "CreatePipe", PtrP,hStdOutRd, PtrP,hStdOutWr, Ptr,0, UInt,0 ) 281 | DllCall( "SetHandleInformation", Ptr,hStdOutWr, UInt,1, UInt,1 ) 282 | 283 | pi := DllCall("GlobalAlloc", "UInt", 0x0040, "Ptr", (A_PtrSize == 4) ? 16 : 24, "Ptr") 284 | si := DllCall("GlobalAlloc", "UInt", 0x0040, "Ptr", (siSz := (A_PtrSize == 4) ? 68 : 104), "Ptr") 285 | NumPut( siSz, si+0, 0, "UInt" ) 286 | NumPut( 0x100, si+0, (A_PtrSize == 4) ? 44 : 60, "UInt" ) 287 | NumPut( hStdOutWr, si+0, (A_PtrSize == 4) ? 60 : 88, "Ptr" ) 288 | NumPut( hStdOutWr, si+0, (A_PtrSize == 4) ? 64 : 96, "Ptr" ) 289 | 290 | If ( !DllCall( "CreateProcess", Ptr,0, Ptr,&sCmd, Ptr,0, Ptr,0, Int,True, UInt,(CREATE_NO_WINDOW := 0x08000000 | CREATE_SUSPENDED := 0x00000004) 291 | , Ptr,0, Ptr,sDir?&sDir:0, Ptr,si, Ptr,pi ) ) 292 | Return 0 293 | , DllCall( "CloseHandle", Ptr,hStdOutWr ) 294 | , DllCall( "CloseHandle", Ptr,hStdOutRd ) 295 | , DllCall("GlobalFree", "Ptr", si, "Ptr") 296 | , DllCall("GlobalFree", "Ptr", pi, "Ptr") 297 | 298 | DllCall( "CloseHandle", Ptr,hStdOutWr ) ; The write pipe must be closed before reading the stdout. 299 | 300 | ret := {"pi": pi, "si": si, "hStdOutRd": hStdOutRd} 301 | 302 | ok := True 303 | if (FileExist(dllPath)) { 304 | static GetBinaryType := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "kernel32.dll", "Ptr"), "AStr", A_IsUnicode ? "GetBinaryTypeW" : "GetBinaryTypeA", "Ptr") 305 | ,LoadLibrary := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "kernel32.dll", "Ptr"), "AStr", A_IsUnicode ? "LoadLibraryW" : "LoadLibraryA", "Ptr") 306 | ok := False 307 | cbDllPath := VarSetCapacity(dllPath) 308 | 309 | if ((DllCall(GetBinaryType, "Str", StrSplit(sCmd, """", """")[2], "UInt*", BinaryType))) { 310 | if ((BinaryType == 6 && A_PtrSize == 8) || (BinaryType == 0 && A_PtrSize == 4)) { 311 | if ((pRemoteDllPath := DllCall("VirtualAllocEx", "Ptr", (hProcess := NumGet(pi+0,0,"Ptr")), "Ptr", 0, "Ptr", cbDllPath, "UInt", MEM_COMMIT := 0x00001000, "UInt", PAGE_READWRITE := 0x04, "Ptr"))) { 312 | if (DllCall("WriteProcessMemory", "Ptr", hProcess, "Ptr", pRemoteDllPath, "Ptr", &dllPath, "Ptr", cbDllPath, "Ptr", 0)) { 313 | if (hRemoteThread := DllCall("CreateRemoteThread", "Ptr", hProcess, "Ptr", 0, "Ptr", 0, "Ptr", LoadLibrary, "Ptr", pRemoteDllPath, "UInt", 0, "Ptr", 0, "Ptr")) { 314 | DllCall("WaitForSingleObject", "Ptr", hRemoteThread, "UInt", 0xFFFFFFFF) ; don't use MsgWaitForMultipleObjectsEx here and let this block. There's gonna be problems anyway if this fails - having the AutoHotkey script blocked is no problem 315 | DllCall("CloseHandle", "Ptr", hRemoteThread) 316 | ok := True 317 | } 318 | } 319 | DllCall("VirtualFreeEx", "Ptr", hProcess, "Ptr", pRemoteDllPath, "Ptr", 0, "UInt", MEM_RELEASE := 0x8000) 320 | } 321 | } 322 | } 323 | } 324 | 325 | if (ok) 326 | DllCall("ResumeThread", "Ptr", NumGet(pi+0,A_PtrSize)) 327 | else { 328 | DllCall("TerminateProcess", "Ptr", hProcess, "UInt", 1) 329 | StdoutToVar_Cleanup(ret) 330 | ret := 0 331 | } 332 | 333 | Return ret 334 | } 335 | 336 | StdoutToVar_Cleanup(stvCtx) 337 | { 338 | if (IsObject(stvCtx)) { 339 | DllCall( "CloseHandle", Ptr,NumGet(stvCtx["pi"]+0,0) ) 340 | DllCall( "CloseHandle", Ptr,NumGet(stvCtx["pi"]+0,A_PtrSize) ) 341 | DllCall( "CloseHandle", Ptr,stvCtx.hStdOutRd ) 342 | 343 | DllCall("GlobalFree", "Ptr", stvCtx["si"], "Ptr") 344 | DllCall("GlobalFree", "Ptr", stvCtx["pi"], "Ptr") 345 | } 346 | } 347 | 348 | TermWait_WaitForProcTerm(hWnd, hProcess, ByRef sDataIn:="") { 349 | ; Author .......: Cyruz (http://ciroprincipe.info) & SKAN (http://goo.gl/EpCq0Z) 350 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 351 | static addrCallback := RegisterSyncCallback("AHK_TERMNOTIFY") 352 | 353 | if (hProcess < 1) 354 | return 0 355 | 356 | szDataIn := VarSetCapacity(sDataIn) 357 | pGlobal := DllCall("GlobalAlloc", "UInt", 0x0040, "UInt", (A_PtrSize == 8 ? 32 : 20) + szDataIn, "Ptr") 358 | 359 | NumPut(hWnd, pGlobal+0,, "Ptr") 360 | NumPut(hProcess, pGlobal+0, A_PtrSize == 8 ? 16 : 12, "Ptr") 361 | 362 | DllCall("RtlMoveMemory", "Ptr", pGlobal+(A_PtrSize == 8 ? 32 : 20), "Ptr", &sDataIn, "Ptr", szDataIn) 363 | if (!DllCall("RegisterWaitForSingleObject", "Ptr", pGlobal+(A_PtrSize == 8 ? 24 : 16), "Ptr", hProcess, "Ptr", addrCallback 364 | , "Ptr", pGlobal, "UInt", 0xFFFFFFFF, "UInt", 0x00000004 | 0x00000008)) { ; INFINITE, WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE 365 | DllCall("GlobalFree", "Ptr", pGlobal, "Ptr") 366 | return 0 367 | } 368 | return pGlobal 369 | } 370 | 371 | TermWait_StopWaiting(pGlobal) { 372 | if (pGlobal) { 373 | DllCall("UnregisterWait", "Ptr", NumGet(pGlobal+0, A_PtrSize == 8 ? 24 : 16, "Ptr")) 374 | DllCall("GlobalFree", "Ptr", pGlobal, "Ptr") 375 | } 376 | } 377 | 378 | RegisterSyncCallback(FunctionName, Options:="", ParamCount:="") 379 | { 380 | ; Author: lexikos (https://autohotkey.com/boards/viewtopic.php?t=21223) 381 | if !(fn := Func(FunctionName)) || fn.IsBuiltIn 382 | throw Exception("Bad function", -1, FunctionName) 383 | if (ParamCount == "") 384 | ParamCount := fn.MinParams 385 | if (ParamCount > fn.MaxParams && !fn.IsVariadic || ParamCount+0 < fn.MinParams) 386 | throw Exception("Bad param count", -1, ParamCount) 387 | 388 | static sHwnd := 0, sMsg, sSendMessageW 389 | if !sHwnd 390 | { 391 | Gui RegisterSyncCallback: +Parent%A_ScriptHwnd% +hwndsHwnd 392 | OnMessage(sMsg := 0x8000, Func("RegisterSyncCallback_Msg")) 393 | sSendMessageW := DllCall("GetProcAddress", "ptr", DllCall("GetModuleHandle", "str", "user32.dll", "ptr"), "astr", "SendMessageW", "ptr") 394 | } 395 | 396 | if !(pcb := DllCall("GlobalAlloc", "uint", 0, "ptr", 96, "ptr")) 397 | throw 398 | DllCall("VirtualProtect", "ptr", pcb, "ptr", 96, "uint", 0x40, "uint*", 0) 399 | 400 | p := pcb 401 | if (A_PtrSize = 8) 402 | { 403 | /* 404 | 48 89 4c 24 08 ; mov [rsp+8], rcx 405 | 48 89 54'24 10 ; mov [rsp+16], rdx 406 | 4c 89 44 24 18 ; mov [rsp+24], r8 407 | 4c'89 4c 24 20 ; mov [rsp+32], r9 408 | 48 83 ec 28' ; sub rsp, 40 409 | 4c 8d 44 24 30 ; lea r8, [rsp+48] (arg 3, ¶ms) 410 | 49 b9 .. ; mov r9, .. (arg 4, operand to follow) 411 | */ 412 | p := NumPut(0x54894808244c8948, p+0) 413 | p := NumPut(0x4c182444894c1024, p+0) 414 | p := NumPut(0x28ec834820244c89, p+0) 415 | p := NumPut( 0xb9493024448d4c, p+0) - 1 416 | lParamPtr := p, p += 8 417 | 418 | p := NumPut(0xba, p+0, "char") ; mov edx, nmsg 419 | p := NumPut(sMsg, p+0, "int") 420 | p := NumPut(0xb9, p+0, "char") ; mov ecx, hwnd 421 | p := NumPut(sHwnd, p+0, "int") 422 | p := NumPut(0xb848, p+0, "short") ; mov rax, SendMessageW 423 | p := NumPut(sSendMessageW, p+0) 424 | /* 425 | ff d0 ; call rax 426 | 48 83 c4 28 ; add rsp, 40 427 | c3 ; ret 428 | */ 429 | p := NumPut(0x00c328c48348d0ff, p+0) 430 | } 431 | else ;(A_PtrSize = 4) 432 | { 433 | p := NumPut(0x68, p+0, "char") ; push ... (lParam data) 434 | lParamPtr := p, p += 4 435 | p := NumPut(0x0824448d, p+0, "int") ; lea eax, [esp+8] 436 | p := NumPut(0x50, p+0, "char") ; push eax 437 | p := NumPut(0x68, p+0, "char") ; push nmsg 438 | p := NumPut(sMsg, p+0, "int") 439 | p := NumPut(0x68, p+0, "char") ; push hwnd 440 | p := NumPut(sHwnd, p+0, "int") 441 | p := NumPut(0xb8, p+0, "char") ; mov eax, &SendMessageW 442 | p := NumPut(sSendMessageW, p+0, "int") 443 | p := NumPut(0xd0ff, p+0, "short") ; call eax 444 | p := NumPut(0xc2, p+0, "char") ; ret argsize 445 | p := NumPut((InStr(Options, "C") ? 0 : ParamCount*4), p+0, "short") 446 | } 447 | NumPut(p, lParamPtr+0) ; To be passed as lParam. 448 | p := NumPut(&fn, p+0) 449 | p := NumPut(ParamCount, p+0, "int") 450 | return pcb 451 | } 452 | 453 | RegisterSyncCallback_Msg(wParam, lParam) 454 | { 455 | if (A_Gui != "RegisterSyncCallback") 456 | return 457 | fn := Object(NumGet(lParam + 0)) 458 | paramCount := NumGet(lParam + A_PtrSize, "int") 459 | params := [] 460 | Loop % paramCount 461 | params.Push(NumGet(wParam + A_PtrSize * (A_Index-1))) 462 | return %fn%(params*) 463 | } 464 | 465 | UnloadWinDivert() 466 | { 467 | return 468 | ; Note: doing the following prevents GoodbyeDPI from being loaded again. In the case of fast startup, the driver kernel state of this most probably persists, which is why I don't do this even on shutdown 469 | if ((SCM := DllCall("Advapi32\OpenSCManager", "Ptr", 0, "Ptr", 0, "UInt", 0xF003F, "Ptr"))) { 470 | if ((SVC := DllCall("Advapi32\OpenService", "Ptr", SCM, "Str", "WinDivert1.3", "UInt", 0x0001 | 0x0002 | 0x0004 | 0x0020, "Ptr"))) { 471 | DllCall("Advapi32\DeleteService", "Ptr", SVC) 472 | VarSetCapacity(SERVICE_STATUS, 28) 473 | DllCall("Advapi32.dll\ControlService", "Ptr", SVC, "UInt", 0x00000001, "Ptr", &SERVICE_STATUS) 474 | DllCall("Advapi32\CloseServiceHandle", "Ptr", SVC) 475 | } 476 | DllCall("Advapi32\CloseServiceHandle", "Ptr", SCM) 477 | } 478 | 479 | } 480 | 481 | WTFMS() 482 | { 483 | ; Author: robertcollier4: https://autohotkey.com/board/topic/91577-taskbarnavigation-switch-windows-in-taskbar-order-alt-tab-replacement/ 484 | hwnd := DllCall("GetForegroundWindow", "Ptr") 485 | loop { 486 | hwnd := DllCall("GetWindow", "Ptr", hwnd, "Ptr", 2, "Ptr") 487 | } until (DllCall("IsWindowVisible", "Ptr", hwnd)) 488 | if (!DllCall("IsIconic", "Ptr", hwnd)) 489 | if (!DllCall("SetForegroundWindow", "Ptr", hwnd)) 490 | DllCall("SwitchToThisWindow", "Ptr", hwnd, "UInt", 1) 491 | } 492 | 493 | MsgSleep(hObject, dwTimeout) 494 | { 495 | static MsgWaitForMultipleObjectsEx := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandleW", "WStr", "user32.dll", "Ptr"), "AStr", "MsgWaitForMultipleObjectsEx", "Ptr") 496 | ; Based on code by Raymond Chen, from https://blogs.msdn.microsoft.com/oldnewthing/20060126-00/?p=32513, and from Lexikos: https://autohotkey.com/board/topic/27515-fileextract-fileextract-tomem-counterpart-of-fileinstall/ 497 | ; Assumes waiting will be done on one object, but adding support for more if needed is trivial 498 | r := 0xFFFFFFFF, dwStart := A_TickCount 499 | while ((dwElapsed := A_TickCount - dwStart) < dwTimeout) { 500 | r := DllCall(MsgWaitForMultipleObjectsEx, "UInt", 1, "Ptr*", hObject, "UInt", dwTimeout - dwElapsed, "UInt", 0x4FF, "UInt", 0x6, "UInt") 501 | if (r == 0 || r == 0xFFFFFFFF || r == 258) 502 | break 503 | Sleep -1 504 | } 505 | return r 506 | } 507 | 508 | ; Very little error checking. TBH, I'd be surprised if someone actually uses this, so... 509 | ProcAddressFromRemoteProcess(hProcess, sModuleName, targetFuncName, ByRef Magic := 0) 510 | { 511 | if (!hProcess || !sModuleName || !targetFuncName) 512 | return 0 513 | 514 | MAX_PATH := 260 515 | INFINITE := 0xffffffff 516 | LIST_MODULES_DEFAULT := 0x00 517 | Loop { 518 | if (!DllCall("psapi\EnumProcessModulesEx", "Ptr", hProcess, "Ptr", 0, "UInt", 0, "UInt*", cbNeeded, "UInt", LIST_MODULES_DEFAULT)) 519 | throw 520 | VarSetCapacity(hModules, cbNeeded, 0) 521 | } until (DllCall("psapi\EnumProcessModulesEx", "Ptr", hProcess, "Ptr", &hModules, "UInt", cbNeeded, "UInt*", cbNeeded, "UInt", LIST_MODULES_DEFAULT)) 522 | 523 | VarSetCapacity(modName, (MAX_PATH + 2) * 2) 524 | Loop % cbNeeded / A_PtrSize { 525 | if (DllCall("psapi\GetModuleBaseName", "Ptr", hProcess, "Ptr", NumGet(hModules, A_PtrSize * (A_Index - 1), "Ptr"), "Str", modName, "UInt", MAX_PATH)) { 526 | if (modName = sModuleName) { 527 | hModule := NumGet(hModules, A_PtrSize * (A_Index - 1), "Ptr") 528 | break 529 | } 530 | } 531 | } 532 | 533 | if (!hModule) 534 | return 0 535 | 536 | ; MarkHC: https://www.unknowncheats.me/forum/1457119-post3.html 537 | IMAGE_DOS_SIGNATURE := 0x5A4D, IMAGE_NT_SIGNATURE := 0x4550 538 | if (DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule, "UShort*", header, "Ptr", 2, "Ptr*", br) && br == 2 && header == IMAGE_DOS_SIGNATURE) { 539 | if (DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+60, "Int*", e_lfanew, "Ptr", 4, "Ptr*", br) && DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+e_lfanew, "UInt*", Signature, "Ptr", 4, "Ptr*", br)) { 540 | if (Signature == IMAGE_NT_SIGNATURE) { 541 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+e_lfanew+24, "UShort*", Magic, "Ptr", 2, "Ptr*", br) 542 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+e_lfanew+24+(Magic == (IMAGE_NT_OPTIONAL_HDR64_MAGIC := 0x20b) ? 112 : 96), "UInt*", exportTableRVA, "Ptr", 4, "Ptr*", br) 543 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+exportTableRVA+20, "UInt*", NumberOfFunctions, "Ptr", 4, "Ptr*", br) 544 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+exportTableRVA+24, "UInt*", NumberOfNames, "Ptr", 4, "Ptr*", br) 545 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+exportTableRVA+28, "UInt*", AddressOfFunctions, "Ptr", 4, "Ptr*", br) 546 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+exportTableRVA+32, "UInt*", AddressOfNames, "Ptr", 4, "Ptr*", br) 547 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+exportTableRVA+36, "UInt*", AddressOfNameOrdinals, "Ptr", 4, "Ptr*", br) 548 | 549 | VarSetCapacity(functions, NumberOfFunctions * 4) 550 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+AddressOfFunctions, "Ptr", &functions, "Ptr", NumberOfFunctions * 4, "Ptr*", br) 551 | VarSetCapacity(exports, NumberOfNames * 4) 552 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+AddressOfNames, "Ptr", &exports, "Ptr", NumberOfNames * 4, "Ptr*", br) 553 | VarSetCapacity(ordinals, NumberOfNames * 2) 554 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+AddressOfNameOrdinals, "Ptr", &ordinals, "Ptr", NumberOfNames * 2, "Ptr*", br) 555 | 556 | Loop % NumberOfNames { 557 | addr := NumGet(exports, 4 * (A_Index - 1), "UInt") 558 | i := 0, funcName := "" 559 | while (true) { 560 | DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", hModule+addr+i, "Int*", letter, "Ptr", 1, "Ptr*", br) 561 | if (!letter) 562 | break 563 | funcName .= Chr(letter) 564 | i += 1 565 | } 566 | if (funcName == targetFuncName) { 567 | ordinal := NumGet(ordinals, 2 * (A_Index - 1), "UShort") 568 | return NumGet(functions, 4 * ordinal, "UInt") + hModule 569 | } 570 | } 571 | } 572 | } 573 | } 574 | return 0 575 | } 576 | 577 | Edit() { 578 | Edit 579 | } 580 | 581 | ExitApp() { 582 | ExitApp 583 | } 584 | -------------------------------------------------------------------------------- /GoodbyeDPITray/NoStdoutBuffering.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwerty12/AutoHotkeyScripts/a9423f59c945a3a031cb38b25cf461a34de9a6d3/GoodbyeDPITray/NoStdoutBuffering.dll -------------------------------------------------------------------------------- /GoodbyeDPITray/NoStdoutBuffering.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwerty12/AutoHotkeyScripts/a9423f59c945a3a031cb38b25cf461a34de9a6d3/GoodbyeDPITray/NoStdoutBuffering.zip -------------------------------------------------------------------------------- /GoodbyeDPITray/README.md: -------------------------------------------------------------------------------- 1 | Very basic tray script to start/stop ValdikSS's [GoodbyeDPI](https://github.com/ValdikSS/GoodbyeDPI). 2 | 3 | The script tries to stop GoodbyeDPI correctly by having Windows send Ctrl+C to the script. 4 | 5 | Extract GoodbyeDPI's exe and WinDivert DLL and driver into the same folder. Edit the script to change the arguments it starts GoodbyeDPI with. 6 | 7 | If Tor is installed as a service, it can start/stop it too. 8 | 9 | To get around the problem explained on https://www.codeproject.com/Articles/16163/Real-Time-Console-Output-Redirection so that this script can view its output without hanging, GoodbyeDPI injects a DLL called NoStdoutBuffering.dll into GoodbyeDPI's process. NoStdoutBuffering (the source is included in the 7z file) is a very simple DLL that uses the excellent [MinHook](https://github.com/TsudaKageyu/minhook) library to hook isatty to stop the CRT logic of not flushing when stdout is a pipe. 10 | 11 | The included compiled NoStdoutBuffering.dll is for 64-bit only. If you're using a 64-bit Windows OS, it's recommended you only run this script with a 64-bit AutoHotkey. -------------------------------------------------------------------------------- /GoodbyeDPITray/off.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwerty12/AutoHotkeyScripts/a9423f59c945a3a031cb38b25cf461a34de9a6d3/GoodbyeDPITray/off.ico -------------------------------------------------------------------------------- /IFilterPDF/README.txt: -------------------------------------------------------------------------------- 1 | This is an example of a script that uses Microsoft's IFilter technology to look at files' contents. 2 | 3 | Since Windows 8 (because of Reader, I presume), Microsoft has included an IFilter support plugin for PDF files, allowing indexing of their contents out of the box. If you're on 7, just install SumatraPDF. 4 | 5 | You can also use this script to get the text contents of a Word document, provided the architecture of the installed Office matches the architecture of the AutoHotkey executable. -------------------------------------------------------------------------------- /IFilterPDF/ifilter.ahk: -------------------------------------------------------------------------------- 1 | ; IFilter AutoHotkey example by qwerty12 2 | ; Credits: 3 | ; https://tlzprgmr.wordpress.com/2008/02/02/using-the-ifilter-interface-to-extract-text-from-documents/ 4 | ; https://stackoverflow.com/questions/7177953/loadifilter-fails-on-all-pdfs-but-mss-filtdump-exe-doesnt 5 | ; https://forums.adobe.com/thread/1086426?start=0&tstart=0 6 | 7 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 8 | AutoTrim, Off 9 | ListLines, Off 10 | SetBatchLines, -1 11 | #KeyHistory 0 12 | SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 13 | 14 | ; --- 15 | #MaxMem 4 ; Might need to be multipled by 2 and 1 added to it because sizeof(WCHAR == 2). Not sure. It works for me as it is currently. 16 | cchBufferSize := 4 * 1024 17 | ; --- 18 | resultstriplinebreaks := true 19 | file := "" 20 | searchstring := "" 21 | ; --- 22 | 23 | CHUNK_TEXT := 1 24 | 25 | STGM_READ := 0 26 | 27 | IFILTER_INIT_CANON_PARAGRAPHS := 1, 28 | IFILTER_INIT_HARD_LINE_BREAKS := 2, 29 | IFILTER_INIT_CANON_HYPHENS := 4, 30 | IFILTER_INIT_CANON_SPACES := 8, 31 | IFILTER_INIT_APPLY_INDEX_ATTRIBUTES := 16, 32 | IFILTER_INIT_APPLY_OTHER_ATTRIBUTES := 32, 33 | IFILTER_INIT_APPLY_CRAWL_ATTRIBUTES := 256, 34 | IFILTER_INIT_INDEXING_ONLY := 64, 35 | IFILTER_INIT_SEARCH_LINKS := 128, 36 | IFILTER_INIT_FILTER_OWNED_VALUE_OK := 512, 37 | IFILTER_INIT_FILTER_AGGRESSIVE_BREAK := 1024, 38 | IFILTER_INIT_DISABLE_EMBEDDED := 2048, 39 | IFILTER_INIT_EMIT_FORMATTING := 4096 40 | 41 | S_OK := 0 42 | FILTER_S_LAST_TEXT := 268041 43 | FILTER_E_NO_MORE_TEXT := -2147215615 44 | 45 | if (!A_IsUnicode) { 46 | MsgBox The IFilter APIs appear to be Unicode only. Please try again with a Unicode build of AHK. 47 | ExitApp 48 | } 49 | 50 | if (!file || !searchstring) { 51 | MsgBox Please make sure the file to search in and the string to search for is specified in %A_ScriptFullPath% 52 | ExitApp 53 | } 54 | 55 | SplitPath, file,,, ext 56 | VarSetCapacity(FILTERED_DATA_SOURCES, 4*A_PtrSize, 0), NumPut(&ext, FILTERED_DATA_SOURCES,, "Ptr") 57 | VarSetCapacity(FilterClsid, 16, 0) 58 | 59 | ; Adobe workaround 60 | if (job := DllCall("CreateJobObject", "Ptr", 0, "Str", "filterProc", "Ptr")) 61 | DllCall("AssignProcessToJobObject", "Ptr", job, "Ptr", DllCall("GetCurrentProcess", "Ptr")) 62 | 63 | FilterRegistration := ComObjCreate("{9E175B8D-F52A-11D8-B9A5-505054503030}", "{c7310722-ac80-11d1-8df3-00c04fb6ef4f}") 64 | if (DllCall(NumGet(NumGet(FilterRegistration+0)+3*A_PtrSize), "Ptr", FilterRegistration, "Ptr", 0, "Ptr", &FILTERED_DATA_SOURCES, "Ptr", 0, "Int", false, "Ptr", &FilterClsid, "Ptr", 0, "Ptr*", 0, "Ptr*", IFilter) != 0 ) ; ILoadFilter::LoadIFilter 65 | ExitApp 66 | if (IsFunc("Guid_ToStr")) 67 | MsgBox % Guid_ToStr(FilterClsid) 68 | ObjRelease(FilterRegistration) 69 | 70 | if (DllCall("shlwapi\SHCreateStreamOnFile", "Str", file, "UInt", STGM_READ, "Ptr*", iStream) != 0 ) 71 | ExitApp 72 | PersistStream := ComObjQuery(IFilter, "{00000109-0000-0000-C000-000000000046}") 73 | if (DllCall(NumGet(NumGet(PersistStream+0)+5*A_PtrSize), "Ptr", PersistStream, "Ptr", iStream) != 0 ) ; ::Load 74 | ExitApp 75 | ObjRelease(iStream) 76 | 77 | status := 0 78 | if (DllCall(NumGet(NumGet(IFilter+0)+3*A_PtrSize), "Ptr", IFilter, "UInt", IFILTER_INIT_DISABLE_EMBEDDED | IFILTER_INIT_INDEXING_ONLY, "Int64", 0, "Ptr", 0, "Int64*", status) != 0 ) ; IFilter::Init 79 | ExitApp 80 | 81 | VarSetCapacity(STAT_CHUNK, A_PtrSize == 8 ? 64 : 52) 82 | VarSetCapacity(buf, (cchBufferSize * 2) + 2) 83 | while (DllCall(NumGet(NumGet(IFilter+0)+4*A_PtrSize), "Ptr", IFilter, "Ptr", &STAT_CHUNK) == 0) { ; ::GetChunk 84 | if (NumGet(STAT_CHUNK, 8, "UInt") & CHUNK_TEXT) { 85 | while (DllCall(NumGet(NumGet(IFilter+0)+5*A_PtrSize), "Ptr", IFilter, "Int64*", (siz := cchBufferSize), "Ptr", &buf) != FILTER_E_NO_MORE_TEXT) ; ::GetText 86 | { 87 | text := StrGet(&buf,, "UTF-16") 88 | if (resultstriplinebreaks) 89 | text := StrReplace(text, "`r`n") 90 | if (InStr(text, searchstring)) { 91 | MsgBox "%searchstring%" found 92 | break 93 | } 94 | } 95 | } 96 | } 97 | ObjRelease(PersistStream) 98 | ObjRelease(iFilter) 99 | if (job) 100 | DllCall("CloseHandle", "Ptr", job) 101 | 102 | ExitApp -------------------------------------------------------------------------------- /InternetExplorerCaretBrowsingEnabledForPage.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | ; Select an Internet Explorer tab and press q while this script is running 4 | 5 | OLECMDF_SUPPORTED := 0x1 6 | OLECMDF_ENABLED := 0x2 7 | OLECMDF_LATCHED := 0x4 8 | 9 | VarSetCapacity(CGID_MSHTML, 16) 10 | DllCall("ole32\CLSIDFromString", "WStr", "{de4ba900-59ca-11cf-9592-444553540000}", "Ptr", &CGID_MSHTML) 11 | 12 | q:: 13 | oWB := WBGet("ahk_id " . WinExist("A")) 14 | ; https://msdn.microsoft.com/en-us/library/cc849093(v=vs.85).aspx 15 | IOleCommandTarget := ComObjQuery(oWB.Document, "{b722bccb-4e68-101b-a2bc-00aa00404770}") 16 | VarSetCapacity(OLECMD, 8, 0), NumPut(IDM_CARETBROWSINGMODE := 2436, OLECMD,, "UInt") 17 | if (DllCall(NumGet(NumGet(IOleCommandTarget+0)+3*A_PtrSize), "Ptr", IOleCommandTarget, "Ptr", &CGID_MSHTML, "UInt", 1, "Ptr", &OLECMD, "Ptr", 0) >= 0) 18 | MsgBox % "Caret browsing active: " . (NumGet(OLECMD, 4, "UInt") & OLECMDF_LATCHED ? "True" : "False") 19 | 20 | newSetting := -1 ; -1: toggle, False: disable, True:enable 21 | if (newSetting == -1) { 22 | pVar := 0 23 | } else { 24 | VarSetCapacity(VARIANT, 24, 0) 25 | NumPut(VT_BOOL := 11, VARIANT,, "UShort") 26 | NumPut(newSetting ? -1 : False, VARIANT, 8, "Short") 27 | pVar := &VARIANT 28 | } 29 | DllCall(NumGet(NumGet(IOleCommandTarget+0)+4*A_PtrSize), "Ptr", IOleCommandTarget, "Ptr", &CGID_MSHTML, "UInt", IDM_CARETBROWSINGMODE, "UInt", OLECMDEXECOPT_DONTPROMPTUSER := 2, "Ptr", pVar, "Ptr", 0) 30 | ObjRelease(IOleCommandTarget) 31 | oWB := "" 32 | return 33 | 34 | ;[WBGet function for AHK v1.1] 35 | ;WBGet function - AutoHotkey Community 36 | ;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869 37 | 38 | WBGet(WinTitle="ahk_class IEFrame", Svr#=1) { ;// based on ComObjQuery docs 39 | static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT") 40 | , IID := "{0002DF05-0000-0000-C000-000000000046}" ;// IID_IWebBrowserApp 41 | ;// , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ;// IID_IHTMLWindow2 42 | SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle% 43 | if (ErrorLevel != "FAIL") { 44 | lResult:=ErrorLevel, VarSetCapacity(GUID,16,0) 45 | if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 { 46 | DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc) 47 | return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc) 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 qwerty12 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LaptopBrightnessSetter/README.md: -------------------------------------------------------------------------------- 1 | Download from https://gist.github.com/qwerty12/4b3f41eb61724cd9e8f2bb5cc15c33c2 2 | 3 | On Windows 10, it will set the laptop's monitor brightness and show the brightness OSD present there. 4 | 5 | Showing the OSD might be a bit iffy, however: 6 | * On Windows 10, the OSD window responds to a SHELLHOOK message to show the OSD on demand. However, the window to send said message to doesn't exist until it's created by pressing the brightness/volume buttons (the former only available physically), or if an undocumented function provided by the shell over COM is called. To create the window if needed, this tries the latter first and then falls back to quickly muting/unmuting the volume. I suspect with every new Windows 10 service pack major update, the GUIDs needed to call the COM method will change, like how they did for the IPolicyConfig interface and "IVirtualDesktopManagerInternal". The SID and IID is correct for 14393.693. 7 | * On Windows 8, I'm hoping the behaviour is the same, but I haven't checked 8 | * On Windows 7, there is no OSD to speak of 9 | 10 | To use, paste the contents of the Gist into your file or save the raw contents of the Gist as something like, say, BrightnessSetter.ahk in a default AutoHotkey library folder. And then do something like this: 11 | 12 | #include ; if you saved the class as its own file 13 | BrightnessSetter.SetBrightness(-10) 14 | 15 | If an own instance of the BrightnessSetter class is created, then it will monitor the AC insertion state. That's optional, however. 16 | 17 | There's really only one method that actually does anything, the SetBrightness method. Its parameters: 18 | * increment - how much to increase or decrease the current brightness by. If jump is set, then increment is considered to be an absolute value 19 | * jump - sets the brightness directly instead of working relatively with the current brightness value. False by default 20 | * showOSD - determines if the OSD should be shown. To match the behaviour of the physical brightness keys, BrightnessSetter shows the OSD regardless of whether the brightness was actually changed. True by default 21 | * autoDcOrAc - set to -1 if you want BrightnessSetter to determine the power source and set the brightness for the active power source, 0 if you want the brightness value for when battery power is active to be changed, and 1 for the brightness value when a charger is plugged in. -1 by default 22 | * forceDifferentScheme - by default, BrightnessSetter works on the active power plan. If you want the brightness for a non-active power plan to be set, you can pass a pointer to the appropriate GUID structure for it. Linear Spoon has an excellent post here on using PowerEnumerate to get all the power plans on the system along with their GUIDs. 0 by default to force using the active scheme 23 | 24 | Credits: 25 | * YashMaster for the shellhook mechanism and brightness validity tests I pretty much copied (and possibly messed up): https://github.com/YashMaster/Tweaky 26 | -------------------------------------------------------------------------------- /LoadAdBlockPlusForIEintoAHK.ahk: -------------------------------------------------------------------------------- 1 | try if ((BhoAbp := ComObjCreate("{FFCB3198-32F3-4E8B-9539-4324694ED664}", "{FC4801A3-2BA9-11CF-A229-00AA003D7352}"))) { 2 | DllCall(NumGet(NumGet(BhoAbp+0)+3*A_PtrSize), "Ptr", BhoAbp, "Ptr", wb) 3 | } 4 | ... 5 | if (BhoAbp) { 6 | ; When it's time to release the your ActiveX WebBrowser object: 7 | DllCall(NumGet(NumGet(BhoAbp+0)+3*A_PtrSize), "Ptr", BhoAbp, "Ptr", 0) 8 | ObjRelease(BhoAbp) 9 | } -------------------------------------------------------------------------------- /LogoffAllUsersExceptYou.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | full_command_line := DllCall("GetCommandLine", "str") 4 | 5 | if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) 6 | { 7 | try 8 | { 9 | if A_IsCompiled 10 | Run *RunAs "%A_ScriptFullPath%" /restart 11 | else 12 | Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%" 13 | } 14 | ExitApp 15 | } 16 | LogonDesktop_ProcessIdToSessionId(LogonDesktop_GetCurrentProcessId(), scriptProcessSessionId) 17 | 18 | if ((wtsapi32 := DllCall("LoadLibrary", "Str", "wtsapi32.dll", "Ptr"))) { 19 | if (DllCall("wtsapi32\WTSEnumerateSessionsEx", "Ptr", WTS_CURRENT_SERVER_HANDLE := 0, "UInt*", 1, "UInt", 0, "Ptr*", pSessionInfo, "UInt*", wtsSessionCount)) { 20 | WTS_CONNECTSTATE_CLASS := {0: "WTSActive", 1: "WTSConnected", 2: "WTSConnectQuery", 3: "WTSShadow", 4: "WTSDisconnected", 5: "WTSIdle", 6: "WTSListen", 7: "WTSReset", 8: "WTSDown", 9: "WTSInit"} 21 | cbWTS_SESSION_INFO_1 := A_PtrSize == 8 ? 56 : 32 22 | Loop % wtsSessionCount { 23 | currSessOffset := cbWTS_SESSION_INFO_1 * (A_Index - 1) ;, ExecEnvId := NumGet(pSessionInfo+0, currSessOffset, "UInt") 24 | currSessOffset += 4, State := NumGet(pSessionInfo+0, currSessOffset, "UInt") 25 | currSessOffset += 4, SessionId := NumGet(pSessionInfo+0, currSessOffset, "UInt") 26 | currSessOffset += A_PtrSize ; , SessionName := StrGet(NumGet(pSessionInfo+0, currSessOffset, "Ptr")) 27 | currSessOffset += A_PtrSize ;, HostName := StrGet(NumGet(pSessionInfo+0, currSessOffset, "Ptr")) 28 | ; currSessOffset += A_PtrSize, UserName := StrGet(NumGet(pSessionInfo+0, currSessOffset, "Ptr")) 29 | ; currSessOffset += A_PtrSize, DomainName := StrGet(NumGet(pSessionInfo+0, currSessOffset, "Ptr")) 30 | ; currSessOffset += A_PtrSize, FarmName := StrGet(NumGet(pSessionInfo+0, currSessOffset, "Ptr")) 31 | 32 | if (SessionId && SessionId != scriptProcessSessionId) 33 | DllCall("wtsapi32\WTSLogoffSession", "Ptr", WTS_CURRENT_SERVER_HANDLE, "UInt", SessionId, "Int", False) 34 | } 35 | DllCall("wtsapi32\WTSFreeMemoryEx", "UInt", WTSTypeSessionInfoLevel1 := 2, "Ptr", pSessionInfo, "UInt", wtsSessionCount) 36 | } 37 | DllCall("FreeLibrary", "Ptr", wtsapi32) 38 | } 39 | 40 | LogonDesktop_GetCurrentProcessId() { 41 | static dwProcessId := DllCall("GetCurrentProcessId", "UInt") ; well, it's not like this one is going to change each time we call it 42 | return dwProcessId 43 | } 44 | 45 | LogonDesktop_ProcessIdToSessionId(dwProcessId, ByRef dwSessionId) 46 | { 47 | static ProcessIdToSessionId := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandleW", "WStr", "kernel32.dll", "Ptr"), "AStr", "ProcessIdToSessionId", "Ptr") 48 | return DllCall(ProcessIdToSessionId, "UInt", dwProcessId, "UInt*", dwSessionId) 49 | } -------------------------------------------------------------------------------- /MoveAHKGuiToDifferentWindows10VirtualDesktop.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | ; #Warn ; Enable warnings to assist with detecting common errors. 3 | SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 4 | SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 5 | #NoTrayIcon 6 | #SingleInstance force 7 | 8 | ; Create multiple Windows 10 virtual desktops first 9 | 10 | ; base script by k1dr0ck 11 | 12 | gui, +AlwaysOnTop +HwndhwndGui 13 | gui, add, button, x10 y5 h20 w35 gsub1, <- 14 | gui, add, button, x55 y5 h20 w35 gsub2, -> 15 | gui, show, x15 y680 h30 w100 16 | 17 | return 18 | 19 | sub1: 20 | { 21 | SendInput ^#{Left} 22 | movewindow(hwndGui) 23 | } 24 | return 25 | 26 | sub2: 27 | { 28 | SendInput ^#{Right} 29 | movewindow(hwndGui) 30 | } 31 | return 32 | 33 | guiclose: 34 | { 35 | exitapp 36 | } 37 | return 38 | 39 | movewindow(guiHwnd) 40 | { 41 | static desktopID 42 | if (!VarSetCapacity(desktopID)) 43 | VarSetCapacity(desktopID, 16) 44 | 45 | try if IVirtualDesktopManager := ComObjCreate("{aa509086-5ca9-4c25-8f95-589d3c07b48a}", "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}") { 46 | Loop 10 { ; wait to see until our main GUI is not on the starting virtual desktop 47 | hr := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3 * A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", guiHwnd, "Int*", onCurrentDesktop) 48 | if (hr == "" || hr < 0) { 49 | ObjRelease(IVirtualDesktopManager) 50 | return 51 | } 52 | Sleep 100 53 | if (!onCurrentDesktop) 54 | break 55 | } 56 | if (!onCurrentDesktop) { 57 | gui tmp: +Hwndwtfms ; create a new temporary GUI belonging to our process on the new virtual desktop 58 | gui tmp: show 59 | hr := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 4 * A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", wtfms, "Ptr", &desktopID) ; get the GUID of the virtual desktop hosting our temporary window 60 | Gui tmp: destroy 61 | if (hr == 0 && DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 5 * A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", guiHwnd, "Ptr", &desktopID) == 0) ; move the main window to the same desktop 62 | WinActivate ahk_id %guiHwnd% ; re-activate the window 63 | } 64 | ObjRelease(IVirtualDesktopManager) 65 | } 66 | } -------------------------------------------------------------------------------- /MultiFileProperties.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 3 | 4 | ; Shows the same thing that you get when you select more than one file and view their combined properties 5 | 6 | ; Credits: Remy Lebeau: https://stackoverflow.com/a/34551988 7 | 8 | MultiFileProperties(filenames*) { 9 | static IID_IDataObject 10 | if (!VarSetCapacity(IID_IDataObject)) 11 | VarSetCapacity(IID_IDataObject, 16), DllCall("ole32\CLSIDFromString", "WStr", "{0000010e-0000-0000-C000-000000000046}", "Ptr", &IID_IDataObject) 12 | 13 | ret := False 14 | if (!filenames.MaxIndex()) 15 | return ret 16 | 17 | DllCall("shell32\SHGetDesktopFolder", "Ptr*", pDesktop) 18 | if (!pDesktop) 19 | return ret 20 | 21 | VarSetCapacity(pidl_list, filenames.MaxIndex() * A_PtrSize) 22 | filenameCount := 0, ParseDisplayName := NumGet(NumGet(pDesktop+0)+3*A_PtrSize) 23 | for _, filename in filenames 24 | filenameCount += DllCall(ParseDisplayName, "Ptr", pDesktop, "Ptr", 0, Ptr, 0, "WStr", filename, "Ptr", 0, "Ptr", &pidl_list+(filenameCount * A_PtrSize), "Ptr", 0) == 0 25 | 26 | if (filenameCount && DllCall(NumGet(NumGet(pDesktop+0)+10*A_PtrSize), "Ptr", pDesktop, "Ptr", 0, "UInt", filenameCount, "Ptr", &pidl_list, "Ptr", &IID_IDataObject, "Ptr", 0, "Ptr*", pDataObject) == 0) { ; GetUIObjectOf 27 | ret := DllCall("shell32\SHMultiFileProperties", "Ptr", pDataObject, "UInt", 0) == 0 28 | ObjRelease(pDataObject) 29 | } 30 | 31 | loop %filenameCount% { 32 | if ((pidl := NumGet(pidl_list, (A_Index - 1) * A_PtrSize, "Ptr"))) 33 | DllCall("ole32\CoTaskMemFree", "Ptr", pidl) 34 | } 35 | ObjRelease(pDesktop) 36 | 37 | return ret 38 | } 39 | 40 | if (MultiFileProperties(A_ProgramFiles . "\Internet Explorer\iexplore.exe", A_WinDir . "\Explorer.exe", A_ScriptFullPath)) { 41 | MsgBox Wait for the properties window and then click OK here when done to end the script 42 | } else { 43 | MsgBox Error 44 | } -------------------------------------------------------------------------------- /OneDriveOnDemandSyncToggle/OneDriveOnDemandSyncToggle.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | #NoTrayIcon 3 | 4 | MODE_GET_STATUS := 0 5 | ,MODE_TOGGLE_KEEP_ON_DEVICE := 1 6 | ,MODE_FREE_SPACE := 2 7 | 8 | mode := MODE_GET_STATUS 9 | 10 | if 0 < 1 11 | { 12 | MsgBox This script requires at least 1 incoming parameter. 13 | ExitApp 1 14 | } 15 | else if 0 = 2 16 | { 17 | firstParam = %1% 18 | if (firstParam = "/keepondevice") 19 | mode := MODE_TOGGLE_KEEP_ON_DEVICE 20 | else if (firstParam = "/freespace") 21 | mode := MODE_FREE_SPACE 22 | else 23 | ExitApp 1 24 | } 25 | else if 0 > 2 26 | { 27 | ExitApp 1 28 | } 29 | 30 | RegRead, UserFolder, HKEY_CURRENT_USER\Software\Microsoft\OneDrive, UserFolder 31 | if (ErrorLevel || !InStr(FileExist(UserFolder), "D")) 32 | ExitApp 1 33 | SetWorkingDir %UserFolder% 34 | 35 | if (mode == MODE_GET_STATUS) 36 | filenameParam = %1% 37 | else 38 | filenameParam = %2% 39 | if (!FileExist(filenameParam)) 40 | ExitApp 1 41 | 42 | VarSetCapacity(dwTypeData, 2050) 43 | ,VarSetCapacity(IID_IDataObject, 16) 44 | ,DllCall("ole32\CLSIDFromString", "WStr", "{0000010e-0000-0000-C000-000000000046}", "Ptr", &IID_IDataObject) 45 | 46 | DoOrDie(DllCall("shell32\SHGetDesktopFolder", "Ptr*", pDesktop)) 47 | filenames := [DllCall("shlwapi\PathCombineW", "Ptr", &dwTypeData, "Ptr", &UserFolder, "Ptr", &filenameParam, "WStr")] 48 | VarSetCapacity(pidl_list, filenames.MaxIndex() * A_PtrSize) 49 | filenameCount := 0, ParseDisplayName := NumGet(NumGet(pDesktop+0)+3*A_PtrSize) 50 | for _, filename in filenames 51 | filenameCount += DllCall(ParseDisplayName, "Ptr", pDesktop, "Ptr", 0, Ptr, 0, "WStr", filename, "Ptr", 0, "Ptr", &pidl_list+(filenameCount * A_PtrSize), "Ptr", 0) >= 0x00 52 | if (!filenameCount) 53 | ExitApp 1 54 | DoOrDie(DllCall(NumGet(NumGet(pDesktop+0)+10*A_PtrSize), "Ptr", pDesktop, "Ptr", 0, "UInt", filenameCount, "Ptr", &pidl_list, "Ptr", &IID_IDataObject, "Ptr", 0, "Ptr*", pDataObject)) 55 | 56 | fsctxmenu := ComObjCreate("{CB3D0F55-BC2C-4C1A-85ED-23ED75B5106B}", "{000214E4-0000-0000-C000-000000000046}") 57 | fsshextinit := ComObjQuery(fsctxmenu, "{000214E8-0000-0000-C000-000000000046}") 58 | DoOrDie(DllCall(NumGet(NumGet(fsshextinit+0)+3*A_PtrSize), "Ptr", fsshextinit, "Ptr", 0, "Ptr", pDataObject, "Ptr", 0)) 59 | 60 | DoOrDie(DllCall(NumGet(NumGet(fsctxmenu+0)+3*A_PtrSize), "Ptr", fsctxmenu, "Ptr", (hMenu := DllCall("CreatePopupMenu", "Ptr")), "UInt", 0, "UInt", 0, "UInt", 0x7FFF, "UInt", 0x00000080)) 61 | VarSetCapacity(MENUITEMINFOW, (cbMENUITEMINFOW := A_PtrSize == 8 ? 72 : 44)) 62 | Loop % DllCall("GetMenuItemCount", "Ptr", hMenu, "Int") { 63 | DllCall("ntdll\RtlZeroMemory", "Ptr", &MENUITEMINFOW, "Ptr", cbMENUITEMINFOW) 64 | ,NumPut(cbMENUITEMINFOW, MENUITEMINFOW, 0, "UInt") 65 | ,NumPut(0x00000002 | 0x00000001 | 0x00000040, MENUITEMINFOW, 4, "UInt") 66 | ,NumPut(1024, MENUITEMINFOW, A_PtrSize == 8 ? 64 : 40, "UInt") 67 | ,NumPut(&dwTypeData, MENUITEMINFOW, A_PtrSize == 8 ? 56 : 36, "Ptr") 68 | if ((DllCall("GetMenuItemInfo", "Ptr", hMenu, "UInt", A_Index - 1, "Int", True, "Ptr", &MENUITEMINFOW, "Int")) && (cch := NumGet(MENUITEMINFOW, A_PtrSize == 8 ? 64 : 40, "UInt"))) { 69 | fState := NumGet(MENUITEMINFOW, 12, "UInt") 70 | ,idn := NumGet(MENUITEMINFOW, 16, "UInt") 71 | ,menulabel := StrGet(&dwTypeData, cch, "UTF-16") 72 | if (menulabel == "Always keep on this device") { 73 | if (mode == MODE_GET_STATUS) 74 | msg .= (StrLen(msg) ? "`n" : "") . filenameParam . " is " . (fState & 0x00000008 != 0x00000008 ? "not " : "") . "set to always be kept on this device" 75 | else if (mode == MODE_TOGGLE_KEEP_ON_DEVICE) 76 | break 77 | } else if (menulabel == "Free up space") { 78 | cannotBeSelected := fState & 0x00000001 || fState & 0x00000002 79 | if (mode == MODE_GET_STATUS) { 80 | msg .= (StrLen(msg) ? "`n" : "") . filenameParam . " can" . (cannotBeSelected ? "not " : " ") . "be freed to make space" 81 | } else if (mode == MODE_FREE_SPACE) { 82 | if (cannotBeSelected) 83 | mode := -1 84 | break 85 | } 86 | } 87 | } 88 | } 89 | 90 | if (mode == MODE_GET_STATUS) { 91 | msgbox %msg% 92 | } else if (mode == MODE_TOGGLE_KEEP_ON_DEVICE || mode == MODE_FREE_SPACE) { 93 | VarSetCapacity(info, (cbCMINVOKECOMMANDINFO := A_PtrSize == 8 ? 56 : 36), 0) 94 | ,NumPut(cbCMINVOKECOMMANDINFO, info, 0, "UInt") 95 | ,NumPut(0x00000100, info, 4, "UInt") 96 | ,NumPut(A_ScriptHwnd, info, 8, "Ptr") 97 | ,NumPut(idn, info, A_PtrSize == 8 ? 16 : 12, "UPtr") 98 | ,DoOrDie(DllCall(NumGet(NumGet(fsctxmenu+0)+4*A_PtrSize), "Ptr", fsctxmenu, "Ptr", &info)) ; IContextMenu::InvokeCommand 99 | Sleep -1 100 | } 101 | 102 | DllCall("DestroyMenu", "Ptr", hMenu) 103 | ,ObjRelease(fsshextinit) 104 | ,ObjRelease(fsctxmenu) 105 | ,ObjRelease(pDataObject) 106 | Loop %filenameCount% { 107 | if ((pidl := NumGet(pidl_list, (A_Index - 1) * A_PtrSize, "Ptr"))) 108 | DllCall("ole32\CoTaskMemFree", "Ptr", pidl) 109 | } 110 | ObjRelease(pDesktop) 111 | ExitApp 112 | 113 | DoOrDie(hr) 114 | { 115 | if (hr == "" || hr < 0) 116 | ExitApp 1 117 | } -------------------------------------------------------------------------------- /OneDriveOnDemandSyncToggle/README.md: -------------------------------------------------------------------------------- 1 | WARNING: I do not use OneDrive myself. I have not tested this with any file over 200 KB... *Make sure you have backups of any important files stored outside of OneDrive!* 2 | 3 | A hack that loads the OneDrive context menu shell extension into AutoHotkey, where AHK can then select menu items directly - the extension tells the OneDrive client to perform the action. 4 | 5 | To find out if a file is set to always remain stored on your PC and/or whether the space used (if any) by said file can be freed, run the script with just the target's filename as the script's sole argument. `Example: Untitled.ahk "Documents\New Text Document.txt"` 6 | 7 | To toggle a file's always-remain-on-your-PC status, run the script with /keepondevice as the first argument, followed by the target's filename as the second argument. Example: `Untitled.ahk /keepondevice "Documents\New Text Document.txt"` 8 | 9 | To have a file cleared from your PC, run the script with /freespace as the first argument, followed by the target's filename as the second argument. Example: `Untitled.ahk /freespace "Documents\New Text Document.txt"` 10 | 11 | * This is the bare minimum to do something like this this way. Adding in support to toggle multiple files' always-remain-on-your-PC status / freeing multiple files is probably possible by reworking my bad command-line logic and adding the extra filenames to the filenames array. 12 | * But not for the getting a file's current status operation! Select multiple files in your OneDrive folder of varying sync statuses, right-click and observe the inconsistencies. This script determines the current status for one file by seeing if the relevant menu is (un)checked / enabled / disabled. Yeah... 13 | -------------------------------------------------------------------------------- /PopupMenuUtils.ahk: -------------------------------------------------------------------------------- 1 | ; https://autohotkey.com/board/topic/16457-controlling-popup-menues/ 2 | 3 | PopupMenuUtils_user32_handle(fn) 4 | { 5 | static u32 := DllCall("GetModuleHandle", Str, "user32.dll", "Ptr") 6 | return DllCall("GetProcAddress", "Ptr", u32, "AStr", fn, "Ptr") 7 | } 8 | 9 | PopupMenuUtils_MF_BYPOSITION() { 10 | return 0x00000400 11 | } 12 | 13 | PopupMenuUtils_GetMenuItemCount(hMenu) 14 | { 15 | static GetMenuItemCount := PopupMenuUtils_user32_handle("GetMenuItemCount") 16 | return DllCall(GetMenuItemCount, "Ptr", hMenu, "Int") 17 | } 18 | 19 | ;PopupMenuUtils_GetMenuString(hMenu, nPos) 20 | ;{ 21 | ; static GetMenuStringW := PopupMenuUtils_user32_handle("GetMenuStringW"), byp := PopupMenuUtils_MF_BYPOSITION() 22 | ; if ((hMenu) && (length := DllCall(GetMenuStringW, "Ptr", hMenu, "UInt", nPos, "Ptr", 0, "Int", 0, "UInt", byp))) { 23 | ; length += 1, VarSetCapacity(lpString, (length * 2) + 2) 24 | ; if (DllCall(GetMenuStringW, "Ptr", hMenu, "UInt", nPos, "WStr", lpString, "Int", length, "UInt", byp)) 25 | ; return lpString 26 | ; } 27 | ; return "" 28 | ;} 29 | 30 | PopupMenuUtils_GetMenuString(hMenu, nPos) 31 | { 32 | static lpString, GetMenuStringW := PopupMenuUtils_user32_handle("GetMenuStringW"), byp := PopupMenuUtils_MF_BYPOSITION() 33 | if !VarSetCapacity(lpString) 34 | VarSetCapacity(lpString, 1024) ; what sort of idiot makes a menu item have ~510 characters, anyway? 35 | if (DllCall(GetMenuStringW, "Ptr", hMenu, "UInt", nPos, "WStr", lpString, "Int", 511, "UInt", byp)) 36 | return lpString 37 | } 38 | 39 | PopupMenuUtils_GetMenuState(hMenu, nPos) 40 | { 41 | static GetMenuState := PopupMenuUtils_user32_handle("GetMenuState"), byp := PopupMenuUtils_MF_BYPOSITION() 42 | return DllCall(GetMenuState, "Ptr", hMenu, "UInt", nPos, "UInt", byp, "UInt") 43 | } 44 | 45 | PopupMenuUtils_ItemIsChecked(State) { 46 | return !!(State & 0x00000008) ; MF_CHECKED 47 | } 48 | 49 | PopupMenuUtils_ItemIsDisabled(State) { 50 | return !!(State & 0x00000002 || State & 0x00000001) ; MF_DISABLED || MF_GRAYED 51 | } 52 | 53 | PopupMenuUtils_ItemIsPopup(State) { 54 | return !!(State & 0x00000010) ; MF_POPUP 55 | } 56 | 57 | PopupMenuUtils_GetMenuItemID(hMenu, nPos) { 58 | return DllCall("GetMenuItemID", "Ptr", hMenu, "int", nPos, "UInt") 59 | } 60 | 61 | PopupMenuUtils_GetHmenuFromHwnd(hWnd) 62 | { 63 | static SendMessagePtr := PopupMenuUtils_user32_handle(A_IsUnicode ? "SendMessageW" : "SendMessageA") 64 | return DllCall(SendMessagePtr, "Ptr", hWnd, "UInt", 0x01E1, "Ptr", 0, "Ptr", 0, "Ptr") ; MN_GETHMENU 65 | } 66 | 67 | PopupMenuUtils_GetMenu(hwnd) { 68 | return DllCall("GetMenu", "Ptr", hwnd, "Ptr") 69 | } 70 | 71 | PopupMenuUtils_GetSubmenu(hMenu, nPos) { 72 | return DllCall("GetSubMenu", "Ptr", hMenu, "int", nPos, "Ptr") 73 | } 74 | 75 | PopupMenuUtils_WinHasMenu(WinTitle:="") { 76 | return !!PopupMenuUtils_GetMenu(WinExist(WinTitle)) 77 | } 78 | -------------------------------------------------------------------------------- /ProcessIsSuspended.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv 2 | 3 | ; Taken from the Process Hacker source code, by wj32 and dmex 4 | ; Thanks to jeeswg for fixing the 32-bit incompatibility 5 | 6 | ProcessIsSuspended(pid, ByRef isPartiallySuspended := 0) { 7 | static initialBufferSize := 0x4000, cbSYSTEM_THREAD_INFORMATION := A_PtrSize == 8 ? 80 : 64 8 | static SystemProcessInformation := 5, STATUS_BUFFER_TOO_SMALL := 0xC0000023, STATUS_INFO_LENGTH_MISMATCH := 0xC0000004 9 | static Waiting := 5, Suspended := 5 10 | static UniqueProcessIdOffset := A_PtrSize == 8 ? 80 : 68, NumberOfThreadsOffset := 4, ThreadsArrayOffset := A_PtrSize == 8 ? 256 : 184 11 | static ThreadStateOffset := A_PtrSize == 8 ? 68 : 52, WaitReasonOffset := A_PtrSize == 8 ? 72 : 56 12 | bufferSize := initialBufferSize 13 | 14 | VarSetCapacity(ProcessBuffer, bufferSize) 15 | 16 | Loop { 17 | status := DllCall("ntdll\NtQuerySystemInformation", "UInt", SystemProcessInformation, "Ptr", &ProcessBuffer, "UInt", bufferSize, "UInt*", bufferSize, "UInt") 18 | if (status == STATUS_BUFFER_TOO_SMALL || status == STATUS_INFO_LENGTH_MISMATCH) { 19 | VarSetCapacity(ProcessBuffer, bufferSize) 20 | } 21 | else { 22 | break 23 | } 24 | } 25 | 26 | if (status < 0) { 27 | return -1 28 | } 29 | 30 | if (bufferSize <= 0x100000) initialBufferSize := bufferSize 31 | 32 | isSuspended := pid > 0 33 | isPartiallySuspended := False 34 | ThisEntryOffset := 0 35 | 36 | Loop { 37 | if (NumGet(ProcessBuffer, ThisEntryOffset + UniqueProcessIdOffset, "Ptr") == pid) { 38 | Loop % NumGet(ProcessBuffer, ThisEntryOffset + NumberOfThreadsOffset, "UInt") { 39 | ThisThreadsOffset := ThisEntryOffset + ThreadsArrayOffset + (cbSYSTEM_THREAD_INFORMATION * (A_Index - 1)) 40 | ThreadState := NumGet(ProcessBuffer, ThisThreadsOffset + ThreadStateOffset, "UInt") 41 | WaitReason := NumGet(ProcessBuffer, ThisThreadsOffset + WaitReasonOffset, "UInt") 42 | if (ThreadState != Waiting || WaitReason != Suspended) { 43 | isSuspended := False 44 | } else { 45 | isPartiallySuspended := True 46 | } 47 | } 48 | return isSuspended 49 | } 50 | } until (!(NextEntryOffset := NumGet(ProcessBuffer, ThisEntryOffset, "UInt")), ThisEntryOffset += NextEntryOffset) 51 | 52 | return -1 53 | } 54 | 55 | ;MsgBox % ProcessIsSuspended(560) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Other scripts that might be of interest: 2 | 3 | * [Change the size of the quick launch deskband programmatically](https://autohotkey.com/boards/viewtopic.php?p=150599#p150599) 4 | 5 | * [Firefox native messaging example](https://autohotkey.com/boards/viewtopic.php?f=5&t=29308) 6 | 7 | * [Chrome native messaging example](https://autohotkey.com/boards/viewtopic.php?p=150461#p150461) 8 | 9 | * [Get selected filenames from open Open/Save file dialogs in other processes](https://autohotkey.com/boards/viewtopic.php?p=146043#p146043) 10 | 11 | * [Using IPolicyConfig to disable an audio device](https://autohotkey.com/boards/viewtopic.php?f=5&t=21229) 12 | 13 | * [Add cursor file as resource to exe](https://autohotkey.com/boards/viewtopic.php?f=5&t=8516) 14 | 15 | -------------------------------------------------------------------------------- /SetGlobalWindowsTextToSpeechVoice.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | ; https://autohotkey.com/boards/viewtopic.php?p=166239#p166239 4 | 5 | if (SUCCEEDED(SpGetCategoryFromId(SPCAT_VOICES := "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices", cpSpObjectTokenCategory))) 6 | { 7 | hr := DllCall(NumGet(NumGet(cpSpObjectTokenCategory+0)+18*A_PtrSize), "Ptr", cpSpObjectTokenCategory, "Ptr", 0, "Ptr", 0, "Ptr*", cpSpEnumTokens) 8 | 9 | if (SUCCEEDED(hr)) 10 | { 11 | hr := DllCall(NumGet(NumGet(cpSpEnumTokens+0)+8*A_PtrSize), "Ptr", cpSpEnumTokens, "UInt*", tokenCount) 12 | if (SUCCEEDED(hr)) 13 | { 14 | voices := Object() 15 | Loop %tokenCount% { 16 | hr := DllCall(NumGet(NumGet(cpSpEnumTokens+0)+7*A_PtrSize), "Ptr", cpSpEnumTokens, "UInt", A_Index - 1, "Ptr*", pToken) 17 | if (FAILED(hr)) { 18 | MsgBox Bailing out 19 | ExitApp 1 20 | } 21 | hr := DllCall(NumGet(NumGet(pToken+0)+6*A_PtrSize), "Ptr", pToken, "Ptr", 0, "Ptr*", pszValue) 22 | if (FAILED(hr)) { 23 | MsgBox Bailing out 24 | ExitApp 2 25 | } 26 | hr := DllCall(NumGet(NumGet(pToken+0)+16*A_PtrSize), "Ptr", pToken, "Ptr*", pszCoMemTokenId) 27 | if (FAILED(hr)) { 28 | MsgBox Bailing out 29 | ExitApp 3 30 | } 31 | voices[StrGet(pszCoMemTokenId, "UTF-16")] := StrGet(pszValue, "UTF-16") 32 | DllCall("ole32\CoTaskMemFree", "Ptr", pszValue) 33 | DllCall("ole32\CoTaskMemFree", "Ptr", pszCoMemTokenId) 34 | ObjRelease(pToken) 35 | } 36 | prompt := "Pick a voice by its number:" 37 | for k, v in voices 38 | prompt .= "`r`n" . A_Index . ": " v 39 | InputBox, TheChosenOne,, %prompt% 40 | if (ErrorLevel == 0) { 41 | for k, v in voices { 42 | if (A_Index == TheChosenOne) { 43 | hr := DllCall(NumGet(NumGet(cpSpObjectTokenCategory+0)+19*A_PtrSize), "Ptr", cpSpObjectTokenCategory, "WStr", k) 44 | break 45 | } 46 | } 47 | } 48 | } 49 | ObjRelease(cpSpEnumTokens) 50 | } 51 | 52 | ObjRelease(cpSpObjectTokenCategory) 53 | } 54 | 55 | SpGetCategoryFromId(pszCategoryId, ByRef ppCategory, fCreateIfNotExist := False) 56 | { 57 | static CLSID_SpObjectTokenCategory := "{A910187F-0C7A-45AC-92CC-59EDAFB77B53}" 58 | ,ISpObjectTokenCategory := "{2D3D3845-39AF-4850-BBF9-40B49780011D}" 59 | 60 | hr := 0 61 | try { 62 | cpTokenCategory := ComObjCreate(CLSID_SpObjectTokenCategory, ISpObjectTokenCategory) 63 | } catch e { 64 | ; No, A_LastError or ErrorLevel doesn't contain the error code on its own and I CBA to use CoCreateInstance directly 65 | if (RegExMatch(e.Message, "0[xX][0-9a-fA-F]+", errCode)) { ; https://stackoverflow.com/a/9221391 66 | hr := errCode + 0 67 | } else { 68 | hr := 0x80004005 69 | } 70 | } 71 | 72 | if (SUCCEEDED(hr)) 73 | { 74 | hr := DllCall(NumGet(NumGet(cpTokenCategory+0)+15*A_PtrSize), "Ptr", cpTokenCategory, "WStr", pszCategoryId, "Int", fCreateIfNotExist) 75 | } 76 | 77 | if (SUCCEEDED(hr)) 78 | { 79 | ppCategory := cpTokenCategory 80 | } 81 | else 82 | { 83 | if (cpTokenCategory) 84 | ObjRelease(cpTokenCategory) 85 | } 86 | 87 | return hr 88 | } 89 | 90 | ; https://github.com/maul-esel/AHK-Util-Funcs/blob/master/FAILED.ahk 91 | SUCCEEDED(hr) 92 | { 93 | return hr != "" && hr >= 0x00 94 | } 95 | 96 | FAILED(hr) 97 | { 98 | return hr == "" || hr < 0 99 | } -------------------------------------------------------------------------------- /SetRestrictedProcessDacl.ahk: -------------------------------------------------------------------------------- 1 | SetRestrictedProcessDacl() 2 | { 3 | ret := False 4 | 5 | hCurProc := DllCall("GetCurrentProcess", "Ptr") 6 | if (!DllCall("advapi32\OpenProcessToken", "Ptr", hCurProc, "UInt", TOKEN_QUERY := 0x0008, "Ptr*", hToken)) 7 | return ret 8 | 9 | if (!_GetTokenInformation(hToken, TokenUser := 1, 0, 0, dwLengthNeeded)) 10 | if (A_LastError == 122 && VarSetCapacity(TOKEN_USER, dwLengthNeeded)) ; ERROR_INSUFFICIENT_BUFFER 11 | if (_GetTokenInformation(hToken, TokenUser, &TOKEN_USER, dwLengthNeeded, dwLengthNeeded)) { 12 | SECURITY_MAX_SID_SIZE := 68 13 | SIDs := {"WinWorldSid": "1", "WinLocalSystemSid": "22", "WinBuiltinAdministratorsSid": "26"} 14 | for k, v in SIDs { 15 | SIDs.SetCapacity(k, (cbSid := SECURITY_MAX_SID_SIZE)) 16 | if (!DllCall("advapi32\CreateWellKnownSid", "UInt", v+0, "Ptr", 0, "Ptr", SIDs.GetAddress(k), "UInt*", cbSid)) { 17 | DllCall("CloseHandle", "Ptr", hToken) 18 | return ret 19 | } 20 | } 21 | 22 | EA := [{ "grfAccessPermissions": PROCESS_ALL_ACCESS := (STANDARD_RIGHTS_REQUIRED := 0x000F0000) | (SYNCHRONIZE := 0x00100000) | 0xFFFF ; 0xFFF for XP and 2000 23 | ,"grfAccessMode": GRANT_ACCESS := 1 24 | ,"grfInheritance": NO_INHERITANCE := 0 25 | ,"TrusteeForm": TRUSTEE_IS_SID := 0 26 | ,"TrusteeType": TRUSTEE_IS_WELL_KNOWN_GROUP := 5 27 | ,"ptstrName": SIDs.GetAddress("WinLocalSystemSid")} 28 | ,{ "grfAccessPermissions": PROCESS_ALL_ACCESS 29 | ,"grfAccessMode": GRANT_ACCESS 30 | ,"grfInheritance": NO_INHERITANCE 31 | ,"TrusteeForm": TRUSTEE_IS_SID 32 | ,"TrusteeType": TRUSTEE_IS_WELL_KNOWN_GROUP 33 | ,"ptstrName": SIDs.GetAddress("WinBuiltinAdministratorsSid")} 34 | ,{ "grfAccessPermissions": PROCESS_QUERY_LIMITED_INFORMATION := 0x1000 | PROCESS_CREATE_PROCESS := 0x0080 35 | ,"grfAccessMode": GRANT_ACCESS 36 | ,"grfInheritance": NO_INHERITANCE 37 | ,"TrusteeForm": TRUSTEE_IS_SID 38 | ,"TrusteeType": TRUSTEE_IS_USER := 1 39 | ,"ptstrName": NumGet(TOKEN_USER,, "Ptr")} ; user script is running under 40 | ,{ "grfAccessPermissions": PROCESS_ALL_ACCESS 41 | ,"grfAccessMode": DENY_ACCESS := 3 42 | ,"grfInheritance": NO_INHERITANCE 43 | ,"TrusteeForm": TRUSTEE_IS_SID 44 | ,"TrusteeType": TRUSTEE_IS_WELL_KNOWN_GROUP 45 | ,"ptstrName": SIDs.GetAddress("WinWorldSid")}] 46 | 47 | padding := A_PtrSize == 8 ? 4 : 0 48 | cbEXPLICIT_ACCESS_W := (4 * 3) + padding + (A_PtrSize + (4 * 3) + padding + A_PtrSize) 49 | VarSetCapacity(EXPLICIT_ACCESS_W, cbEXPLICIT_ACCESS_W * EA.MaxIndex(), 0) 50 | for i, v in EA { 51 | thisEA := cbEXPLICIT_ACCESS_W * (i - 1) 52 | NumPut(v.grfAccessPermissions, EXPLICIT_ACCESS_W, thisEA, "UInt") 53 | NumPut(v.grfAccessMode, EXPLICIT_ACCESS_W, thisEA + 4, "UInt") 54 | NumPut(v.grfInheritance, EXPLICIT_ACCESS_W, thisEA + (4 * 2), "UInt") 55 | NumPut(v.TrusteeForm, EXPLICIT_ACCESS_W, thisEA + ((4 * 3) + padding + A_PtrSize + 4), "UInt") 56 | NumPut(v.TrusteeType, EXPLICIT_ACCESS_W, thisEA + ((4 * 3) + padding + A_PtrSize + (4 * 2)), "UInt") 57 | NumPut(v.ptstrName, EXPLICIT_ACCESS_W, thisEA + ((4 * 3) + padding + A_PtrSize + (4 * 3) + padding), "Ptr") 58 | } 59 | 60 | if (!DllCall("advapi32\SetEntriesInAcl", "UInt", EA.MaxIndex(), "Ptr", &EXPLICIT_ACCESS_W, "Ptr", 0, "Ptr*", pNewDacl)) { 61 | ret := !DllCall("Advapi32\SetSecurityInfo", "Ptr", hCurProc, "UInt", SE_KERNEL_OBJECT := 6, "UInt", DACL_SECURITY_INFORMATION := 0x00000004, "Ptr", 0, "Ptr", 0, "Ptr", pNewDacl, "Ptr", 0) 62 | DllCall("LocalFree", "Ptr", pNewDacl, "Ptr") 63 | } 64 | } 65 | 66 | DllCall("CloseHandle", "Ptr", hToken) 67 | return ret 68 | } 69 | 70 | _GetTokenInformation(TokenHandle, TokenInformationClass, ByRef TokenInformation, TokenInformationLength, ByRef ReturnLength, _tokenInfoType := "Ptr") { 71 | return DllCall("advapi32\GetTokenInformation", "Ptr", TokenHandle, "UInt", TokenInformationClass, _tokenInfoType, TokenInformation, "UInt", TokenInformationLength, "UInt*", ReturnLength) 72 | } -------------------------------------------------------------------------------- /SetThemeFromdotThemeFile.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | ; An alternative to selecting a .theme file by double-clicking on it and then closing the resulting personalisation window afterwards manually 4 | 5 | ; Source: C:\Windows\diagnostics\system\AERO\CL_Utility.ps1 6 | 7 | MsgBox This will change your Windows theme to Windows 7's classic one. Exit now from the tray menu if you do not want this. 8 | 9 | themePath := A_WinDir . "\Resources\Ease of Access Themes\classic.theme" ; Change as needed 10 | if (FileExist(themePath)) 11 | { 12 | try themeManager := ComObjCreate(CLSID_IThemeManager := "{C04B329E-5823-4415-9C93-BA44688947B0}", IID_IThemeManager := "{0646EBBE-C1B7-4045-8FD0-FFD65D3FC792}") 13 | if (themeManager) { 14 | themeBstr := DllCall("oleaut32\SysAllocString", "WStr", themePath, "Ptr") 15 | if (themeBstr) { 16 | DllCall(NumGet(NumGet(themeManager+0)+4*A_PtrSize), "Ptr", themeManager, "Ptr", themeBstr) ; ::ApplyTheme 17 | DllCall("oleaut32\SysFreeString", "Ptr", themeBstr) 18 | } 19 | ObjRelease(themeManager) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SetWindows10LockScreenPicture/README.txt: -------------------------------------------------------------------------------- 1 | This is a script that uses the raw RT COM API directly to change your (i.e. the logged on user) Windows 10 lockscreen background picture. No dependencies other than Windows 10 and AutoHotkey itself. 2 | 3 | For something more robust, you might consider https://github.com/Sauler/PowershellUtils instead. -------------------------------------------------------------------------------- /SetWindows10LockScreenPicture/SetWindows10LockScreenPicture.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | ; DllCall("ole32.dll\OleUninitialize") 4 | ; DllCall("combase.dll\RoInitialize", "UInt", RO_INIT_MULTITHREADED := 1) 5 | 6 | filename := "C:\Users\Me\Pictures\Wallpapers\affinity_street_romain_trystram_01.jpg" 7 | 8 | if (FileExist(filename)) { 9 | ; 1. Create StorageFile obj for pic 10 | VarSetCapacity(IIDStorageFileStatics, 16), VA_GUID(IIDStorageFileStatics := "{5984C710-DAF2-43C8-8BB4-A4D3EACFD03F}") 11 | StorageFile := new HSTRING("Windows.Storage.StorageFile") 12 | if (!DllCall("combase.dll\RoGetActivationFactory", "Ptr", StorageFile.str, "Ptr", &IIDStorageFileStatics, "Ptr*", instStorageFile)) { 13 | if (!DllCall(NumGet(NumGet(instStorageFile+0)+6*A_PtrSize), "Ptr", instStorageFile, "Ptr", (_ := new HSTRING(filename)).str, "Ptr*", sfileasyncwrapper)) { 14 | ; 2. Said SF obj gets created async. Keep checking (in a sync manner) to see if actual SF obj is created 15 | ; Yes, this isn't a good way, but it's not like I usually expect COM objects to be returned async 16 | sfileasyncinfo := ComObjQuery(sfileasyncwrapper, IID_IAsyncInfo := "{00000036-0000-0000-C000-000000000046}") 17 | while (!DllCall(NumGet(NumGet(sfileasyncinfo+0)+7*A_PtrSize), "Ptr", sfileasyncinfo, "UInt*", status) && !status) 18 | Sleep 100 19 | if (status != 1) 20 | ExitApp 1 21 | ObjRelease(sfileasyncinfo) 22 | 23 | ; 3. It has! Finally take pointer to sf obj 24 | DllCall(NumGet(NumGet(sfileasyncwrapper+0)+8*A_PtrSize), "Ptr", sfileasyncwrapper, "Ptr*", sfile) 25 | 26 | ; 4. Create LockScreen obj 27 | VarSetCapacity(IIDLockScreenStatics, 16), VA_GUID(IIDLockScreenStatics := "{3EE9D3AD-B607-40AE-B426-7631D9821269}") 28 | lockScreen := new HSTRING("Windows.System.UserProfile.LockScreen") 29 | if (!DllCall("combase.dll\RoGetActivationFactory", "Ptr", lockScreen.str, "Ptr", &IIDLockScreenStatics, "Ptr*", instLockScreen)) { 30 | ; Tell ls obj to set ls pic from sf obj 31 | DllCall(NumGet(NumGet(instLockScreen+0)+8*A_PtrSize), "Ptr", instLockScreen, "Ptr", sfile, "Ptr*", Operation) 32 | 33 | sfileasyncinfo := ComObjQuery(Operation, IID_IAsyncInfo := "{00000036-0000-0000-C000-000000000046}") 34 | while (!DllCall(NumGet(NumGet(sfileasyncinfo+0)+7*A_PtrSize), "Ptr", sfileasyncinfo, "UInt*", status) && !status) 35 | Sleep 100 36 | ObjRelease(sfileasyncinfo) 37 | 38 | ObjRelease(Operation) 39 | ObjRelease(instLockScreen) 40 | } 41 | 42 | ObjRelease(sfile) 43 | ObjRelease(sfileasyncwrapper) 44 | } 45 | ObjRelease(instStorageFile) 46 | } 47 | } 48 | 49 | class HSTRING { 50 | static lpWindowsCreateString := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "combase.dll", "Ptr"), "AStr", "WindowsCreateString", "Ptr") 51 | static lpWindowsDeleteString := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "combase.dll", "Ptr"), "AStr", "WindowsDeleteString", "Ptr") 52 | 53 | __New(sourceString, length := 0) { 54 | this.str := !DllCall(HSTRING.lpWindowsCreateString, "WStr", sourceString, "UInt", length ? length : StrLen(sourceString), "Ptr*", string) ? string : 0 55 | } 56 | 57 | __Delete() { 58 | DllCall(HSTRING.lpWindowsDeleteString, "Ptr", this.str) 59 | } 60 | } 61 | 62 | ; From Lexikos' VA.ahk: Convert string to binary GUID structure. 63 | VA_GUID(ByRef guid_out, guid_in="%guid_out%") { 64 | if (guid_in == "%guid_out%") 65 | guid_in := guid_out 66 | if guid_in is integer 67 | return guid_in 68 | VarSetCapacity(guid_out, 16, 0) 69 | DllCall("ole32\CLSIDFromString", "wstr", guid_in, "ptr", &guid_out) 70 | return &guid_out 71 | } -------------------------------------------------------------------------------- /ShowNetworkNames.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv 2 | VarSetCapacity(adapterGuid, 16), VarSetCapacity(adapterGuidStr, 140), adapters := GetAdaptersAddresses() 3 | 4 | ; Thanks to Lexikos and HotKeyIt for correcting my attempts 5 | 6 | for INetwork in ComObjCreate("{DCB00C01-570F-4A9B-8D69-199FDBA5723B}").GetNetworks(1) { ; NLM_ENUM_NETWORK_CONNECTED ; NLM_ENUM_NETWORK_ALL := 3 7 | ; INetwork.SetCategory(1) ; NLM_NETWORK_CATEGORY_PRIVATE - uncommenting designates the connected network as "Private". 0 would set it as "Public". You need to be admin for this to have an effect 8 | profileName := INetwork.GetName() 9 | for k, v in INetwork.GetNetworkConnections() { 10 | try if ((INetworkConnection := ComObjQuery(k, "{DCB00005-570F-4A9B-8D69-199FDBA5723B}"))) { 11 | if (DllCall(NumGet(NumGet(INetworkConnection+0)+12*A_PtrSize), "Ptr", INetworkConnection, "Ptr", &adapterGuid) == 0) { ; ::GetAdapterId 12 | if (DllCall("ole32\StringFromGUID2", "Ptr", &adapterGuid, "WStr", adapterGuidStr, "Int", 68)) { 13 | adapterName := adapters[adapterGuidStr].Description 14 | interfaceAlias := adapters[adapterGuidStr].FriendlyName 15 | } 16 | } 17 | ObjRelease(INetworkConnection) 18 | } 19 | } 20 | MsgBox % profileName . "`n" . adapterName . "`n" . interfaceAlias 21 | } 22 | 23 | ; By just me: https://autohotkey.com/boards/viewtopic.php?t=18768 24 | GetAdaptersAddresses() 25 | { 26 | ; initial call to GetAdaptersAddresses to get the size needed 27 | If (DllCall("iphlpapi.dll\GetAdaptersAddresses", "UInt", 2, "UInt", 0, "Ptr", 0, "Ptr", 0, "UIntP", Size) = 111) ; ERROR_BUFFER_OVERFLOW 28 | If !(VarSetCapacity(Buf, Size, 0)) 29 | Return "Memory allocation failed for IP_ADAPTER_ADDRESSES struct" 30 | 31 | ; second call to GetAdapters Addresses to get the actual data we want 32 | If (DllCall("iphlpapi.dll\GetAdaptersAddresses", "UInt", 2, "UInt", 0, "Ptr", 0, "Ptr", &Buf, "UIntP", Size) != 0) ; NO_ERROR 33 | Return "Call to GetAdaptersAddresses failed with error: " . A_LastError 34 | 35 | Addr := &Buf 36 | Adapters := {} 37 | While (Addr) { 38 | AdapterName := StrGet(NumGet(Addr + 8, A_PtrSize, "Uptr"), "CP0") 39 | Description := StrGet(NumGet(Addr + 8, A_PtrSize * 7, "UPtr"), "UTF-16") 40 | FriendlyName := StrGet(NumGet(Addr + 8, A_PtrSize * 8, "UPtr"), "UTF-16") 41 | Adapters[AdapterName] := {Description: Description, FriendlyName: FriendlyName} 42 | Addr := NumGet(Addr + 8, "UPtr") ; *Next 43 | } 44 | Return Adapters 45 | } -------------------------------------------------------------------------------- /ShowWindows10TrayClock.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv 2 | 3 | ControlGet, hClock, Hwnd,, TrayClockWClass1, ahk_class Shell_TrayWnd ; https://autohotkey.com/board/topic/70770-win7-taskbar-clock-toggle/ 4 | if (hClock) { 5 | VarSetCapacity(IID_IAccessible, 16), DllCall("ole32\CLSIDFromString", "WStr", "{618736e0-3c3d-11cf-810c-00aa00389b71}", "Ptr", &IID_IAccessible) 6 | if (DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hClock, "UInt", OBJID_CLIENT := 0xFFFFFFFC, "Ptr", &IID_IAccessible, "Ptr*", accTrayClock)) 7 | return 8 | VarSetCapacity(variant, A_PtrSize == 8 ? 24 : 16, 0), NumPut(VT_I4 := 3, variant,, "UShort") 9 | if (A_PtrSize == 4) ; Thanks Eidola: https://autohotkey.com/boards/viewtopic.php?p=111355#p111355 10 | DllCall(NumGet(NumGet(accTrayClock+0)+25*A_PtrSize), "Ptr", accTrayClock, "Int64", NumGet(variant, 0, "Int64"), Int64, NumGet(variant, 8, "Int64")) ; IAccessible::DoDefaultAction 11 | else 12 | DllCall(NumGet(NumGet(accTrayClock+0)+25*A_PtrSize), "Ptr", accTrayClock, "Ptr", &variant) ; IAccessible::DoDefaultAction 13 | ObjRelease(accTrayClock) 14 | } 15 | 16 | /* ControlGet, hClock, Hwnd,, TrayClockWClass1, ahk_class Shell_TrayWnd ; https://autohotkey.com/board/topic/70770-win7-taskbar-clock-toggle/ 17 | PostMessage, 0x466, 1, 0,, ahk_id %hClock% */ -------------------------------------------------------------------------------- /ThinkPadScripts/EnableTrackPointAndButtonsOnlyWhenFnIsHeld.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 3 | AutoTrim, Off 4 | ListLines, Off 5 | SetBatchLines, -1 6 | #KeyHistory 0 7 | 8 | SP_DisableState := 0x10000171 9 | SynAPI := ComObjCreate("SynCtrl.SynAPICtrl") 10 | SynAPI.Initialize 11 | SynDev := ComObjCreate("SynCtrl.SynDeviceCtrl") 12 | SynDev.Select(SynAPI.FindDevice(SE_ConnectionAny := 0, SE_DeviceIBMCompatibleStick := 4, 0)) 13 | OnExit("AtExit") 14 | SynDev.SetLongProperty(SP_DisableState, True) ; force TrackPoint to be disabled at startup of script 15 | return 16 | 17 | SC163:: 18 | SynDev.SetLongProperty(SP_DisableState, False) ; enable device when Fn pressed 19 | return 20 | 21 | SC163 up:: ; Replace 159 with your key's value. 22 | SynDev.SetLongProperty(SP_DisableState, True) ; disable device when Fn key released 23 | return 24 | 25 | Esc::ExitApp 26 | 27 | AtExit() { 28 | global SynDev, SP_DisableState 29 | SynDev.SetLongProperty(SP_DisableState, False) ; re-enable TP at exit of script 30 | } -------------------------------------------------------------------------------- /ThinkPadScripts/LenovoBatterySetRegisterThresholds.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | AutoTrim, Off 3 | ListLines, Off 4 | SetBatchLines, -1 5 | SetFormat, FloatFast, 0.6 6 | SetFormat, IntegerFast, D 7 | #KeyHistory 0 8 | 9 | ; adapted from heresy's lib 10 | Service_Start(ServiceName) 11 | { 12 | if (!A_IsAdmin) 13 | return true 14 | result := false 15 | 16 | SCM_HANDLE := DllCall("advapi32\OpenSCManager", "Ptr", 0, "Ptr", 0, "UInt", 0x1, "Ptr") 17 | if (SCM_HANDLE) { 18 | if (SC_HANDLE := DllCall("advapi32\OpenService", "Ptr", SCM_HANDLE, "Str", ServiceName, "UInt", 0x10, "Ptr")) { 19 | result := DllCall("advapi32\StartService", "Ptr", SC_HANDLE , "UInt", 0, "Ptr", 0) 20 | DllCall("advapi32\CloseServiceHandle", "Ptr", SC_HANDLE) 21 | } 22 | DllCall("advapi32\CloseServiceHandle", "Ptr", SCM_HANDLE) 23 | if (!SC_HANDLE) ; Service not found 24 | ErrorLevel := -4 25 | } 26 | if (result) 27 | ErrorLevel := 0 28 | return result 29 | } 30 | 31 | ; all credits to XYUU 32 | WatchLenovoBatteryKey_SetRegisterThresholds(bId, start, stop) 33 | { 34 | ; yes, this is ugly, but w/e - I'm not a programmer :-) 35 | start := ((start >= 1 && start <= 100)) ? start - 1 : (start == 0 ? start : -1) 36 | stop := ((stop >= 0 && start <= 100)) ? (stop == 100 ? 0x00 : stop) : -1 37 | 38 | if (start != -1 || stop != -1) 39 | { 40 | INVALID_HANDLE_VALUE := -1 41 | GENERIC_READ := 0x80000000 ;, GENERIC_WRITE := 0x40000000 42 | FILE_SHARE_READ := 0x00000001 ;, FILE_SHARE_WRITE := 0x00000002 43 | 44 | Service_Start("IBMPMDRV") ; make sure the IBM Power Management driver is running 45 | IBMPmDrv := DllCall("CreateFile", "Str", "\\.\IBMPmDrv", "UInt", GENERIC_READ, "UInt", FILE_SHARE_READ, "Ptr", 0, "UInt", OPEN_EXISTING := 3, "UInt", 0, "Ptr", 0, "Ptr") 46 | if (IBMPmDrv && IBMPmDrv != INVALID_HANDLE_VALUE) 47 | { 48 | currStartValue := currStopValue := 0x00 49 | 50 | ; get the current threshold values 51 | for i, ioctl in [GET_BATTERY_THRESH_START := 0x22262C, GET_BATTERY_THRESH_STOP := 0x222634] 52 | { 53 | VarSetCapacity(GET_BATTERY_THRESH_IN, reqBufSzGetIn := 4, 0), VarSetCapacity(GET_BATTERY_THRESH_OUT, reqBufSzGetOut := 4, 0) 54 | NumPut(bId, GET_BATTERY_THRESH_IN,, "UChar") 55 | if ((DllCall("DeviceIoControl", "Ptr", IBMPmDrv, "UInt", ioctl, "Ptr", &GET_BATTERY_THRESH_IN, "UInt", reqBufSzGetIn, "Ptr", &GET_BATTERY_THRESH_OUT, "UInt", reqBufSzGetOut, "UInt*", actualOutSz, "Ptr", 0)) && actualOutSz == reqBufSzGetOut) { 56 | if (ioctl == GET_BATTERY_THRESH_START) 57 | currStartValue := NumGet(GET_BATTERY_THRESH_OUT,, "UChar") 58 | else if (ioctl == GET_BATTERY_THRESH_STOP) 59 | currStopValue := NumGet(GET_BATTERY_THRESH_OUT,, "UChar") 60 | } 61 | } 62 | 63 | ; set the new thresholds if they're different 64 | for i, ioctl in [SET_BATTERY_THRESH_START := 0x222630, SET_BATTERY_THRESH_STOP := 0x222638] 65 | { 66 | val := -1 67 | if (ioctl == SET_BATTERY_THRESH_START) 68 | { 69 | if (start != currStartValue) 70 | val := start 71 | } 72 | else if (ioctl == SET_BATTERY_THRESH_STOP) 73 | { 74 | if (stop != currStopValue) 75 | val := stop 76 | } 77 | 78 | if (val > -1) 79 | { 80 | VarSetCapacity(SET_BATTERY_THRESH_IN, reqBufSz := 4, 0) 81 | NumPut(val, SET_BATTERY_THRESH_IN,, "UChar"), NumPut(bId, SET_BATTERY_THRESH_IN, 1, "UChar") 82 | DllCall("DeviceIoControl", "Ptr", IBMPmDrv, "UInt", ioctl, "Ptr", &SET_BATTERY_THRESH_IN, "UInt", reqBufSz, "Ptr", 0, "UInt", 0, "Ptr", 0, "Ptr", 0) 83 | } 84 | } 85 | 86 | DllCall("CloseHandle", "Ptr", IBMPmDrv) 87 | } 88 | } 89 | } 90 | 91 | MsgBox This will set your battery charging thresholds to start at 20`% and to stop at 90`%. Exit now from the tray menu if you do not want this. 92 | 93 | WatchLenovoBatteryKey_SetRegisterThresholds(0x01, 20, 90) ; DEFAULT_BATTERY_ID == 0x01, see https://github.com/teleshoes/tpacpi-bat/blob/master/battery_asl#L200 94 | -------------------------------------------------------------------------------- /ThinkPadScripts/README.md: -------------------------------------------------------------------------------- 1 | Scripts specific to my X230 laptop. 2 | 3 | EnableTrackPointAndButtonsOnlyWhenFnIsHeld - does what it says. You can press Escape to exit the script at any time. Credits: 4 | 5 | * The people in this thread https://autohotkey.com/board/topic/65849-controlling-synaptics-touchpad-using-com-api/ 6 | 7 | * Synaptics for their SDK - specifically the Disabler program 8 | 9 | LenovoBatterySetRegisterThresholds - asks the IBM power management driver directly to set the battery thresholds, removing the only reason I might have had to keep Lenovo's UWP abomination around. 10 | The method used comes from RE work by XYUU. See his blog post [here](https://zhuanlan.zhihu.com/p/20706403) and his application [here](https://github.com/XYUU/BatteryUtils). 11 | 12 | Things to be aware of: 13 | 14 | * When you run it, it will set the thresholds right away. You should change them before running the script for the first time. 15 | 16 | * This script just asks the IBM driver to set the thresholds and then exits. It is not persistent. And for that matter, the threshold setting changes it makes might not always be remembered by the EC. I run this on startup. 17 | 18 | * If you don't like the script, just have it set your thresholds back to the original values (0, 100) and delete it - it leaves nothing else lying around 19 | 20 | * Lenovo software itself might reset the thresholds. I uninstalled Lenovo Settings, the ThinkPad Settings Dependency package and Lenovo System Interface Foundation 21 | 22 | * If the script is run elevated (not a requirement), it will try to make sure the IBM power management driver is started 23 | 24 | I do have an AutoHotkey script that makes the microphone LED blink when the CapsLock key is pressed, but [this](https://gitlab.com/valinet/thinkpad-leds-control) is a better program for it. -------------------------------------------------------------------------------- /ToggleWindows10TabletMode.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv 2 | SetBatchLines -1 3 | ListLines Off 4 | #NoTrayIcon 5 | 6 | TABLETMODESTATE_DESKTOPMODE := 0x0 7 | TABLETMODESTATE_TABLETMODE := 0x1 8 | 9 | TabletModeController_GetMode(TabletModeController, ByRef mode) { 10 | return DllCall(NumGet(NumGet(TabletModeController+0),3*A_PtrSize), "Ptr", TabletModeController, "UInt*", mode) 11 | } 12 | 13 | TabletModeController_SetMode(TabletModeController, _TABLETMODESTATE, _TMCTRIGGER := 4) { 14 | return DllCall(NumGet(NumGet(TabletModeController+0),4*A_PtrSize), "Ptr", TabletModeController, "UInt", _TABLETMODESTATE, "UInt", _TMCTRIGGER) 15 | } 16 | 17 | MsgBox This will put Windows 10 into Tablet Mode. Exit now from the tray menu if you do not want this. (You can go back from the Windows 10 settings or by running this script again.) 18 | 19 | ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}") 20 | TabletModeController := ComObjQuery(ImmersiveShell, "{4fda780a-acd2-41f7-b4f2-ebe674c9bf2a}", "{4fda780a-acd2-41f7-b4f2-ebe674c9bf2a}") 21 | 22 | if (TabletModeController_GetMode(TabletModeController, mode) == 0) 23 | TabletModeController_SetMode(TabletModeController, mode == TABLETMODESTATE_DESKTOPMODE ? TABLETMODESTATE_TABLETMODE : TABLETMODESTATE_DESKTOPMODE) 24 | 25 | ObjRelease(TabletModeController), TabletModeController := 0 26 | ObjRelease(ImmersiveShell), ImmersiveShell := 0 ; Can be freed after TabletModeController is created, instead -------------------------------------------------------------------------------- /ToggleWindows10TabletOSK.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | #NoTrayIcon 3 | 4 | ; Credits: torvin - https://stackoverflow.com/a/40921638 5 | 6 | try { 7 | ITipInvocation := ComObjCreate("{4ce576fa-83dc-4F88-951c-9d0782b4e376}", "{37c994e7-432b-4834-a2f7-dce1f13b834b}") 8 | DllCall(NumGet(NumGet(ITipInvocation+0)+3*A_PtrSize), "Ptr", ITipInvocation, "Ptr", DllCall("GetDesktopWindow", "Ptr")) 9 | ObjRelease(ITipInvocation) 10 | } catch { 11 | Run %A_ProgramFiles%\Common Files\microsoft shared\ink\TabTip.exe, %A_ProgramFiles%\Common Files\microsoft shared\ink\, UseErrorLevel 12 | } -------------------------------------------------------------------------------- /WinHTTPFileDownloader/README.md: -------------------------------------------------------------------------------- 1 | ![WinHTTPFileDownloader](https://i.imgur.com/HTqb6b6.png) 2 | 3 | A very messy script that downloads a segment of waik_supplement_en-us.iso, written for https://autohotkey.com/boards/viewtopic.php?f=5&t=17370 4 | 5 | There is no buffering mechanism to speak of, it downloads a hardcoded segment from a file determined from a hardcoded URL path to a hardcoded filename. 6 | 7 | just me's [Class_TaskDialog](https://autohotkey.com/boards/viewtopic.php?f=6&t=5711) is needed. 8 | 9 | For something that actually works, you might consider https://github.com/potmdehex/WinInet-Downloader instead. -------------------------------------------------------------------------------- /WinHTTPFileDownloader/WinHTTPFileDownloader.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | SetWorkingDir D:\ ; My RAMDisk, you'll probably want AHK's default of %A_ScriptDir% 3 | SetBatchLines -1 4 | ListLines Off 5 | 6 | #Include Class_TaskDialog.ahk 7 | 8 | if (hModule := WinHttp_Init()) ; load winhttp library. Will fail if not running on a Unicode build of AHK 9 | hSession := WinHttp_Open("WinHTTP Example/1.0", "WINHTTP_ACCESS_TYPE_NO_PROXY", "WINHTTP_NO_PROXY_NAME", "WINHTTP_NO_PROXY_BYPASS") ; Open WinHttp session - set User Agent and proxy settings 10 | 11 | if (hSession) 12 | hConnect := WinHttp_Connect(hSession, "download.microsoft.com", "INTERNET_DEFAULT_HTTP_PORT") ; Not relevant here, but it's worth noting the same connection can be used for multiple requests from the same site to speed up things 13 | 14 | if (hConnect) 15 | hRequest := WinHttp_OpenRequest(hConnect,, "/download/0/4/C/04C805CC-4C04-4D76-BE80-7D67B951CF73/waik_supplement_en-us.iso") ; the path to access from the domain above. WinHttpCrackUrl() (which is not wrapped here) can break down a full URL 16 | 17 | /* 18 | if (hSession) 19 | hConnect := WinHttp_Connect(hSession, "127.0.0.1", 8080) 20 | 21 | if (hConnect) 22 | hRequest := WinHttp_OpenRequest(hConnect,, "/waik_supplement_en-us.iso") 23 | */ 24 | 25 | ; Adding resuming support is, I believe, bytes=%bytesDownloaded%-450673718 and opening the already-existing file in append mode 26 | if (hRequest) 27 | bResults := WinHttp_SendRequest(hRequest, "Range: bytes=336336896-450673718") ; Add header to download the specified range. I *think* adding additional headers is a matter of delimiting them in the same string with `r`n 28 | 29 | if (bResults) 30 | bResults := DllCall("winhttp\WinHttpReceiveResponse", "Ptr", hRequest, "Ptr", NULL) 31 | 32 | if (bResults) 33 | { 34 | ; Get response headers 35 | 36 | ; Determine size of buffer to store headers in 37 | if (!WinHttp_QueryHeaders(hRequest, WINHTTP_QUERY_RAW_HEADERS_CRLF := 22, WINHTTP_HEADER_NAME_BY_INDEX := 0, 0, dwSize := 0, WINHTTP_NO_HEADER_INDEX := 0)) 38 | { 39 | if (A_LastError == 0x7A) ; ERROR_INSUFFICIENT_BUFFER 40 | { 41 | VarSetCapacity(outBuffer, dwSize + 2) ; allocate space needed for the actual headers 42 | if (WinHttp_QueryHeaders(hRequest, WINHTTP_QUERY_RAW_HEADERS_CRLF, WINHTTP_HEADER_NAME_BY_INDEX, &outBuffer, dwSize, WINHTTP_NO_HEADER_INDEX)) 43 | { 44 | ; call WinHttp_QueryHeaders again to actually get the response headers now that there's a buffer with enough space to store the result 45 | responseHeaders := StrGet(&outBuffer, "UTF-16") 46 | 47 | ; I'm sure there's a quicker way than this somewhere to get just the Content-Length... 48 | y := SubStr(responseHeaders, InStr(responseHeaders, "Content-Length: ")) 49 | if (y) 50 | Content_Length := StrSplit(SubStr(y, 1, InStr(y, "`r") - 1), ":", " ")[2] 51 | 52 | ; If the file already exists, you could compare the size of that file with the Content_Length above to see if the file is already downloaded in its entirety 53 | } 54 | } 55 | } 56 | } 57 | 58 | if (bResults) 59 | { 60 | fileName := "7x86winpe.wim" ; save file with this name 61 | 62 | TD := New TaskDialog(FormatTitle("0.00 MB"),, "Downloading " . filename, ["Cancel"]) 63 | TD.SetProgressBar("NONMARQUEE") 64 | TD.SetAlwaysOnTop() 65 | TD.SetCallbackFunc("TaskDialogCustomCallback") 66 | TD.AllowCancel() 67 | 68 | TD.Show() ; blocks, hence the SetTimer awkwardness in the callback 69 | } 70 | 71 | if (!bResults) 72 | MsgBox Error %A_LastError% has occurred 73 | 74 | WinHttp_CloseHandle(hRequest) 75 | WinHttp_CloseHandle(hConnect) 76 | WinHttp_CloseHandle(hSession) 77 | 78 | WinHttp_Deinit(hModule) 79 | ExitApp 80 | 81 | TaskDialogCustomCallback(H, N, W, L, D) 82 | { 83 | global shouldCancel 84 | if (N == 0) ; TDN_CREATED 85 | { 86 | SetTimer, StartDownloading, -5 87 | } 88 | else if (N == 2) ; TDN_BUTTON_CLICKED 89 | { 90 | shouldCancel := true 91 | } 92 | return 0 93 | } 94 | 95 | StartDownloading() 96 | { 97 | global fileName, hRequest, TD, Content_Length, shouldCancel 98 | hFile := FileOpen(fileName, "w") ; open the file named in the first argument for writing 99 | Loop 100 | { 101 | if (shouldCancel) 102 | break 103 | ; A buffering/caching mechanism, like HttpRequest has, instead of instantly writing the recieved to the disk would be nice 104 | if (!WinHttp_QueryDataAvailable(hRequest, dwSize)) 105 | { 106 | TD.TDM_SET_PROGRESS_BAR_STATE("ERROR") 107 | TD.TDM_UPDATE_ELEMENT_TEXT("MAIN", "Error " . A_LastError . " in WinHttpQueryDataAvailable") 108 | shouldCancel := true 109 | break 110 | } 111 | if (VarSetCapacity(pszOutBuffer, dwSize + 1, 0) < dwSize + 1) 112 | { 113 | OutputDebug Out of memory 114 | ExitApp 115 | } 116 | if (!WinHttp_ReadData(hRequest, &pszOutBuffer, dwSize, dwDownloaded)) 117 | { 118 | TD.TDM_SET_PROGRESS_BAR_STATE("ERROR") 119 | TD.TDM_UPDATE_ELEMENT_TEXT("MAIN", "Error " . A_LastError . " in WinHttpReadData") 120 | ; shouldCancel := true 121 | } 122 | else 123 | { 124 | hFile.RawWrite(pszOutBuffer, dwDownloaded) ; write the downloaded bytes to the file 125 | 126 | totalDownloaded += dwDownloaded 127 | pct := Ceil((totalDownloaded * 100) / Content_Length) 128 | if (pct != lastPct || pct >= 100) { ; Just for that last update 129 | TD.TDM_SET_PROGRESS_BAR_POS(pct), lastPct := pct 130 | TD.TDM_UPDATE_ELEMENT_TEXT("MAIN", FormatTitle(FormatBytes(totalDownloaded))) ; Move outside of the if block for more frequent updates at the cost of more CPU usage 131 | } 132 | } 133 | if (dwSize <= 0) 134 | break 135 | } 136 | if (!shouldCancel) 137 | SetTimer, CloseTD, -3000 138 | hFile.Close() 139 | } 140 | 141 | FormatTitle(bytes) 142 | { 143 | global Content_Length 144 | return "Downloaded " . bytes . (Content_Length ? " of " . FormatBytes(Content_Length) : "") 145 | } 146 | 147 | ; By SKAN 148 | FormatBytes(bytes) { 149 | VarSetCapacity(pszBuf, 32) 150 | return DllCall("Shlwapi\StrFormatByteSizeW", "Int64", bytes, "Ptr", &pszBuf, "UInt", 32, "WStr") 151 | } 152 | 153 | CloseTD() 154 | { 155 | global TD 156 | TD.TDM_CLICK_BUTTON(8) ; Manually trigger click of the cancel button 157 | } 158 | 159 | ; --- Incomplete, bad wrapper library follows 160 | 161 | WinHttp_Init() 162 | { 163 | if (!A_IsUnicode) 164 | return 0 165 | return DllCall("LoadLibrary", "Str", "winhttp.dll", "Ptr") 166 | } 167 | 168 | WinHttp_Deinit(hModule) 169 | { 170 | DllCall("FreeLibrary", "Ptr", hModule) 171 | } 172 | 173 | WinHttp_CloseHandle(hInternet) 174 | { 175 | if (hInternet) 176 | DllCall("winhttp\WinHttpCloseHandle", "Ptr", hInternet) 177 | } 178 | 179 | WinHttp_Open(userAgent, proxyType := "WINHTTP_ACCESS_TYPE_DEFAULT_PROXY", proxyName := "", proxyBypass := "", flags := "") 180 | { 181 | if (!userAgent) 182 | return 0 183 | 184 | if proxyType not in WINHTTP_ACCESS_TYPE_NO_PROXY,WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,WINHTTP_ACCESS_TYPE_NAMED_PROXY 185 | return 0 186 | 187 | if (!proxyName || proxyName == "WINHTTP_NO_PROXY_NAME") 188 | { 189 | pnType := "Ptr" 190 | proxyName := _WinHttp_DWordFromWHConstant("WINHTTP_NO_PROXY_NAME") 191 | } 192 | else 193 | { 194 | pnType := "WStr" 195 | } 196 | 197 | if (!proxyBypass || proxyBypass == "WINHTTP_NO_PROXY_BYPASS") 198 | { 199 | pbType := "Ptr" 200 | proxyBypass := _WinHttp_DWordFromWHConstant("WINHTTP_NO_PROXY_BYPASS") 201 | } 202 | else 203 | { 204 | pbType := "WStr" 205 | } 206 | 207 | if (flags && flags != "WINHTTP_FLAG_ASYNC") 208 | return 0 209 | else 210 | flags := flags ? _WinHttp_DWordFromWHConstant("WINHTTP_FLAG_ASYNC") : 0 211 | 212 | return DllCall("winhttp\WinHttpOpen", "WStr", userAgent 213 | ,"UInt", _WinHttp_DWordFromWHConstant(proxyType) 214 | ,pnType, proxyName 215 | ,pbType, proxyBypass 216 | ,"UInt", flags 217 | ,"Ptr") 218 | } 219 | 220 | WinHttp_Connect(hSession, ServerName, ServerPort := "INTERNET_DEFAULT_PORT") 221 | { 222 | if (!hSession || !ServerName) 223 | return 0 224 | 225 | if ServerPort is not integer 226 | { 227 | if ServerPort not in INTERNET_DEFAULT_PORT,INTERNET_DEFAULT_HTTP_PORT,INTERNET_DEFAULT_HTTPS_PORT 228 | return 0 229 | ServerPort := _WinHttp_DWordFromWHConstant(ServerPort) 230 | } 231 | 232 | return DllCall("winhttp\WinHttpConnect", "Ptr", hSession 233 | ,"WStr", ServerName 234 | ,"UInt", ServerPort 235 | ,"UInt", 0 236 | ,"Ptr") 237 | } 238 | 239 | WinHttp_OpenRequest(hConnect, verb := "GET", objectName := "", httpVersion := "", referrer := "WINHTTP_NO_REFERER", acceptTypes := "WINHTTP_DEFAULT_ACCEPT_TYPES", flags := "") 240 | { 241 | if (!hConnect || !objectName) ; don't ask 242 | return 0 243 | 244 | if (!referrer || referrer == "WINHTTP_NO_REFERER") 245 | referrer := _WinHttp_DWordFromWHConstant("WINHTTP_NO_REFERER") 246 | 247 | if (!acceptTypes || acceptTypes == "WINHTTP_DEFAULT_ACCEPT_TYPES") 248 | acceptTypes := _WinHttp_DWordFromWHConstant("WINHTTP_DEFAULT_ACCEPT_TYPES") 249 | 250 | if (flags) 251 | { 252 | if (!InStr(flags, "|")) 253 | flags := flags . "|" 254 | flagsSplit := StrSplit(flags, "|", " `r`n`t") 255 | actualFlags := 0 256 | Loop % flagsSplit.MaxIndex() 257 | { 258 | if (flagsSplit[A_Index]) 259 | { 260 | if flagsSplit[A_Index] not in WINHTTP_FLAG_SECURE,WINHTTP_FLAG_ESCAPE_PERCENT 261 | ,WINHTTP_FLAG_NULL_CODEPAGE,WINHTTP_FLAG_BYPASS_PROXY_CACHE 262 | ,WINHTTP_FLAG_REFRESH,WINHTTP_FLAG_ESCAPE_DISABLE,WINHTTP_FLAG_ESCAPE_DISABLE_QUERY 263 | { 264 | return 0 265 | } 266 | else 267 | { 268 | actualFlags := actualFlags | _WinHttp_DWordFromWHConstant(flagsSplit[A_Index]) 269 | } 270 | } 271 | } 272 | } 273 | else 274 | { 275 | actualFlags := 0 276 | } 277 | 278 | return DllCall("winhttp\WinHttpOpenRequest", "Ptr", hConnect 279 | ,"WStr", verb 280 | ,"WStr", objectName 281 | ,httpVersion ? "WStr" : "Ptr", httpVersion ? httpVersion : 0 282 | ,referrer ? "WStr" : "Ptr", referrer 283 | ,acceptTypes ? "WStr" : "Ptr", acceptTypes 284 | ,"UInt", actualFlags 285 | ,"Ptr") 286 | } 287 | 288 | WinHttp_SendRequest(hRequest, headers := "WINHTTP_NO_ADDITIONAL_HEADERS", headersLength := -1 289 | , optionalData := "WINHTTP_NO_REQUEST_DATA", optionalDataLength := 0, totalLength := 0 290 | , context := 0) 291 | { 292 | if (!headers || headers == "WINHTTP_NO_ADDITIONAL_HEADERS") 293 | headers := _WinHttp_DWordFromWHConstant("WINHTTP_NO_ADDITIONAL_HEADERS") 294 | 295 | if (!optionalData || optionalData == "WINHTTP_NO_REQUEST_DATA") 296 | optionalData := _WinHttp_DWordFromWHConstant("WINHTTP_NO_REQUEST_DATA") 297 | 298 | return DllCall("winhttp\WinHttpSendRequest", "Ptr", hRequest 299 | ,headers ? "WStr" : "Ptr", headers 300 | ,"UInt", headers ? headersLength : 0 301 | ,optionalData ? "WStr" : "Ptr", optionalData 302 | ,"UInt", optionalDataLength 303 | ,"UInt", totalLength 304 | ,"Ptr", context) 305 | } 306 | 307 | WinHttp_QueryDataAvailable(hRequest, ByRef dwNumberOfBytesAvailable) 308 | { 309 | if (!IsByRef(dwNumberOfBytesAvailable)) 310 | return false 311 | return DllCall("winhttp\WinHttpQueryDataAvailable", "Ptr", hRequest, "UInt*", dwNumberOfBytesAvailable) 312 | } 313 | 314 | WinHttp_ReadData(hRequest, pointerToBuffer, bufferSize, ByRef dwDownloaded) 315 | { 316 | return DllCall("winhttp\WinHttpReadData", "Ptr", hRequest, "Ptr", pointerToBuffer, "UInt", bufferSize, "UInt*", dwDownloaded) 317 | } 318 | 319 | WinHttp_QueryHeaders(hRequest, infoLevel, name, ptrBuffer, ByRef bufferSize, headerIndex) 320 | { 321 | if (!IsByRef(bufferSize)) 322 | return false 323 | ; Sorry, too many flags here for me to, uhm, neatly wrap 324 | return DllCall("winhttp\WinHttpQueryHeaders", "Ptr", hRequest, "UInt", infoLevel, "Ptr", name, "Ptr", ptrBuffer, "UInt*", bufferSize, "Ptr", headerIndex) 325 | } 326 | 327 | _WinHttp_DWordFromWHConstant(constant) 328 | { 329 | static something := { "WINHTTP_NO_PROXY_NAME" : 0 330 | ,"WINHTTP_NO_PROXY_BYPASS" : 0 331 | ,"WINHTTP_ACCESS_TYPE_DEFAULT_PROXY" : 0 332 | ,"WINHTTP_ACCESS_TYPE_NO_PROXY" : 1 333 | ,"WINHTTP_ACCESS_TYPE_NAMED_PROXY" : 3 334 | ,"WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY" : 4 335 | ,"INTERNET_DEFAULT_PORT" : 0 336 | ,"INTERNET_DEFAULT_HTTP_PORT" : 80 337 | ,"INTERNET_DEFAULT_HTTPS_PORT" : 443 338 | ,"WINHTTP_NO_REFERER" : 0 339 | ,"WINHTTP_DEFAULT_ACCEPT_TYPES" : 0 340 | ,"WINHTTP_NO_ADDITIONAL_HEADERS" : 0 341 | ,"WINHTTP_NO_REQUEST_DATA" : 0 342 | ,"WINHTTP_FLAG_ASYNC" : 0x10000000 343 | ,"WINHTTP_FLAG_SECURE" : 0x00800000 344 | ,"WINHTTP_FLAG_ESCAPE_PERCENT" : 0x00000004 345 | ,"WINHTTP_FLAG_NULL_CODEPAGE" : 0x00000008 346 | ,"WINHTTP_FLAG_BYPASS_PROXY_CACHE" : 0x00000100 347 | ,"WINHTTP_FLAG_REFRESH" : 0x00000100 348 | ,"WINHTTP_FLAG_ESCAPE_DISABLE" : 0x00000040 349 | ,"WINHTTP_FLAG_ESCAPE_DISABLE_QUERY" : 0x00000080} 350 | 351 | return something[constant] 352 | } -------------------------------------------------------------------------------- /XPGetLeftAndRightChannelsVolume.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | WaveOutIDOfPreferredDevice := mixerID := 0 4 | if (DllCall("winmm\waveOutMessage", "Ptr", WAVE_MAPPER := -1, "UInt", DRVM_MAPPER_PREFERRED_GET := 0x2015, "UInt*", WaveOutIDOfPreferredDevice, "UInt*", Status, "UInt") == 0 5 | && DllCall("winmm\mixerGetID", "Ptr", WaveOutIDOfPreferredDevice, "UInt*", mixerID, "UInt", MIXER_OBJECTF_WAVEOUT := 0x10000000, "UInt") == 0 6 | && FindDevIDs(mixerID, volID, finalDestination)) { 7 | if (DllCall("winmm\mixerOpen", "Ptr*", hmx, "UInt", mixerID, "UInt", 0, "UInt", 0, "UInt", MIXER_OBJECTF_WAVEOUT, "UInt") == 0) { 8 | VarSetcapacity(mxl, 280, 0) 9 | NumPut(280, mxl,, "UInt") 10 | NumPut(finalDestination, mxl, 4, "UInt") 11 | if (DllCall("winmm\mixerGetLineInfo", "Ptr", hmx, "Ptr", &mxl, "UInt", 0, "UInt") == 0) { 12 | channels := NumGet(mxl, 28, "UInt") 13 | VarSetcapacity(mcd, 24, 0) 14 | VarSetcapacity(m, 4 * channels, 0) 15 | NumPut(24, mcd,, "UInt") 16 | NumPut(volID, mcd, 4, "UInt") 17 | NumPut(channels, mcd, 8, "UInt") 18 | NumPut(4, mcd, 16, "UInt") 19 | NumPut(&m, mcd, 20, "Ptr") 20 | if (DllCall("winmm\mixerGetControlDetailsW", "Ptr", hmx, "Ptr", &mcd, "UInt", 0, "UInt") == 0) { 21 | Loop % channels 22 | MsgBox % Round((NumGet(m, 4 * (A_Index - 1), "UInt") / 0xFFFF) * 100) 23 | } 24 | } 25 | DllCall("winmm\mixerClose", "Ptr", hmx) 26 | } 27 | } 28 | 29 | FindDevIDs(mixerID, ByRef volID, ByRef finalDestination) 30 | { 31 | VarSetcapacity(mxcapsw, (cbmxcaps := 80)) 32 | ret := False 33 | 34 | if (DllCall("winmm\mixerGetDevCapsW", "UInt", mixerID, "Ptr", &mxcapsw, "UInt", cbmxcaps) == 0) { 35 | if ((destinations := NumGet(mxcapsw, cbmxcaps - 4, "UInt")) > 0) { 36 | VarSetcapacity(mxl, (cbmxl := 280)) 37 | dest := 0 38 | while (!ret && dest < destinations) { 39 | NumPut(cbmxl, mxl,, "UInt") 40 | NumPut(dest, mxl, 4, "UInt") 41 | if (DllCall("winmm\mixerGetLineInfoW", "Ptr", mixerID, "Ptr", &mxl, "UInt", 0, "UInt") == 0) { 42 | componentType := NumGet(mxl, 24, "UInt") 43 | if (componentType == 4 || componentType == 5 || componentType == 4104) { ; speakers, headphones & wave out 44 | if ((controls := NumGet(mxl, 36, "UInt")) && !ret) { ; controls present 45 | finalDestination := dest 46 | control := 0 47 | cbmc := 228 48 | VarSetcapacity(mc, controls * cbmc) 49 | VarSetcapacity(mxlc, (cbmxl := 24), 0) 50 | NumPut(cbmxl, mxlc,, "UInt") 51 | NumPut(NumGet(mxl, 12, "UInt"), mxlc, 4, "UInt") 52 | NumPut(controls, mxlc, 12, "UInt") 53 | NumPut(cbmc, mxlc, 16, "UInt") 54 | NumPut(&mc, mxlc, 20, "Ptr") 55 | 56 | if (DllCall("winmm\mixerGetLineControlsW", "UInt", mixerID, "Ptr", &mxlc, "UInt", 0, "UInt") == 0) { 57 | while (!ret && control < controls) { 58 | if (NumGet(mc, 8 * control, "UInt") == 1342373889) { 59 | ret := True 60 | volID := NumGet(mc, 4 * control, "UInt") 61 | } 62 | control += 1 63 | } 64 | } 65 | } 66 | } 67 | } 68 | dest += 1 69 | } 70 | } 71 | } 72 | 73 | return ret 74 | } -------------------------------------------------------------------------------- /XPSetLeftAndRightChannelsVolume.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | Up::ShiftChannelVolume(1, 2, False) 4 | Down::ShiftChannelVolume(1, -2, False) 5 | Left::ShiftChannelVolume(0, -2, False) 6 | Right::ShiftChannelVolume(0, 2, False) 7 | 8 | ShiftChannelVolume(channel, adj, jump) { 9 | static mixerID, volID, finalDestination, Minimum, Maximum := -1, Steps, MIXER_OBJECTF_WAVEOUT := 0x10000000, mxl, mcd 10 | 11 | if (channel < 0) 12 | return 13 | 14 | if (Maximum == -1) { 15 | if (!(DllCall("winmm\waveOutMessage", "Ptr", WAVE_MAPPER := -1, "UInt", DRVM_MAPPER_PREFERRED_GET := 0x2015, "UInt*", WaveOutIDOfPreferredDevice, "UInt*", Status, "UInt") == 0 16 | && DllCall("winmm\mixerGetID", "Ptr", WaveOutIDOfPreferredDevice, "UInt*", mixerID, "UInt", MIXER_OBJECTF_WAVEOUT, "UInt") == 0 17 | && FindDevIDs(mixerID, volID, finalDestination, Minimum, Maximum, Steps))) { 18 | Maximum := -1 19 | return 20 | } 21 | VarSetcapacity(mxl, 280) 22 | VarSetcapacity(mcd, 24) 23 | } 24 | DllCall("ntdll\RtlZeroMemory", "Ptr", &mxl, "Ptr", 280) 25 | NumPut(280, mxl,, "UInt"), NumPut(finalDestination, mxl, 4, "UInt") 26 | 27 | adj := CLAMP(adj, jump ? 0 : -100, 100) 28 | 29 | if (DllCall("winmm\mixerOpen", "Ptr*", hmx, "UInt", mixerID, "UInt", 0, "UInt", 0, "UInt", MIXER_OBJECTF_WAVEOUT, "UInt") == 0) { 30 | if (DllCall("winmm\mixerGetLineInfo", "Ptr", hmx, "Ptr", &mxl, "UInt", 0, "UInt") == 0) { 31 | channels := NumGet(mxl, 28, "UInt") 32 | if (channel < channels) { 33 | DllCall("ntdll\RtlZeroMemory", "Ptr", &mcd, "Ptr", 24) 34 | VarSetcapacity(m, 4 * channels, 0) 35 | NumPut(24, mcd,, "UInt") 36 | NumPut(volID, mcd, 4, "UInt") 37 | NumPut(channels, mcd, 8, "UInt") 38 | NumPut(4, mcd, 16, "UInt") 39 | NumPut(&m, mcd, 20, "Ptr") 40 | 41 | if (DllCall("winmm\mixerGetControlDetailsW", "Ptr", hmx, "Ptr", &mcd, "UInt", 0, "UInt") == 0) { 42 | curVolume := Round((NumGet(m, 4 * channel, "UInt") / Maximum) * 100) 43 | newVol := jump ? adj : CLAMP(curVolume + adj, 0, 100) 44 | if (curVolume != newVol) { 45 | NumPut((Maximum - Minimum) * (newVol / 100.0), m, 4 * channel, "UInt") ; stolen from the AutoHotkey source 46 | DllCall("winmm\mixerSetControlDetails", "Ptr", hmx, "Ptr", &mcd, "UInt", 0, "UInt") 47 | } 48 | } 49 | } 50 | } 51 | DllCall("winmm\mixerClose", "Ptr", hmx) 52 | } 53 | } 54 | 55 | FindDevIDs(mixerID, ByRef volID, ByRef finalDestination, ByRef Minimum, ByRef Maximum, ByRef Steps) 56 | { 57 | VarSetcapacity(mxcapsw, (cbmxcaps := 80)) 58 | 59 | if (DllCall("winmm\mixerGetDevCapsW", "UInt", mixerID, "Ptr", &mxcapsw, "UInt", cbmxcaps) == 0) { 60 | if ((destinations := NumGet(mxcapsw, cbmxcaps - 4, "UInt")) > 0) { 61 | VarSetcapacity(mxl, (cbmxl := 280)) 62 | NumPut(cbmxl, mxl,, "UInt") 63 | cbmc := 228 64 | cbmxlc := 24 65 | Loop %destinations% { 66 | dest := A_Index - 1 67 | NumPut(dest, mxl, 4, "UInt") 68 | if (DllCall("winmm\mixerGetLineInfoW", "Ptr", mixerID, "Ptr", &mxl, "UInt", 0, "UInt") == 0) { 69 | componentType := NumGet(mxl, 24, "UInt") 70 | if (componentType == 4 || componentType == 5 || componentType == 4104) { ; speakers, headphones & wave out 71 | if ((controls := NumGet(mxl, 36, "UInt"))) { ; controls present 72 | finalDestination := dest 73 | VarSetcapacity(mc, controls * cbmc) 74 | VarSetcapacity(mxlc, cbmxlc, 0) 75 | NumPut(cbmxlc, mxlc,, "UInt") 76 | NumPut(NumGet(mxl, 12, "UInt"), mxlc, 4, "UInt") 77 | NumPut(controls, mxlc, 12, "UInt") 78 | NumPut(cbmc, mxlc, 16, "UInt") 79 | NumPut(&mc, mxlc, 20, "Ptr") 80 | 81 | if (DllCall("winmm\mixerGetLineControlsW", "UInt", mixerID, "Ptr", &mxlc, "UInt", 0, "UInt") == 0) { 82 | Loop %controls% { 83 | control := A_Index - 1 84 | if (NumGet(mc, 8 + (control * cbmc), "UInt") == 1342373889) { ; volume control 85 | Minimum := NumGet(mc, 180 + (control * cbmc), "UInt") 86 | Maximum := NumGet(mc, 184 + (control * cbmc), "UInt") 87 | Steps := NumGet(mc, 204 + (control * cbmc), "UInt") 88 | volID := NumGet(mc, 4 + (control * cbmc), "UInt") 89 | return True 90 | } 91 | } 92 | } 93 | } 94 | } 95 | } 96 | } 97 | } 98 | } 99 | 100 | return False 101 | } 102 | 103 | CLAMP(x, low, high) 104 | { 105 | return (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) 106 | } -------------------------------------------------------------------------------- /startWindows10Calendar.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 2 | 3 | ; AppUserID string source: https://stackoverflow.com/questions/32150759/how-to-enumerate-the-installed-storeapps-and-their-id-in-windows-8-and-10 4 | IApplicationActivationManager := ComObjCreate("{45BA127D-10A8-46EA-8AB7-56EA9078943C}", "{2e941141-7f97-4756-ba1d-9decde894a3d}") 5 | DllCall(NumGet(NumGet(IApplicationActivationManager+0)+3*A_PtrSize), "Ptr", IApplicationActivationManager, "Str", "microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.calendar", "Str", 0, "UInt", 0, "IntP", processId) 6 | ObjRelease(IApplicationActivationManager) 7 | ExitApp --------------------------------------------------------------------------------