Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Terminate sqlservr.exe process

Terminate sqlservr.exe process

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sirtimid
    wrote on last edited by
    #1

    Hello everybody, Does anyone know ho can I terminate the sqlservr.exe process? I tried the TerminateProcess() but it didn't work and I guess that it must be the child processes or threads that might be running with it. So how can I terminate all the tree process? Thanks in Advance! sirtimid

    D T 2 Replies Last reply
    0
    • S sirtimid

      Hello everybody, Does anyone know ho can I terminate the sqlservr.exe process? I tried the TerminateProcess() but it didn't work and I guess that it must be the child processes or threads that might be running with it. So how can I terminate all the tree process? Thanks in Advance! sirtimid

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      sirtimid wrote: I tried the TerminateProcess() but it didn't work... Which means nothing unless you tell us why it failed? What does GetLastError() return?


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      S 1 Reply Last reply
      0
      • S sirtimid

        Hello everybody, Does anyone know ho can I terminate the sqlservr.exe process? I tried the TerminateProcess() but it didn't work and I guess that it must be the child processes or threads that might be running with it. So how can I terminate all the tree process? Thanks in Advance! sirtimid

        T Offline
        T Offline
        Tim Smith
        wrote on last edited by
        #3

        It is probably a service that can be shutdown using the service manager. Tim Smith I'm going to patent thought. I have yet to see any prior art.

        1 Reply Last reply
        0
        • D David Crow

          sirtimid wrote: I tried the TerminateProcess() but it didn't work... Which means nothing unless you tell us why it failed? What does GetLastError() return?


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          S Offline
          S Offline
          sirtimid
          wrote on last edited by
          #4

          This is the process that the MSSQLSERVER runs. It returned 6 (The handle is invalid. - ERROR_INVALID_HANDLE) I got the Process ID as shown below: HANDLE hProcessSnap = NULL; BOOL bRet = FALSE; PROCESSENTRY32 pe32 = {0}; hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == INVALID_HANDLE_VALUE) return FALSE; pe32.dwSize = sizeof(PROCESSENTRY32); if (Process32First(hProcessSnap, &pe32)) { DWORD dwPriorityClass,excd; BOOL bGotModule = FALSE; bool found = false; MODULEENTRY32 me32 = {0}; do { HANDLE hProcess; hProcess = OpenProcess (PROCESS_ALL_ACCESS | PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, FALSE, pe32.th32ProcessID); if(!memcmp(pe32.szExeFile,"sqlservr.exe",12)) { bGotModule = GetExitCodeProcess(hProcess, &excd); TerminateProcess(hProcess, excd); err = GetLastError(); found = true; } else { found = false; } CloseHandle (hProcess); } while (Process32Next(hProcessSnap, &pe32) && !found); } CloseHandle (hProcessSnap);

          D 1 Reply Last reply
          0
          • S sirtimid

            This is the process that the MSSQLSERVER runs. It returned 6 (The handle is invalid. - ERROR_INVALID_HANDLE) I got the Process ID as shown below: HANDLE hProcessSnap = NULL; BOOL bRet = FALSE; PROCESSENTRY32 pe32 = {0}; hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == INVALID_HANDLE_VALUE) return FALSE; pe32.dwSize = sizeof(PROCESSENTRY32); if (Process32First(hProcessSnap, &pe32)) { DWORD dwPriorityClass,excd; BOOL bGotModule = FALSE; bool found = false; MODULEENTRY32 me32 = {0}; do { HANDLE hProcess; hProcess = OpenProcess (PROCESS_ALL_ACCESS | PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, FALSE, pe32.th32ProcessID); if(!memcmp(pe32.szExeFile,"sqlservr.exe",12)) { bGotModule = GetExitCodeProcess(hProcess, &excd); TerminateProcess(hProcess, excd); err = GetLastError(); found = true; } else { found = false; } CloseHandle (hProcess); } while (Process32Next(hProcessSnap, &pe32) && !found); } CloseHandle (hProcessSnap);

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            sirtimid wrote:

            hProcess = OpenProcess (PROCESS_ALL_ACCESS | PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, FALSE, pe32.th32ProcessID); if(!memcmp(pe32.szExeFile,"sqlservr.exe",12)) {

            Shouldn't you be checking the return value from OpenProcess() before attempting to call memcmp()?


            "One must learn from the bite of the fire to leave it alone." - Native American Proverb

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups