我正在开发一个程序,用于将文件从本地计算机发送到通过LAN连接的其他计算机(kiosk)。 如何终止特定流程?自助服务终端正在运行应用程序,但我想先终止程序并将文件(更新)发送到文件夹,就像文件分发一样。我尝试了一些代码,但它是异常的。下面是我尝试过的两个功能,但都没有工作。如果有什么我想念或错误,请提供协助。
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?
推荐答案您的方法存在缺陷,远程终止进程并不是发送更新应用程序的好方法。相反,您应该寻找Click Once Deployment。本文 ClickOnce - 快速部署,安装和更新基于Windows的步骤客户端应用程序 [ ^ ]可以帮助您提供良好的开端。 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.
更多推荐
在LAN连接的其他计算机上终止进程
发布评论