Skip to content

Commit

Permalink
Fix Memory Leak
Browse files Browse the repository at this point in the history
  • Loading branch information
TatshSiow committed Jan 30, 2024
1 parent 247ebb0 commit 29a2e57
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions SSAR_v1.3.vbs → SSAR_v1.4.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ Select Case response
' Clean up the temporary batch file
objFSO.DeleteFile(tempBatchFile)



Case vbNo ' Terminate
' Terminate the running batch script
TerminateBatchScript
' Confirmation dialog before terminating cmd.exe and conhost.exe
confirmResponse = MsgBox("Deactivating Service will kill cmd.exe and conhost.exe, Proceed?", vbYesNo + vbExclamation, "Confirmation")

If confirmResponse = vbYes Then
' Terminate conhost.exe and cmd.exe processes
objShell.Run "taskkill /F /IM conhost.exe", 0, True
objShell.Run "taskkill /F /IM cmd.exe", 0, True

' Display a prompt indicating Service Deactivated
MsgBox "Service Deactivated", vbInformation, "SmoothScroll AutoRefresh"
' Display a prompt indicating Service Deactivated
MsgBox "Service Deactivated", vbInformation, "SmoothScroll AutoRefresh"
Else
' User chose not to proceed, do nothing
End If

Case vbCancel ' Exit
' Do nothing or add any cleanup logic if needed
Expand All @@ -67,19 +73,3 @@ Function FindSmoothScrollPath()
' Return an empty string if SmoothScroll.exe is not found
FindSmoothScrollPath = ""
End Function

Sub TerminateBatchScript()
' Subroutine to terminate the running batch script
Dim objWMIService, colProcesses, objProcess

' Create WMI service object
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

' Query for CMD.exe process associated with the batch script
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where CommandLine Like '%TempBatchFile.bat%'")

' Terminate the CMD.exe process associated with the batch script
For Each objProcess In colProcesses
objProcess.Terminate
Next
End Sub

0 comments on commit 29a2e57

Please sign in to comment.