Ms Sql Server 命令行方式的 启动,关闭

类别:编程语言 点击:0 评论:0 推荐:

前题,sql server 安装的是默认名字

BOOL StartMsSqlServer()
{
 PROCESS_INFORMATION pi   = {0};
 STARTUPINFO   si   = {0};
 BOOL    bSuccess = FALSE;
 
    bSuccess = CreateProcess(
            NULL,
            "scm -Silent 1 -Action 1 -Service mssqlserver",
            NULL,
   NULL,
            FALSE,
            CREATE_NO_WINDOW,
            NULL,
            NULL,
            &si,  //返回的结构中有进程的句柄
            &pi);

    if(bSuccess)
    {
        CloseHandle(pi.hThread);

        //用进程句柄等待进程结束
        if(WaitForSingleObject(pi.hProcess,INFINITE) == WAIT_FAILED)
  {
            bSuccess = FALSE;
  }

        CloseHandle(pi.hProcess);
    }

 return bSuccess;
}

static BOOL CloseMsSqlServer()
{
 PROCESS_INFORMATION pi   = {0};
 STARTUPINFO   si   = {0};
 BOOL    bSuccess = FALSE;
 
    bSuccess = CreateProcess(
            NULL,
            "scm -Silent 1 -Action 6 -Service mssqlserver",
            NULL,
   NULL,
            FALSE,
            CREATE_NO_WINDOW,
            NULL,
            NULL,
            &si,  //返回的结构中有进程的句柄
            &pi);

    if(bSuccess)
    {
        CloseHandle(pi.hThread);

        //用进程句柄等待进程结束
        if(WaitForSingleObject(pi.hProcess,INFINITE) == WAIT_FAILED)
  {
            bSuccess = FALSE;
  }

        CloseHandle(pi.hProcess);
    }

 return bSuccess;
}

本文地址:http://com.8s8s.com/it/it24012.htm