Terminate sqlservr.exe process
-
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
-
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
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
-
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
-
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
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);
-
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);
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 callmemcmp()
?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb