ganjeii
Member
I'm writing a small application to clear temp files on a Windows 7/8 machine and to check for, and close Adobe Reader if it is running before continuing. For some reason after Adobe Reader is closed, the code seems to cease and the temp file removal process never starts, this is all done calling subs and functions under a single click event. Please let me know if more code is required aside from what I have posted below:
In this case the process is "AcroRd32"
And I call checkProcess within the button btnKillFolders. Then check to see if Reader is running, if the process count is less than 1 then continue to execute the code within the IF statement, but it just stops. I have gotten it to proceed if I add a MessageBox after the process is killed in the above function, and click OK.
I had also tried a simple wait command after calling checkProcess("AcroRd32") just in-case the process wasn't closed completely when the IF statement was reached. But with no luck.
If I click the button again, then the IF statement executes, but I have to click the button a second time after Adobe Reader is closed because for some reason the IF statement is never executed. I don't want the user to have to do this. I may be completely off base, is there a better way to do this? Or am I just missing something simple? Any feedback is greatly appreciated, and please let me know if any further code is needed. Thanks!
In this case the process is "AcroRd32"
VB.NET:
'Checks for and prompts to close process
Public Sub checkProcess(ByVal procN As String)
Dim pr() As Process
pr = Process.GetProcessesByName(procN)
If pr.Count > 0 Then
Dim cont As Boolean = True
Dim pick As Integer = MessageBox.Show _
(procN & " is running. Press OK to close or Cancel to exit.", _
procN & " running", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If pick = DialogResult.OK Then
endProcess(procN)
ElseIf pick = DialogResult.Cancel Then
End If
Else
End If
End Sub
I had also tried a simple wait command after calling checkProcess("AcroRd32") just in-case the process wasn't closed completely when the IF statement was reached. But with no luck.
VB.NET:
'Executes subs to clean temps
Private Sub btnKillFolders_Click(sender As Object, e As EventArgs) Handles btnKillData.Click
checkProcess("AcroRd32")
Dim proc() As Process
proc = Process.GetProcessesByName("AcroRd32")
If proc.Count < 1 Then
endProcess("armsvc")
endProcess("AdobeARM")
endProcess("iexplore")
FixWeb()
fixAdobe()
Else
End If
End Sub