Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty12 authored Nov 6, 2018
0 parents commit a9423f5
Show file tree
Hide file tree
Showing 51 changed files with 3,342 additions and 0 deletions.
69 changes: 69 additions & 0 deletions AddFolderShare.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#NoTrayIcon
#NoEnv
Process, Priority, , A
#SingleInstance Off
NERR_Success := 0

if (!A_IsAdmin)
ExitApp

; This is the equivalent of "net share 1=C:\1 /GRANT:%USERNAME%,READ /GRANT:%USERNAME%,CHANGE /USERS:2 /CACHE:None"

userName := A_UserName
shi502_netname := "1"
shi502_path := "C:\1"

if (DllCall("Netapi32\NetShareCheck", "Ptr", 0, "WStr", shi502_netname, "UInt*", 0) == NERR_Success) ; if this succeeds, it means the folder is already shared
ExitApp

CSC_MASK_EXT := 0x2030, CSC_CACHE_NONE := 0x0030
SECURITY_DESCRIPTOR_REVISION := 1, ACL_REVISION := 2
ACCESS_READ := 0x01, ACCESS_WRITE := 0x02, ACCESS_CREATE := 0x04, ACCESS_EXEC := 0x08, ACCESS_DELETE := 0x10, ACCESS_ATRIB := 0x20
; thanks to ctusch: https://stackoverflow.com/a/17236838
FILE_READ_DATA := FILE_LIST_DIRECTORY := 0x1
FILE_EXECUTE := FILE_TRAVERSE := 0x20
FILE_WRITE_DATA := FILE_ADD_FILE := 0x2
FILE_APPEND_DATA := FILE_ADD_SUBDIRECTORY := 0x4
SHARE_READ := FILE_LIST_DIRECTORY | FILE_READ_EA := 0x8 | FILE_TRAVERSE | FILE_READ_ATTRIBUTES := 0x80 | READ_CONTROL := 0x20000 | SYNCHRONIZE := 0x100000
SHARE_CHANGE := FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_WRITE_EA := 0x10 | FILE_WRITE_ATTRIBUTES := 0x100 | DELETE := 0x10000
SHARE_FULLCONTROL := FILE_DELETE_CHILD := 0x40 | WRITE_DAC := 0x40000 | WRITE_OWNER := 0x80000

; prepare SD with a DACL containing one ACE: your user gets Read and Change access to the share
VarSetCapacity(SecurityDescriptor, 40, 0)
if (!DllCall("advapi32\InitializeSecurityDescriptor", "Ptr", &SecurityDescriptor, "UInt", SECURITY_DESCRIPTOR_REVISION))
ExitApp
cbAcl := 8 + (12 * 1) ; sizeof(ACL) + ((sizeof(ACCESS_ALLOWED_ACE)) * NUM_OF_ACES)
DllCall("sechost\LookupAccountNameLocalW", "WStr", userName, "Ptr", 0, "UInt*", cbSid := 0, "Ptr", 0, "UInt*", cbDomain := 0, "UInt*", 0)
if (A_LastError != 122)
ExitApp
VarSetCapacity(Sid, cbSid, 0), VarSetCapacity(domain, cbDomain)
if (!DllCall("sechost\LookupAccountNameLocalW", "WStr", userName, "Ptr", &Sid, "UInt*", cbSid, "Ptr", &domain, "UInt*", cbDomain, "UInt*", 0))
ExitApp
cbAcl += cbSid - 4 ; for (int i = 0; i < NUM_OF_ACES; i++) cbAcl += GetLengthSid(psids[i]) - sizeof(DWORD); // aka: - sizeof(ACE->SidStart)
cbAcl := (cbAcl + (4 - 1)) & 0xfffffffc ; Align cbAcl to a DWORD
if (VarSetCapacity(Acl, cbAcl, 0) != cbAcl)
ExitApp
if (!DllCall("advapi32\InitializeAcl", "Ptr", &Acl, "UInt", cbAcl, "UInt", ACL_REVISION))
ExitApp
if (!DllCall("advapi32\AddAccessAllowedAce", "Ptr", &Acl, "UInt", ACL_REVISION, "UInt", SHARE_READ | SHARE_CHANGE, "Ptr", &Sid))
ExitApp
if (!DllCall("advapi32\SetSecurityDescriptorDacl", "Ptr", &SecurityDescriptor, "Int", True, "Ptr", &Acl, "Int", False))
ExitApp

