首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找到PID VB.net

找到PID VB.net
EN

Stack Overflow用户
提问于 2015-10-03 19:09:55
回答 1查看 901关注 0票数 0

我正试图在我的游戏中制作一个服务器发射器。我得用不同的吐露来启动GameServer.exe。

GameServer.exe GameServer1.cfg

GameServer.exe GameServer2.cfg

GameServer.exe、GameServer3.cfg等。

下面是我必须启动这些..exe和..cfg的当前代码

代码语言:javascript
复制
Private Sub GS1_Click(sender As Object, e As EventArgs) Handles GS1.Click
    Dim path As String = Directory.GetCurrentDirectory()
    Dim gameservercfg As String = GameServer1.Text
    Dim newpath As String = path + ("\")
    System.Diagnostics.Process.Start(newpath + "GameServer.exe ", gameservercfg)
End Sub

下面是我的代码,通过进程名重新启动它。

代码语言:javascript
复制
Private Sub GSRES_Click(sender As Object, e As EventArgs) Handles GSRES.Click
    Dim path As String = Directory.GetCurrentDirectory()
    Dim gameservercfg As String = GameServer.Text
    Dim newpath As String = path + ("\")
    Dim p() As Process

    p = Process.GetProcessesByName("GameServer")
    If p.Count > 0 Then
        ' Process is running
        Process.GetProcessesByName("GameServer")(0).Kill()
        System.Diagnostics.Process.Start(newpath + "GameServer.exe ", gameservercfg)
    Else
        ' Process is not running
        MsgBox("GameServer is not running!")
    End If
End Sub

有了这段代码,它就会重新启动随机游戏玩家。

问题是,我如何通过ProcessID而不是进程名来做到这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-03 22:15:43

不确定您到底在执行什么here...but,这将杀死现有的游戏实例,如果它在重新启动之前运行:

代码语言:javascript
复制
Private Games As New Dictionary(Of String, Process)

Private Sub GS1_Click(sender As Object, e As EventArgs) Handles GS1.Click
    Dim gameservercfg As String = GameServer1.Text
    Dim Key As String = gameservercfg.ToUpper

    If Games.ContainsKey(Key) Then
        If Not Games(Key).HasExited Then
            Games(Key).Kill()
        End If
        Games.Remove(Key)
    End If

    Dim psi As New ProcessStartInfo
    psi.FileName = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "GameServer.exe")
    psi.WorkingDirectory = System.IO.Path.GetDirectoryName(psi.FileName)
    psi.Arguments = gameservercfg
    Games.Add(Key, System.Diagnostics.Process.Start(psi))
End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32926417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档