Reverted
This commit is contained in:
@@ -13,7 +13,9 @@ extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpsz
|
||||
extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount)
|
||||
|
||||
[<DllImport("user32.dll", SetLastError = true)>]
|
||||
extern uint GetWindowThreadProcessId(IntPtr hWnd, uint& lpdwProcessId)
|
||||
extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam)
|
||||
|
||||
let WM_CLOSE = 0x0010u
|
||||
|
||||
let getClassName (hWnd: IntPtr) =
|
||||
let sb = StringBuilder(256)
|
||||
@@ -22,62 +24,23 @@ let getClassName (hWnd: IntPtr) =
|
||||
else
|
||||
""
|
||||
|
||||
let getProcessIdFromWindow (hWnd: IntPtr) =
|
||||
let mutable processId = 0u
|
||||
GetWindowThreadProcessId(hWnd, &processId) |> ignore
|
||||
int processId
|
||||
|
||||
let killTuneBlade () =
|
||||
try
|
||||
let processes = Process.GetProcessesByName("TuneBlade")
|
||||
for proc in processes do
|
||||
printfn "Killing TuneBlade process (PID: %d)..." proc.Id
|
||||
proc.Kill()
|
||||
proc.WaitForExit(5000) |> ignore
|
||||
processes.Length > 0
|
||||
with
|
||||
| ex ->
|
||||
printfn "Error killing TuneBlade: %s" ex.Message
|
||||
false
|
||||
|
||||
let startTuneBlade (exePath: string) =
|
||||
try
|
||||
printfn "Starting TuneBlade from: %s" exePath
|
||||
Process.Start(exePath) |> ignore
|
||||
true
|
||||
with
|
||||
| ex ->
|
||||
printfn "Error starting TuneBlade: %s" ex.Message
|
||||
false
|
||||
|
||||
[<EntryPoint>]
|
||||
let main _ =
|
||||
let tuneBladeExe = @"C:\Program Files (x86)\TuneBlade\TuneBlade\TuneBlade.exe"
|
||||
|
||||
printfn "TuneBlade Suppressor"
|
||||
printfn "Monitoring for errors and restarting from: %s" tuneBladeExe
|
||||
printfn "Press Ctrl+C to exit"
|
||||
printfn ""
|
||||
|
||||
let main _ =
|
||||
printfn "Running TuneBlade error suppressor..."
|
||||
while true do
|
||||
let hwnd = FindWindow(null, "TuneBlade")
|
||||
|
||||
if hwnd <> IntPtr.Zero then
|
||||
let cls = getClassName hwnd
|
||||
if cls = "#32770" then
|
||||
printfn "TuneBlade error dialog detected - restarting application..."
|
||||
if killTuneBlade() then
|
||||
System.Threading.Thread.Sleep(1000)
|
||||
startTuneBlade tuneBladeExe |> ignore
|
||||
System.Threading.Thread.Sleep(3000)
|
||||
printfn "TuneBlade error dialog detected — closing."
|
||||
PostMessage(hwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero) |> ignore
|
||||
|
||||
let child = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "TuneBlade")
|
||||
if child <> IntPtr.Zero then
|
||||
printfn "TuneBlade dialog window detected — restarting application..."
|
||||
if killTuneBlade() then
|
||||
System.Threading.Thread.Sleep(1000)
|
||||
startTuneBlade tuneBladeExe |> ignore
|
||||
System.Threading.Thread.Sleep(3000)
|
||||
let mutable child = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "TuneBlade")
|
||||
while child <> IntPtr.Zero do
|
||||
printfn "Closing TuneBlade dialog window..."
|
||||
PostMessage(child, WM_CLOSE, IntPtr.Zero, IntPtr.Zero) |> ignore
|
||||
child <- FindWindowEx(IntPtr.Zero, child, "#32770", "TuneBlade")
|
||||
|
||||
System.Threading.Thread.Sleep(2000)
|
||||
0
|
||||
Reference in New Issue
Block a user