gpt4 book ai didi

c# - 绑定(bind)到现有进程

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:53 27 4
gpt4 key购买 nike

我正在尝试以编程方式打开 SQL Server Management studio,我使用 Process 打开 SQL Server 并使用 Start() 方法打开进程,

                    using System.Diagnostics;
Process Sql = new Process();
string strfile1="example1.sql";
string strfile2="example2.sql";
Sql.StartInfo.FileName = "Ssms.exe";//sql server process
Sql.StartInfo.Arguments = strfile1;
Sql.Start();
Sql.StartInfo.Arguments = strfile2;
Sql.Start();

这段代码打开了两个 SQL Server 实例,但我想检查进程是否已经在运行并重用现有进程并在同一个进程中打开 example2.sql。如何做到这一点?

最佳答案

您可以通过名称检查进程是否正在运行(您需要找出您的 ssms 进程的名称),如下所示:

Process[] procName= Process.GetProcessesByName("INSERT NAME HERE");
if (procName.Length >= 0)
{
//you are already running
}

但我认为您无法修改现有的 ssms 实例。

关于c# - 绑定(bind)到现有进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15542126/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com