CFanatic

Go Back   CFanatic > Programming > Win32 Programming

Join CFanatic Forum Now

how to find the running exe and kill that exe topic posted under Win32 Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2007, 05:21 AM
Member
 
Join Date: May 2007
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
vidhya is on a distinguished road
| More
how to find the running exe and kill that exe

hi

i want to know how to find wether one particular exe is running or not.if it running how to kill that exe in win32 application.
please help me to do this.
Reply With Quote
  #2  
Old 06-11-2007, 08:43 AM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,158
Thanks: 48
Thanked 62 Times in 43 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: how to find the running exe and kill that exe

Use FindWindow API
Reply With Quote
  #3  
Old 06-11-2007, 09:58 PM
Member
 
Join Date: May 2007
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
vidhya is on a distinguished road
| More
Re: how to find the running exe and kill that exe

Quote:
Originally Posted by shabbir View Post
Use FindWindow API
i used that but it is not working properly.is their any other way to do the same.what i done is finding the window if it exsist just destroy the window but it is not working.give me the solution for this please.
Reply With Quote
  #4  
Old 06-11-2007, 10:24 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,158
Thanks: 48
Thanked 62 Times in 43 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: how to find the running exe and kill that exe

Let me have what you have tried and I may be able to help you.
Reply With Quote
  #5  
Old 06-12-2007, 01:44 AM
Member
 
Join Date: May 2007
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
vidhya is on a distinguished road
| More
Re: how to find the running exe and kill that exe

Quote:
Originally Posted by shabbir View Post
Let me have what you have tried and I may be able to help you.

what i done is in main i just created one window.and then in main i am calling the one procedure in that procedure in paint case i am scrolling some text in the banner.what i want is if first time i run the code the banner should display next time if i give different arguments the old instance should be deleted or the new value whatever i pass in the command line should be updated in the same banner.i think it is working correctly .in main it is creating window and in the procedure it is just finding the window and destroying.bat what i need is first time when i run it should display the window and next time when i execute the same code it should find wether the window exist or not if the window is their just close or destroy the window and create the new window.

code is like this
Code:
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
//string1.Format("%-0s",lpCmdLine);

	

    
    MSG         Msg;

    WndCls.cbSize        = sizeof(WndCls);
    WndCls.style         = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
    WndCls.lpfnWndProc   = WindProcedure;
    WndCls.cbClsExtra    = 0;
    WndCls.cbWndExtra    = 0;
    WndCls.hInstance     = hInstance;
    WndCls.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    WndCls.hCursor       = LoadCursor(NULL, IDC_ARROW);
    WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    WndCls.lpszMenuName  = NULL;
    WndCls.lpszClassName = szAppName;
    WndCls.hIconSm       = LoadIcon(hInstance, IDI_APPLICATION);
    RegisterClassEx(&WndCls);

		    CreateWindowEx(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE | WS_EX_TRANSPARENT,
                          szAppName,
                          "GDI Accessories and Tools",
                          WS_POPUPWINDOW | WS_VISIBLE,
                          0,
                          720,
                          1500,
                          20,
						  hwnd,
                          NULL,
                          hInstance,
                          NULL);

}


if (g_SingleInstanceObj.IsAnotherInstanceRunning())
{
	exit (1);	
}
     while( GetMessage(&Msg, NULL, 0, 0) )
    {
        TranslateMessage(&Msg);
        DispatchMessage( &Msg);
    }

    return static_cast<int>(Msg.wParam);
}


LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
			   WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT Ps;
 int a;
switch(Msg)
{
	
case WM_PAINT:




szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);

if( NULL == szArglist )
{
      wprintf(L"CommandLineToArgvW failed\n");
     return 0;
}
if(FindWindow(szAppName,"GDI Accessories and Tools")!=NULL)
{
	AfxMessageBox("The");
	CloseWindow(hWnd);
	DestroyWindow(hWnd);
    
}

	ifstream myfile7;

	myfile7.open  ("C:\\cmd.txt"); 

	//sText="EOD has not been started yet";

	if(myfile7.is_open())

	{
	     while (! myfile7.eof() )

	       {

		string pline="";

		getline (myfile7,pline);

		pre_lines+=(pline+"\n"); 

						
	     }

	}

	myfile7.close();

	for( i=1; i<nArgs; i++)
	{ 
		string1=(CString)szArglist[i];

		/*	if ((CString)szArglist[i]=="0")
		{
		string2=string2-(CString)szArglist[i-1];
		}
else*/

		string2=string2+" "+string1;

		/*if((CString)szArglist[2]=="0"  && (CString)szArglist[4]=="0")
		{
			exit(1);
		}*/

	}


			CString str=pre_lines.c_str();
			string3=str+" "+string2;

			ofstream myfile4; 

			myfile4.open("C:\\banner.txt");

			if (myfile4.is_open())

			{


				myfile4 << string(string2);

			}

			myfile4.close();

			
		do
		{
			hDC = BeginPaint(hWnd, &Ps);
			//TextOut(hDC, 10, 1,"Priority 1 Incidents:",21);
			/*	Color(11000000);



					SolidBrush( Color &color
);
					Graphics* g = button1->CreateGraphics();
					Pen* myPen = new Pen(Color::Red);
					myPen->Width = 5;*/
					for(a=1;a<1000;a++)
					{
												
			TextOut(hDC, 10, 1,"Priority 1 Incidents:",21);
			TextOut(hDC, a+150, 1,string2,string2.GetLength());
			//g->DrawLine(myPen, 1, 1, 45, 65);
			EndPaint(hWnd, &Ps);
			Sleep(10); //how fast the text should scroll						
						
			}
					
					
		}while(!NULL);				
			break;
		}

		case WM_DESTROY:
		PostQuitMessage(WM_QUIT);
		break;
	default:
		return DefWindowProc(hWnd, Msg, wParam, lParam);
	}
	return 0;	
}

Last edited by shabbir; 06-12-2007 at 10:12 AM. Reason: Code block
Reply With Quote
  #6  
Old 06-12-2007, 10:13 AM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,158
Thanks: 48
Thanked 62 Times in 43 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: how to find the running exe and kill that exe

Just don't put all your code and say I have done this. Have the code which is relevant. Also learn to use the code block when you have code in the posts.
Reply With Quote
  #7  
Old 06-13-2007, 02:20 AM
Member
 
Join Date: May 2007
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
vidhya is on a distinguished road
| More
Re: how to find the running exe and kill that exe

Quote:
Originally Posted by shabbir View Post
Just don't put all your code and say I have done this. Have the code which is relevant. Also learn to use the code block when you have code in the posts.

ok . sorry for the mistake.
what i done is in main i just created one window.and then in main i am calling the one procedure in that procedure in paint case i am scrolling some text in the banner.what i want is if first time i run the code the banner should display next time if i give different arguments the old instance should be deleted or the new value whatever i pass in the command line should be updated in the same banner.i think it is working correctly .in main it is creating window and in the procedure it is just finding the window and destroying.bat what i need is first time when i run it should display the window and next time when i execute the same code it should find wether the window exist or not if the window is their just close or destroy the window and create the new window.



Code:
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
			   WPARAM wParam, LPARAM lParam)
{
   switch(Msg)
{
	
case WM_PAINT:

if(FindWindow(szAppName,"GDI Accessories and Tools")!=NULL)
{
	AfxMessageBox("The");
	CloseWindow(hWnd);
	DestroyWindow(hWnd);
    
}
.....................
}
Reply With Quote
  #8  
Old 06-13-2007, 09:01 AM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,158
Thanks: 48
Thanked 62 Times in 43 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: how to find the running exe and kill that exe

You have made big mistake. You have not used the hWnd returned by the FindWindow but have used the hWnd of the current application.

Also you don't need to be doing that in WM_PAINT and I have told that before as well how to do this using some message like send a user message to the new exe where it kills itself.
Reply With Quote
  #9  
Old 06-14-2007, 01:31 AM
Member
 
Join Date: May 2007
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
vidhya is on a distinguished road
| More
Re: how to find the running exe and kill that exe

Quote:
Originally Posted by shabbir View Post
You have made big mistake. You have not used the hWnd returned by the FindWindow but have used the hWnd of the current application.

Also you don't need to be doing that in WM_PAINT and I have told that before as well how to do this using some message like send a user message to the new exe where it kills itself.

thanks shabbir.i corrected the code.but now while executing the old window is not at all closing i mean to say the new value whatever i am passing is not updating in the diffrent window.i coded just like this.is it ok if i do like this.please give the solution for this as early as possible.

Code:
Hwnd = FindWindow("GDISuite","GDI Accessories and Tools"); 
if(Hwnd!= NULL)
{

            UpdateWindow(hwnd);

	//stroyWindow(Hwnd);
	//xMessageBox("Window Destryoed");
	
	//CloseWindow(hwnd);
	//ExitProcess(0);
	
}
Reply With Quote
  #10  
Old 06-14-2007, 02:37 AM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,158
Thanks: 48
Thanked 62 Times in 43 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: how to find the running exe and kill that exe

Check the article Single Instance Application
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please, help me to find sites to fix some bugs on my PC. brierieTago Introduce yourself 2 01-25-2009 02:39 AM
what is the simplest way to kill or close or terminate an application? chrono Win32 Programming 4 10-05-2008 04:15 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:22 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board