[Qt-interest] How to close a process running on windows !

Santhosh Y santhosh at softjin.com
Tue Sep 14 13:20:42 CEST 2010


Hi,

This is in context of closing nxdatcom.exe process.

I am able to get the handle to the process in which I am interested in 
closing, but when I call TerminateProcess() it is returning me false.
That means it is not able to terminate the process. Any idea on 
alternative !

////////////////////////////////////////////////////////////////////////////////////////////////////

     bool isRunning()
     {
         unsigned long aProcesses[1024], cbNeeded, cProcesses;
         if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
             return false;

         cProcesses = cbNeeded / sizeof(unsigned long);

         for(unsigned int i = 0; i < cProcesses; i++) {
             if(aProcesses[i] == 0)
                 continue;

             HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | 
PROCESS_VM_READ, 0, aProcesses[i]);

             wchar_t buffer[50];

             GetModuleBaseName(hProcess, 0, buffer, 50);

             std::string str;
             for (int i=0; i < 50; i++) {
                 str.push_back (buffer[i]);
             }

*// std::cout << str << std::endl;
             // Able to print  all the exe's running over my machine*

             if(strcmp(str.c_str(), "nxdatcom.exe") == 0) {

                 //CloseHandle(hProcess);

* BOOL b = TerminateProcess( hProcess, 0); // This is failing; Any idea 
on alternative !*

                 if (b == false) {
                    std::cout <<  GetLastError() << std::endl;
                 }
                 return b;
             }
         }
         return false;
     }

-- 
----------------------------------------------------
Y Santhosh Kumar -
Senior Software Engineer,
SoftJin Technologies Pvt Ltd,
www.softjin.com
----------------------------------------------------



Business Disclaimer
____________________________________________________________
This e-mail message and any files transmitted with it are intended solely
for  the use  of the  individual or entity  to which they  are  addressed. It
may  contain confidential,  proprietary or legally  privileged  information.
If  you  are  not  the  intended recipient please be advised that you have
received  this  message in error and any use is strictly prohibited. Please
immediately  delete it  and all copies of it from your system, destroy any
hard  copies  of  it and  notify  the  sender  by return mail. You must not,
directly or indirectly, use,  disclose,  distribute, print, or copy any part of
this message if you are not the intended recipient.
___________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100914/1ac19e88/attachment.html 


More information about the Qt-interest-old mailing list