Any alternative to setforeground.exe? #66
-
My corporate antimalware software has starting trapping and quarantining setforeground.exe, so I'm no longer able to use this script. Is there any workaround that doesn't require calling an unfamiliar executable? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
ahk_v2 replace Run "`"" A_LineFile "\..\SetForeGroundWindow.exe`" " hWnd with Run "cmd /c echo DllCall(`"SetForegroundWindow`",`"Ptr`"," hWnd ")|`"" A_AhkPath "`" *",,"Hide" ahk_v1 replace Run % """" A_LineFile "\..\SetForeGroundWindow.exe"" " hWnd with Run % "cmd /c echo DllCall(""SetForegroundWindow"",""Ptr""," hWnd ")|""" A_AhkPath """ *",,% "Hide" concepts:
the requirement is having a new process, a new process has to be an exe: |
Beta Was this translation helpful? Give feedback.
-
@micjoh @ajkessel ahk_v2 replace static _WinActivate_NewProcess(hWnd) {
foregroundWindow := DllCall("GetForegroundWindow", "Ptr")
threadID := DllCall("GetWindowThreadProcessId", "Ptr", foregroundWindow, "Uint*", &PID := 0)
currentThreadID := DllCall("GetCurrentThreadId")
if (threadID == currentThreadID) {
DllCall("SetForegroundWindow", "Ptr", hWnd)
} else {
loop 10 {
Run "`"" A_LineFile "\..\SetForeGroundWindow.exe`" " hWnd
if (DllCall("GetForegroundWindow", "Ptr") == hWnd) {
break
}
Sleep 10
if (DllCall("GetForegroundWindow", "Ptr") == hWnd) {
break
}
}
}
} with static _WinActivate_NewProcess(hwnd) {
if (DllCall("AllowSetForegroundWindow","Uint",DllCall("GetCurrentProcessId"))) {
DllCall("SetForegroundWindow","Ptr",hwnd)
} else {
LCtrlDown:=GetKeyState("LCtrl")
RCtrlDown:=GetKeyState("RCtrl")
LShiftDown:=GetKeyState("LShift")
RShiftDown:=GetKeyState("RShift")
LWinDown:=GetKeyState("LWin")
RWinDown:=GetKeyState("RWin")
LAltDown:=GetKeyState("LAlt")
RAltDown:=GetKeyState("RAlt")
if ((LCtrlDown || RCtrlDown) && (LShiftDown || RShiftDown) && (LWinDown || RWinDown) && !(LAltDown || RAltDown)) {
DllCall("keybd_event","UChar",160,"UChar",42,"Uint",2,"Ptr",2) ;LShift Up
}
Send "{LAlt Down}"
DllCall("SetForegroundWindow","Ptr",hwnd)
toAppend:=""
if (!(LAltDown || RAltDown)) {
toAppend.="{LAlt Up}"
}
if (LCtrlDown) {
toAppend.="{LCtrl Down}"
}
if (RCtrlDown) {
toAppend.="{RCtrl Down}"
}
if (LShiftDown) {
toAppend.="{LShift Down}"
}
if (RShiftDown) {
toAppend.="{RShift Down}"
}
if (LWinDown) {
toAppend.="{LWin Down}"
}
if (RWinDown) {
toAppend.="{RWin Down}"
}
if (toAppend) {
Send "{Blind}" toAppend
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I created a repo: you should read: https://github.com/FuPeiJiang/SetForegroundWindow.ah2/blob/main/chat.txt it contains a version with additional fixes in: https://github.com/FuPeiJiang/SetForegroundWindow.ah2/blob/main/SetForegroundWindow.ah2 |
Beta Was this translation helpful? Give feedback.
ahk_v2
replace
with
ahk_v1
replace
with
concepts:
AutoHotkey.exe *
reads the code from stdinexample:
the requirement is having a new process, a new process has to be an exe:
instead of compiling another SetForeGroundWindow.exe which won't be flagged/quarantined,
I'm gonna use AutoHotkey.exe to do the same thing: SetForegroundWindow https://l…