; prepare SHARE_INFO_502 struct
VarSetCapacity(SHARE_INFO_502, 72, 0)
NumPut(&shi502_netname, SHARE_INFO_502, 0, "Ptr")
NumPut((shi502_permissions := ACCESS_READ | ACCESS_WRITE | ACCESS_CREATE | ACCESS_EXEC | ACCESS_DELETE | ACCESS_ATRIB), SHARE_INFO_502, 24, "UInt")
NumPut((shi502_max_uses := 2), SHARE_INFO_502, 28, "UInt")
NumPut(&shi502_path, SHARE_INFO_502, 40, "Ptr")
NumPut(&(shi502_passwd := ""), SHARE_INFO_502, 48, "Ptr")
NumPut(&SecurityDescriptor, SHARE_INFO_502, 64, "Ptr")

if (DllCall("Netapi32\NetShareAdd", "Ptr", 0, "UInt", 502, "Ptr", &SHARE_INFO_502, "Ptr", 0, "UInt") == NERR_Success) {
; disable caching
if (DllCall("Netapi32\NetShareGetInfo", "Ptr", 0, "WStr", shi502_netname, "UInt", 1005, "Ptr*", SHARE_INFO_1005, "UInt") == NERR_Success) {
NumPut((shi1005_flags := (NumGet(SHARE_INFO_1005+0,, "UInt") & ~CSC_MASK_EXT) | CSC_CACHE_NONE), SHARE_INFO_1005+0,, "UInt")
DllCall("Netapi32\NetShareSetInfo", "Ptr", 0, "WStr", shi502_netname, "UInt", 1005, "Ptr", SHARE_INFO_1005, "Ptr", 0, "UInt")
DllCall("Netapi32\NetApiBufferFree", "Ptr", SHARE_INFO_1005)
}
}
41 changes: 41 additions & 0 deletions AddWindowsInboundFirewallRuleForhttpd.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.

xammpPath := A_ScriptDir . "\xampp"
httpd := xammpPath . "\apache\bin\httpd.exe"

if (FileExist(httpd) && A_OSVersion != "WIN_XP" && A_IsAdmin) {
try {
FwPolicy2 := ComObjCreate("HNetCfg.FwPolicy2")
ruleAlreadyExists := False
Rules := FwPolicy2.Rules
for rule in Rules
if (rule.ApplicationName = httpd) {
ruleAlreadyExists := True
break
}
if (!ruleAlreadyExists) {
NewRule := ComObjCreate("HNetCfg.FWRule"), NewRuleUdp := ComObjCreate("HNetCfg.FWRule")
NewRule.Description := NewRule.Name := "httpd.exe"
NewRule.ApplicationName := Format("{:L}", httpd) ; for some reason, the paths are made lower-case by Windows when it adds a firewall rule itself
NewRule.Protocol := NET_FW_IP_PROTOCOL_TCP := 6
NewRule.RemoteAddresses := NewRule.LocalAddresses := NewRule.RemoteAddresses := NewRule.RemotePorts := "*"
NewRule.Direction := NET_FW_RULE_DIR_IN := 1
NewRule.InterfaceTypes := "All"
NewRule.Enabled := True
NewRule.Profiles := NET_FW_PROFILE2_PRIVATE := 0x2 | NET_FW_PROFILE2_PUBLIC := 0x4 ; | NET_FW_PROFILE2_DOMAIN := 0x1 / NET_FW_PROFILE2_ALL := 0x7fffffff
NewRule.Action := NET_FW_ACTION_ALLOW := 1

NewRuleUdp.Description := NewRuleUdp.Name := NewRule.Name
NewRuleUdp.ApplicationName := NewRule.ApplicationName
NewRuleUdp.Protocol := NET_FW_IP_PROTOCOL_UDP := 17
NewRuleUdp.RemoteAddresses := NewRuleUdp.LocalAddresses := NewRuleUdp.RemoteAddresses := NewRuleUdp.RemotePorts := NewRule.RemotePorts
NewRuleUdp.Direction := NewRule.Direction
NewRuleUdp.InterfaceTypes := NewRule.InterfaceTypes
NewRuleUdp.Enabled := NewRule.Enabled
NewRuleUdp.Profiles := NewRule.Profiles
NewRuleUdp.Action := NewRule.Action

Rules.Add(NewRule), Rules.Add(NewRuleUdp)
}
}
}
6 changes: 6 additions & 0 deletions AdvanceToNextSlideshowWallpaper/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Scripts to advance to next background slideshow picture in the background upon pressing Windows + n

