forked from mspace912/iLogic-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEXCEL CLOSE.ILOGICVB
More file actions
75 lines (67 loc) · 3.47 KB
/
EXCEL CLOSE.ILOGICVB
File metadata and controls
75 lines (67 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Option Explicit
'---------------------------------------------------------------------------------------
' : Terminates a process. First checking to see if it is running or not.
' : Uses WMI (Windows Management Instrumentation) to query all running processes
' : then terminates ALL instances of the specified process
' : held in the variable strTerminateThis.
' :
' : ***WARNING: This will terminate a specified running process,use with caution!.
' : ***Terminating certain processes can effect the running of Windows and/or
' : ***running applications.
'---------------------------------------------------------------------------------------
Dim strTerminateThis As String 'The variable to hold the process to terminate
Dim objWMIcimv2 As Object
Dim objProcess As Object
Dim objList As Object
Dim intError As Integer
strTerminateThis = "Excel.exe" 'Process to terminate,
'change Excel.exe to the process you want to terminate
objWMIcimv2 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2") 'Connect to CIMV2 Namespace
objList = objWMIcimv2.ExecQuery _
("select * from win32_process where name='" & strTerminateThis & "'") 'Find the process to terminate
If objList.Count = 0 Then 'If 0 then process isn't running
MessageBox.Show(strTerminateThis & " is NOT running.")
objWMIcimv2 = Nothing
objList = Nothing
objProcess = Nothing
Exit Sub
Else
' 'Ask if OK to continue
' Select Case MsgBox("Are you sure you want to terminate this running process?:" _
' & vbCrLf & "" _
' & vbCrLf & "Process name: " & strTerminateThis _
' & vbCrLf & "" _
' & vbCrLf & "Note:" _
' & vbCrLf & "Terminating certain processes can effect the running of Windows" _
' & "and/or running applications. The process will terminate if you OK it, WITHOUT " _
' & "giving you the chance to save any changes in anything that is running in the specified process above." _
' , vbOKCancel Or vbQuestion Or vbSystemModal Or vbDefaultButton1, "WARNING:")
'
' Case vbOK
'OK to continue with terminating the process
For Each objProcess In objList
intError = objProcess.Terminate 'Terminates a process and all of its threads.
'Return value is 0 for success. Any other number is an error.
If intError <> 0 Then
MessageBox.Show("ERROR: Unable to terminate that process.", "Aborting" )
Exit Sub
End If
Next
'ALL instances of specified process (strTerminateThis) has been terminated
' Call MsgBox("ALL instances of process " & strTerminateThis & " has been successfully terminated.", _
' vbInformation, "Process Terminated")
'
' objWMIcimv2 = Nothing
' objList = Nothing
' objProcess = Nothing
' Exit Sub
'
' Case vbCancel
' 'NOT OK to continue with the termination, abort
' objWMIcimv2 = Nothing
' objList = Nothing
' objProcess = Nothing
' Exit Sub
' End Select
End If