Hi,
I'm developing a program to send file from local computer to other computer(kiosk) which connected through LAN.
How to terminate a specific process? The kiosk is running with application, though I want to terminate the program first and send file (update) to the folder just like file distribution. I have tried some code but it goes exception. Below are two function that I tried, but none working. Please assist if there is something that I miss or mistake.
Public Sub endprocess(ByVal RemotePC As String, ByVal process As String)
Dim objWMIService As Object
Dim colProcessList As Array
Dim objprocess As Object
Dim response As Boolean
objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & RemotePC & "\root\cimv2")
process = "'" & process & "'"
colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " & process)
For Each objprocess In colProcessList
response = MsgBox("End " & process & " on " & RemotePC & "?", MsgBoxStyle.YesNoCancel)
If response = vbYes Then
objprocess.Terminate()
Else
Exit Sub
End If
Next
End Sub
Private Function WMIKill(ByVal Server As String, ByVal sProcess As String)
Try
Dim scope As New ManagementScope("\\" & Server & "\root\CIMV2")
Dim query As New ObjectQuery("SELECT * FROM Win32_Process WHERE Name = '" & sProcess & "'")
Dim searcher As New ManagementObjectSearcher(scope, query)
For Each queryObj As ManagementObject In searcher.Get()
AppendTextBox(txtevents, "-----------------------------------")
AppendTextBox(txtevents, "Win32_Process instance")
AppendTextBox(txtevents, queryObj("Name"))
AppendTextBox(txtevents, "-----------------------------------")
Next
Catch err As ManagementException
AppendTextBox(txtevents, "An error occurred while querying for WMI data: " & err.Message)
Catch unauthorizedErr As System.UnauthorizedAccessException
AppendTextBox(txtevents, "Connection error (user name or password might be incorrect): " & unauthorizedErr.Message)
End Try
End Function
And if someone does this function before, please share. How to run back the application that already updating?