For Windows 8 and 10, this is a simple affair, thanks to the built-in interface for doing so.

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.
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.
153 changes: 153 additions & 0 deletions AdvanceToNextSlideshowWallpaper/Windows7.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetBatchLines, -1
ListLines, Off
#KeyHistory 0

#n::
ShellContextMenu("Desktop", 1)
SetTimer, EmptySet, -10000
return

EmptySet:
Run "%A_AhkPath%" /restart "%A_ScriptFullPath%"
return

; Remake for unicode of Sean's ShellContextMenu by Deo: http://www.autohotkey.com/board/topic/65563-ahk-l-shell-context-menu/
; 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
ShellContextMenu(sPath, idn := "", win_hwnd := 0, ShellContextMenuDebug := false)
{
if (!sPath)
return
pIShellFolder := 0
pIContextMenu := 0
idnValid := false
if idn is Integer
idnValid := true

if (!idnValid && !win_hwnd) {
Gui, SHELL_CONTEXT:New, +hwndwin_hwnd
Gui, Show
}

if (spath == "Desktop") {
DllCall("shell32\SHGetDesktopFolder", "PtrP", pIShellFolder)
DllCall(VTable(pIShellFolder, 8), "Ptr", pIShellFolder, "Ptr", 0, "Ptr", GUID4String(IID_IContextMenu,"{000214E4-0000-0000-C000-000000000046}"), "PtrP", pIContextMenu) ; CreateViewObject
} else {
If sPath Is Not Integer
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).
Else
DllCall("shell32\SHGetFolderLocation", "Ptr", 0, "Int", sPath, "Ptr", 0, "Uint", 0, "PtrP", pidl)
DllCall("shell32\SHBindToParent", "Ptr", pidl, "Ptr", GUID4String(IID_IShellFolder,"{000214E6-0000-0000-C000-000000000046}"), "PtrP", pIShellFolder, "PtrP", pidlChild)
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
CoTaskMemFree(pidl)
}
ObjRelease(pIShellFolder), pIShellFolder := 0

hMenu := DllCall("CreatePopupMenu")
idnMIN := 1 ;idnValid Or debug ? 1 : 3
;IContextMenu->QueryContextMenu
;http://msdn.microsoft.com/en-us/library/bb776097%28v=VS.85%29.aspx
DllCall(VTable(pIContextMenu, 3), "Ptr", pIContextMenu, "Ptr", hMenu, "UInt", 0, "UInt", idnMIN, "UInt", 0x7FFF, "UInt", 0x100) ;CMF_EXTENDEDVERBS

if (!idnValid) {
ComObjError(0)
global pIContextMenu2 := ComObjQuery(pIContextMenu, IID_IContextMenu2:="{000214F4-0000-0000-C000-000000000046}")
global pIContextMenu3 := ComObjQuery(pIContextMenu, IID_IContextMenu3:="{BCFCE0A0-EC17-11D0-8D10-00A0C90F2719}")
e := A_LastError ;GetLastError()
ComObjError(1)
if (e != 0)
goTo, StopContextMenu
global WPOld := DllCall(A_PtrSize == 8 ? "SetWindowLongPtr" : "SetWindowLong", "Ptr", win_hwnd ? win_hwnd : A_ScriptHwnd, "Int", -4, "Ptr", RegisterCallback("ShellContextMenuWindowProc"), "Ptr")
DllCall("GetCursorPos", "Int64*", pt)
DllCall("InsertMenu", "Ptr", hMenu, "UInt", 0, "UInt", 0x0400|0x800, "Ptr", 2, "Ptr", 0)
DllCall("InsertMenu", "Ptr", hMenu, "UInt", 0, "UInt", 0x0400|0x002, "Ptr", 1, "Ptr", &sPath)

idn := DllCall("TrackPopupMenuEx", "Ptr", hMenu, "Uint", 0x0100|0x0001, "Int", pt << 32 >> 32, "Int", pt >> 32, "Ptr", win_hwnd ? win_hwnd : A_ScriptHwnd, "Ptr", 0)
}

