Click here to Skip to main content
15,920,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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
                Exit Sub
            End If
    End Sub
    Private Function WMIKill(ByVal Server As String, ByVal sProcess As String)
            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, "-----------------------------------")
        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?
Dave Kreskowiak 4-Sep-14 9:13am    
It throws an exception, huh? Why is it every noob thinks that the exception message is not important when asking a question about it??
Luiey Ichigo 10-Sep-14 5:21am    
Hi Dave,

Thanks for the remind. Exception message "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

1 solution

Well your approach has flaws, Terminating a process remotely is not a good solution to send updated applications. Instead you should look for Click Once Deployment. This article ClickOnce - Quick steps to Deploy, Install and Update Windows Based Client Applications[^] could help you giving a good start.
Share this answer
Luiey Ichigo 4-Sep-14 4:21am    
i'm using this because if there is any file require update, then I will select a folder an copied all inside folder to the other PC. The main program is running on flash. There is another vendor do this. While me, doing the distribution for any update to the content. Can my situation implement it too?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900