Changed to restart tuneblade
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
open System
|
open System
|
||||||
|
open System.Diagnostics
|
||||||
open System.Runtime.InteropServices
|
open System.Runtime.InteropServices
|
||||||
open System.Text
|
open System.Text
|
||||||
|
|
||||||
@@ -12,9 +13,7 @@ extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpsz
|
|||||||
extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount)
|
extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount)
|
||||||
|
|
||||||
[<DllImport("user32.dll", SetLastError = true)>]
|
[<DllImport("user32.dll", SetLastError = true)>]
|
||||||
extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam)
|
extern uint GetWindowThreadProcessId(IntPtr hWnd, uint& lpdwProcessId)
|
||||||
|
|
||||||
let WM_CLOSE = 0x0010u
|
|
||||||
|
|
||||||
let getClassName (hWnd: IntPtr) =
|
let getClassName (hWnd: IntPtr) =
|
||||||
let sb = StringBuilder(256)
|
let sb = StringBuilder(256)
|
||||||
@@ -23,23 +22,62 @@ let getClassName (hWnd: IntPtr) =
|
|||||||
else
|
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>]
|
[<EntryPoint>]
|
||||||
let main _ =
|
let main argv =
|
||||||
printfn "Running TuneBlade error suppressor..."
|
let tuneBladeExe = @"C:\Program Files (x86)\TuneBlade\TuneBlade\TuneBlade.exe"
|
||||||
|
|
||||||
|
printfn "TuneBlade Auto-Restarter"
|
||||||
|
printfn "Monitoring for errors and restarting from: %s" tuneBladeExe
|
||||||
|
printfn "Press Ctrl+C to exit"
|
||||||
|
printfn ""
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
let hwnd = FindWindow(null, "TuneBlade")
|
let hwnd = FindWindow(null, "TuneBlade")
|
||||||
|
|
||||||
if hwnd <> IntPtr.Zero then
|
if hwnd <> IntPtr.Zero then
|
||||||
let cls = getClassName hwnd
|
let cls = getClassName hwnd
|
||||||
if cls = "#32770" then
|
if cls = "#32770" then
|
||||||
printfn "TuneBlade error dialog detected — closing."
|
printfn "TuneBlade error dialog detected - restarting application..."
|
||||||
PostMessage(hwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero) |> ignore
|
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")
|
let mutable child = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "TuneBlade")
|
||||||
while child <> IntPtr.Zero do
|
if child <> IntPtr.Zero then
|
||||||
printfn "Closing TuneBlade dialog window..."
|
printfn "TuneBlade dialog window detected — restarting application..."
|
||||||
PostMessage(child, WM_CLOSE, IntPtr.Zero, IntPtr.Zero) |> ignore
|
if killTuneBlade() then
|
||||||
child <- FindWindowEx(IntPtr.Zero, child, "#32770", "TuneBlade")
|
System.Threading.Thread.Sleep(1000)
|
||||||
|
startTuneBlade tuneBladeExe |> ignore
|
||||||
|
System.Threading.Thread.Sleep(3000)
|
||||||
|
|
||||||
System.Threading.Thread.Sleep(2000)
|
System.Threading.Thread.Sleep(2000)
|
||||||
0
|
0
|
||||||
Reference in New Issue
Block a user