/*
typedef struct _CMINVOKECOMMANDINFOEX {
DWORD cbSize; 0
DWORD fMask; 4
HWND hwnd; 8
LPCSTR lpVerb; 8+A_PtrSize
LPCSTR lpParameters; 8+2*A_PtrSize
LPCSTR lpDirectory; 8+3*A_PtrSize
int nShow; 8+4*A_PtrSize
DWORD dwHotKey; 12+4*A_PtrSize
HANDLE hIcon; 16+4*A_PtrSize
LPCSTR lpTitle; 16+5*A_PtrSize
LPCWSTR lpVerbW; 16+6*A_PtrSize
LPCWSTR lpParametersW; 16+7*A_PtrSize
LPCWSTR lpDirectoryW; 16+8*A_PtrSize
LPCWSTR lpTitleW; 16+9*A_PtrSize
POINT ptInvoke; 16+10*A_PtrSize
} CMINVOKECOMMANDINFOEX, *LPCMINVOKECOMMANDINFOEX;
http://msdn.microsoft.com/en-us/library/bb773217%28v=VS.85%29.aspx
*/
struct_size := 16+11*A_PtrSize
VarSetCapacity(pici, struct_size, 0)
NumPut(struct_size, pici, 0, "Uint") ;cbSize
NumPut((A_IsUnicode ? 0x00004000 : 0) | 0x20000000 | 0x00100000, pici, 4, "UInt") ;fMask
NumPut(win_hwnd ? win_hwnd : A_ScriptHwnd, pici, 8, "UPtr") ;hwnd
NumPut(1, pici, 8+4*A_PtrSize, "Uint") ;nShow
NumPut(idn-idnMIN, pici, 8+A_PtrSize, "UPtr") ;lpVerb
if (A_IsUnicode)
NumPut(idn-idnMIN, pici, 16+6*A_PtrSize, "UPtr") ;lpVerbW
if (!idnValid)
NumPut(pt, pici, 16+10*A_PtrSize, "UPtr") ;ptInvoke

DllCall(VTable(pIContextMenu, 4), "Ptr", pIContextMenu, "Ptr", &pici) ; InvokeCommand

if (!idnValid) {
if (ShellContextMenuDebug) {
VarSetCapacity(sName, 522)
DllCall(VTable(pIContextMenu, 5), "Ptr", pIContextMenu, "UInt", idn-idnMIN, "UInt", 0x00000000, "UIntP", 0, "Str", sName, "Uint", 260) ; GetCommandString
if (A_IsUnicode)
sName := StrGet(&sName,, "utf-8")
OutputDebug, idn: %idn% command string: %sName%
}
DllCall("GlobalFree", "Ptr", DllCall("SetWindowLongPtr", "Ptr", win_hwnd ? win_hwnd : A_ScriptHwnd, "Int", -4, "Ptr", WPOld, "UPtr"))
}
StopContextMenu:
DllCall("DestroyMenu", "Ptr", hMenu)
if (!idnValid) {
ObjRelease(pIContextMenu3), ObjRelease(pIContextMenu2)
pIContextMenu3 := pIContextMenu2 := WPOld := 0
}
ObjRelease(pIContextMenu), pIContextMenu := 0
Gui, SHELL_CONTEXT:Destroy
VarSetCapacity(pici, 0)
return idn
}

ShellContextMenuWindowProc(hWnd, nMsg, wParam, lParam)
{
Global pIContextMenu2, pIContextMenu3, WPOld
If pIContextMenu3 { ;IContextMenu3->HandleMenuMsg2
If !DllCall(VTable(pIContextMenu3, 7), "Ptr", pIContextMenu3, "Uint", nMsg, "Ptr", wParam, "Ptr", lParam, "Ptr*", lResult)
return lResult
}
Else If pIContextMenu2 { ;IContextMenu2->HandleMenuMsg
If !DllCall(VTable(pIContextMenu2, 6), "Ptr", pIContextMenu2, "Uint", nMsg, "Ptr", wParam, "Ptr", lParam)
return 0
}
return DllCall("user32.dll\CallWindowProcW", "Ptr", WPOld, "Ptr", hWnd, "Uint", nMsg, "Ptr", wParam, "Ptr", lParam)
}

VTable(ppv, idx)
{
Return NumGet(NumGet(ppv+0)+A_PtrSize*idx)
}

GUID4String(ByRef CLSID, String)
{
VarSetCapacity(CLSID, 16, 0)
return DllCall("ole32\CLSIDFromString", "WStr", String, "Ptr", &CLSID) >= 0 ? &CLSID : ""
}

CoTaskMemFree(pv)
{
return DllCall("ole32\CoTaskMemFree", "Ptr", pv)
}
9 changes: 9 additions & 0 deletions AdvanceToNextSlideshowWallpaper/Windows8and10.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.

#n::
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
return
ObjRelease(pDesktopWallpaper)
if ((pDesktopWallpaper := ComObjCreate("{C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD}", "{B92B56A9-8B55-4E14-9A89-0199BBB6F93B}")))
goto %A_ThisHotkey%
return
51 changes: 51 additions & 0 deletions BeepWhenPrintJobAddedForDefaultPrinter.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#NoEnv
PRINTER_CHANGE_ADD_JOB := 0x00000100 ; FindFirstPrinterChangeNotification
INVALID_HANDLE_VALUE := -1

; MsgWaitForMultipleObjectsEx constants:
WAIT_OBJECT_0 := 0x00000000, WAIT_FAILED := INFINITE := 0xFFFFFFFF, MWMO_ALERTABLE := 0x0002, MWMO_INPUTAVAILABLE := 0x0004
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
QS_ALLINPUT := QS_INPUT | QS_POSTMESSAGE := 0x0008 | QS_TIMER := 0x0010 | QS_PAINT := 0x0020 | QS_HOTKEY := 0x0080 | QS_SENDMESSAGE := 0x0040

hModWinspool := DllCall("LoadLibrary", "Str", "winspool.drv", "Ptr")

; Get default printer name
if (DllCall("winspool.drv\GetDefaultPrinter", "Ptr", 0, "UInt*", cchDefPrinter))
ExitApp 1
VarSetCapacity(defaultPrinterName, cchDefPrinter * (A_IsUnicode + 1))
DllCall("winspool.drv\GetDefaultPrinter", "Ptr", &defaultPrinterName, "UInt*", cchDefPrinter)

if (!DllCall("winspool.drv\OpenPrinter", "Ptr", &defaultPrinterName, "Ptr*", hDefaultPrinter, "Ptr", 0))
ExitApp 1
OnExit("cleanup")

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)
ExitApp 1

bKeepMonitoring := True
while (bKeepMonitoring) {
; Bastardised from Lexikos' FileExtract
r := DllCall("MsgWaitForMultipleObjectsEx", "UInt", 1, "Ptr*", hDefaultPrinterChange, "UInt", INFINITE, "UInt", QS_ALLINPUT, "UInt", MWMO_ALERTABLE | MWMO_INPUTAVAILABLE, "UInt"), Sleep 0
if (!bKeepMonitoring || r == WAIT_FAILED) {
break
} else if (r == WAIT_OBJECT_0) {
if ((DllCall("winspool.drv\FindNextPrinterChangeNotification", "Ptr", hDefaultPrinterChange, "UInt*", dwChange, "Ptr", 0, "Ptr", 0)) && dwChange & PRINTER_CHANGE_ADD_JOB)
SoundBeep ; replace this for something stronger
}
}

cleanup()
{
global watchPrinter, hDefaultPrinter, hDefaultPrinterChange, hModWinspool, bKeepMonitoring, INVALID_HANDLE_VALUE
;Critical On
bKeepMonitoring := False
;PostMessage, 0x0000,,,, ahk_id %A_ScriptHwnd%
;Sleep -1
if (hDefaultPrinterChange != INVALID_HANDLE_VALUE)
DllCall("winspool.drv\FindClosePrinterChangeNotification", "Ptr", hDefaultPrinterChange), hDefaultPrinterChange := INVALID_HANDLE_VALUE
if (hDefaultPrinter)
DllCall("winspool.drv\ClosePrinter", "Ptr", hDefaultPrinter), hDefaultPrinter := 0
if (hModWinspool)
DllCall("FreeLibrary", "Ptr", hModWinspool), hModWinspool := 0
;Critical Off
}
Loading

0 comments on commit a9423f5

Please sign in to comment.