Question

[C++] Kill a process

Asked by: JapyDooge

I have a little problem here.
In C++ i create a process and after that i want to end (kill) it but for some reason i can't get this to work.
Check my code down here and see what i already tried (a LOT).

Most of this code is made of 'fount' pieces over the net.
I added 'EndTask' but it says:

 C:\Documents and Settings\2wjd\My Documents\Dev-C++\Projects\T2\main.cpp In function `LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':
353 C:\Documents and Settings\2wjd\My Documents\Dev-C++\Projects\T2\main.cpp `EndTask' undeclared (first use this function)
  (Each undeclared identifier is reported only once for each function it appears in.)
 C:\Documents and Settings\2wjd\My Documents\Dev-C++\Projects\T2\Makefile.win [Build Error]  [main.o] Error 1

That's strange becouse i have al needed includes.

I'm using Dev-C++, the starting and running of my program works great, i only want to kill the process i create on exit...

// test the listbox creation and selection
// modified from BCX generated C code for Dev-C++
// a Dev-C++ tested Windows Application by  vegaseat  04nov2004
 
#include <windows.h>
#include <winuser.h>
#include <stdio.h>
 
using namespace std;
 
static HINSTANCE BCX_hInstance;
static int     BCX_ScaleX;
static int     BCX_ScaleY;
static char    BCX_ClassName[2048];  // default size
static char    text[2048];
static HWND    Form1;
static HWND    List1;
static HWND    Butn1;
static HWND    Butn2;
int     IntSucces;
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
#define Show(Window)  RedrawWindow(Window,0,0,0);ShowWindow(Window,SW_SHOW);
 
HWND    BCX_Form(char*,int=0,int=0,int=250,int=150,int=0,int=0);
HWND    BCX_Listbox(char*,HWND,int  ,int  ,int  ,int  ,int  ,int=0,int=-1);
HWND     BCX_Button(char*,HWND,int=0,int=0,int=0,int=0,int=0,int=0,int=-1);
int     BCX_Set_Text(HWND,char*);
void    Center (HWND,HWND=0,HWND=0);
char*   BCX_TmpStr(size_t);
 
void    FormLoad (void);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void    addLB (HWND, char *);
char    * getLB (HWND);
 
// sample data for the list box
static char names[2][10]=
{
  "WVUN002", "NVUN012"
};
 
 
// this is the standard windows main() function
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR CmdLine,int CmdShow)
{
 WNDCLASS Wc;
 MSG      Msg;
 // *****************************
 strcpy(BCX_ClassName,"ListBox1");
 // ***************************************
 // Programmer has selected to use pixels
 // ***************************************
 BCX_ScaleX       = 1;          // for generic scaling
 BCX_ScaleY       = 1;
 BCX_hInstance    =  hInst;
 // ******************************************************
 Wc.style         =  CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
 Wc.lpfnWndProc   =  WndProc;
 Wc.cbClsExtra    =  0;
 Wc.cbWndExtra    =  0;
 Wc.hInstance     =  hInst;
 Wc.hIcon         =  LoadIcon(NULL,IDI_WINLOGO);
 Wc.hCursor       =  LoadCursor(NULL,IDC_ARROW);
 Wc.hbrBackground =  (HBRUSH)(COLOR_BTNFACE+1);
 Wc.lpszMenuName  =  NULL;
 Wc.lpszClassName =  BCX_ClassName;
 RegisterClass(&Wc);
 
 FormLoad();
  // the event message loop
 while(GetMessage(&Msg,NULL,0,0))
   {
    HWND hActiveWindow = GetActiveWindow();
    if (!IsWindow(hActiveWindow) || !IsDialogMessage(hActiveWindow,&Msg))
      {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
      }
    }
 return Msg.wParam;
}
 
 
// circular storage for strings
char *BCX_TmpStr (size_t Bites)
{
  static int   StrCnt;
  static char *StrFunc[2048];
  StrCnt=(StrCnt + 1) & 2047;
  if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);
  return StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));
}
int BCX_Set_Text(HWND hWnd, char *Text){
      return SetWindowText(hWnd,Text);
}
 
// center the form in the screen (really optional, for looks)
void Center (HWND hwnd, HWND Xhwnd, HWND Yhwnd)
{
  RECT rect, rectP;
  int  x, y, width, height;
  int  screenwidth, screenheight;
  if(Xhwnd==0)
    {
      RECT  DesktopArea;
      RECT  rc;
      SystemParametersInfo(SPI_GETWORKAREA,0,&DesktopArea,0);
      GetWindowRect(hwnd,&rc);
      SetWindowPos(hwnd,HWND_TOP,
        ((DesktopArea.right-DesktopArea.left)-(rc.right-rc.left))/2+
          DesktopArea.left,((DesktopArea.bottom-DesktopArea.top)-
         (rc.bottom-rc.top))/2 + DesktopArea.top,0,0,SWP_NOSIZE);
      return;
    }
  GetWindowRect (hwnd,&rect);
  GetWindowRect (Xhwnd,&rectP);
  width = rect.right-rect.left;
  x = ((rectP.right-rectP.left)-width)/2 + rectP.left;
  if(Yhwnd==NULL)
    {
      height = rect.bottom-rect.top;
      y = ((rectP.bottom-rectP.top)-height)/2 + rectP.top;
    }
  else
    {
      GetWindowRect(Yhwnd,&rectP);
      height = rect.bottom-rect.top;
      y = ((rectP.bottom-rectP.top)-height)/2+rectP.top;
    }
  screenwidth = GetSystemMetrics(SM_CXSCREEN);
  screenheight = GetSystemMetrics(SM_CYSCREEN);
  if ((x<0)) x=0;
  if ((y<0)) y=0;
  if ((x+width>screenwidth))   x = screenwidth-width;
  if ((y+height>screenheight)) y = screenheight-height;
  MoveWindow (hwnd, x, y, width, height, FALSE);
}
 
 
// create the windows form
HWND BCX_Form(char *Caption, int X, int Y, int W, int H, int Style, int Exstyle)
{
   HWND  A;
   // assign a default style
   if (!Style)
   {
     Style=
//     WS_MINIMIZEBOX  |
//     WS_SIZEBOX      |
     WS_CAPTION      |
//     WS_MAXIMIZEBOX  |
     WS_POPUP        |
     WS_SYSMENU      ;
   }
   A = CreateWindowEx(Exstyle,BCX_ClassName,Caption,
     Style,
     X*BCX_ScaleX,
     Y*BCX_ScaleY,
     (4+W)*BCX_ScaleX,
     (12+H)*BCX_ScaleY,
     NULL,(HMENU)NULL,BCX_hInstance,NULL);
   SendMessage(A,(UINT)WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),
     (LPARAM)MAKELPARAM(FALSE,0));
   return A;
}
 
 
// create the list box with desired styles
HWND BCX_Listbox
(char* Text,HWND hWnd,int id,int X,int Y,int W,int H,int Style,int Exstyle)
{ 
  HWND  A;
  // assign a default style if needed
  if (!Style)
  {
    Style=LBS_STANDARD | WS_CHILD | WS_VISIBLE |
    LBS_SORT | WS_VSCROLL | WS_TABSTOP;
  }
  if (Exstyle == -1)
  {
    Exstyle=WS_EX_CLIENTEDGE;
  }
  A = CreateWindowEx(Exstyle,"Listbox",NULL,Style,
        X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,
        hWnd,(HMENU)id,BCX_hInstance,NULL);
  SendMessage(A,(UINT)WM_SETFONT,(WPARAM)GetStockObject
        (DEFAULT_GUI_FONT),(LPARAM)MAKELPARAM(FALSE,0));
  return A;
}
 
 
// create the various buttons
HWND BCX_Button
(char* Text,HWND hWnd,int id,int X,int Y,int W,int H,int Style,int Exstyle)
{ 
HWND A;
// assign default style
if(!Style)
{
Style=WS_CHILD | WS_VISIBLE | BS_MULTILINE | BS_PUSHBUTTON | WS_TABSTOP;
}
if(Exstyle==-1)
{
Exstyle=WS_EX_STATICEDGE;
}
A = CreateWindowEx(Exstyle,"button",Text,Style,
X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,
hWnd,(HMENU)id,BCX_hInstance,NULL);
SendMessage(A,(UINT)WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),
(LPARAM)MAKELPARAM(FALSE,0));
if (W==0)
{
HDC hdc=GetDC(A);
SIZE size;
GetTextExtentPoint32(hdc,Text,strlen(Text),&size);
ReleaseDC(A,hdc);
MoveWindow(A,X*BCX_ScaleX,Y*BCX_ScaleY,(int)(size.cx+(size.cx*0.5)),(int)(size.cy+(size.cy*0.32)),TRUE);
}
return A;
}
 
 
// the details for Form1 and List1 (corner,width,height)
void FormLoad (void)
{
  static char A[2048];
  memset(&A,0,sizeof(A));
  static int      k;
  memset(&k,0,sizeof(k));
  Form1=BCX_Form("Select connection:",0,0,235,195);
  List1=BCX_Listbox("",Form1,1009,10,15,100,150);
  Butn1=BCX_Button("Connect",Form1,1010,120,140,100,25);
  Butn2=BCX_Button("Exit",Form1,1011,120,15,100,25);
  for(k=0; k<=1; k+=1)
  {
    strcpy(A,(char*)names[k]);
    addLB(List1,A);
  }
  Center(Form1);   // optional
  Show(Form1);
}
 
void KillProcess(DWORD pid)
{
HANDLE tokenHandle = INVALID_HANDLE_VALUE;
TOKEN_PRIVILEGES newTokenPrivileges;
TOKEN_PRIVILEGES oldTokenPrivileges;
DWORD oldTokenPrivilegeSize = 0;
LUID newLuid;
 
// Get Debug Privileges for current process
if(!OpenProcessToken(GetCurrentProcess(), (TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY), &tokenHandle))
{
printf ("Unable to get current process token - %d\n", GetLastError());
return;
}
 
// Get the LUID for SE_DEBUG_NAME
if(!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &newLuid))
{
printf ("Unable to lookup privilege value SE_DEBUG_NAME - %d\n", GetLastError());
return;
}
 
// Setup new token privileges
newTokenPrivileges.PrivilegeCount = 1; // We need only one privilege to change time
// Copy over privilege value to one which we will send to system
memcpy(&newTokenPrivileges.Privileges[0].Luid, &newLuid, sizeof(LUID)); // The privilege to change system time
newTokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // Enable it !!
 
// Adjust the process token privileges
if(!AdjustTokenPrivileges(tokenHandle, FALSE, &newTokenPrivileges, sizeof(TOKEN_PRIVILEGES), &oldTokenPrivileges, &oldTokenPrivilegeSize))
{
printf ("Unable to adjust token privileges for current process - %d\n", GetLastError());
return;
}
 
HANDLE processHandle = OpenProcess (PROCESS_ALL_ACCESS, 0, pid);
 
if (!processHandle)
{
//printf ("Could not get process andle for %d... error = %d\n", pid, GetLastError));
//continue;
}
 
if (!TerminateProcess(processHandle, 0))
{
//printf ("Could not terminate process %d... error = %d\n", pid, GetLastError());
//continue;
}
 
CloseHandle(processHandle);
}
 
 
 
 
 
// standard windows message handling
LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
  while(1)
  {
    if (Msg==WM_COMMAND)
    {
      //  list box item clicked (selected) 
      if (LOWORD(wParam)==1009)
      {
        if (HIWORD(wParam)==LBN_SELCHANGE)
        {
          strcpy(text,(char*)getLB(List1));
          //  just for test 
          //Beep(400,500);
          //  selected item to form title 
//          SetWindowText(Form1,text);
          BCX_Set_Text(Butn1,text);
//          system("notepad");
//          Butn1=BCX_Button(text,Form1,1009,120,140,100,25);
        }
      }
      if (LOWORD(wParam)==1010)
      {
          char buffer [500];
//          int n;
          //system("winvnc4.exe -register");
          //system("winvnc4.exe -start");
	//I know its annoying that CreateProcess REQUIRES these
 
	memset(& si, 0, sizeof(si));
	memset(& pi, 0, sizeof(pi));
 
	IntSucces = CreateProcess(NULL, "winvnc4.exe", NULL, NULL, FALSE, 0, 0, NULL, & si, & pi);
 
 
          //system("winvnc4.exe");
          sprintf(buffer, "%s %s %s", "winvnc4.exe -noconsole -connect", text,"DisableWallpaper=1");
          system(buffer);
 
      }
      if (LOWORD(wParam)==1011)
      {
          CloseHandle(pi.hThread );
          CloseHandle(pi.hProcess );
 
 
 
 
 
          IntSucces = TerminateProcess(pi.hProcess,1);
          CloseHandle(pi.hProcess);
          KillProcess((DWORD)pi.hProcess);
          EndTask(pi.hProcess, 0, 1);
          system("winvnc4.exe -disconnect");      
          system("winvnc4.exe -stop");          
          system("winvnc4.exe -unregister");
          UnregisterClass(BCX_ClassName,BCX_hInstance);
          PostQuitMessage(0);                                        
      } 
    }
    break;
  }
  // exit from the window form
  if (Msg==WM_DESTROY)
  {
            KillProcess((DWORD)pi.hProcess);
          CloseHandle(pi.hThread );
          CloseHandle(pi.hProcess );
          EndTask(pi.hProcess, 0, 1);
          IntSucces = TerminateProcess((void*)pi.dwProcessId,1);
          system("winvnc4.exe -disconnect");      
          system("winvnc4.exe -stop");          
          system("winvnc4.exe -unregister");
    UnregisterClass(BCX_ClassName,BCX_hInstance);
    PostQuitMessage(0);
  }
  return DefWindowProc(hWnd,Msg,wParam,lParam);
}
 
 
//  add a string to the listbox 
void addLB (HWND idnr, char *ltext)
{
  SendMessage(idnr,(UINT)LB_ADDSTRING,(WPARAM)0,(LPARAM)ltext);
}
 
//  return selected listbox string
char * getLB (HWND idnr)
{
  static int      index;
  memset(&index,0,sizeof(index));
  static char buf[2048];
  memset(&buf,0,sizeof(buf));
  char *BCX_RetStr={0};
  index=SendMessage(idnr,(UINT)LB_GETCURSEL,(WPARAM)0,(LPARAM)0);
  SendMessage(idnr,(UINT)LB_GETTEXT,(WPARAM)index,(LPARAM)buf);
  BCX_RetStr=BCX_TmpStr(strlen(buf));
  strcpy(BCX_RetStr,buf);
  return BCX_RetStr;
}
 
// *************************************************************
//   Created with BCX -- The BASIC To C Translator (ver 5.02)
//  BCX (c) 1999, 2000, 2001, 2002, 2003, 2004 by Kevin Diggins
// *************************************************************

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-08-05 at 08:24:31ID23622548
Tags

C++

,

n/a

Topics

C++ Programming Language

,

Microsoft Visual C++.Net

,

Microsoft Windows Operating Systems

Participating Experts
3
Points
500
Comments
13

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. how to Case a UINT
    A windoze "C" question If two different applications register the same message string, the applications return the same message value. The message remains registered until the Windows session ends. like this ........ UINT NEW_MSG = RegisterWindowMessage("NE...
  2. Kill a process
    How can I kill a process launched in a Visual Basic project with an expression like : Shell("calc.exe") with another expression in the same project?
  3. Question about LPARAM , WPARAM etc
    A simple theory question (I think). LPARAM , RPARAM , WPARAM etc. What are these?? Using them in my code if I look at them all I see is a value (number) yet somehow this "value" will contain a number I need but can;t see anywhere. ie :OnClickListcontrol(NMHDR* pNM...
  4. Kill a process
    Hi, Could someone show me an example on how to kill a process. It needs to work on 9x and NT. The process I would like to kill is aim.exe "which is AOL Instant Messenger" Thanks
  5. Kill a process
    I need to kill a process (actually a 'service') programmatically using VB6. This process has no forms or windows (it is a service running in the background). All the examples I can find to kill a process involve using 'GetWindow()' to find the hWnd handle by window caption...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: jkrPosted on 2008-08-05 at 08:49:34ID: 22162139

There is in fact no such function named 'EndTask()', neither in your code nor in the Win32 API. But, looking at your code, it seems that it is not needed at all, since the relevant part is already performed by the call to 'KillProcess()' in the preceding lines. Just remove the two calls to 'EndTask()' and you should be fine.

 

by: jkrPosted on 2008-08-05 at 08:50:35ID: 22162153

BTW, see also http://support.microsoft.com/default.aspx?scid=KB;en-us;178893& ('How To Terminate an Application "Cleanly" in Win32')

 

by: rendaduiyanPosted on 2008-08-05 at 22:44:35ID: 22167377

if EndTask is your code, please declare at the begining of the C files.
void EndTask(Process, int, int);
something like that.

 

by: JapyDoogePosted on 2008-08-06 at 01:15:14ID: 22168048

Thanks for the comments, but EndTask was my last try after i found it somewhere on the net.

EndTask() is also in winuser.h and i include that so it should work.

Removing EndTask() does'nt work either...

 

by: jkrPosted on 2008-08-06 at 07:38:15ID: 22170714

Um, there is no 'EndTask()' in winuser.h, neither elsewhere...

 

by: JapyDoogePosted on 2008-08-06 at 07:52:45ID: 22170901

So what is this?

 

by: rendaduiyanPosted on 2008-08-11 at 19:15:17ID: 22209688

Windows 2000       0x0500
Windows Server 2003, Windows XP       0x0501
...

if you realy need this API, please define this macro
_WIN32_WINNT 0x50 accordingly in your stdafx.h

 

by: JapyDoogePosted on 2008-08-18 at 08:52:06ID: 22252996

I don't need that API but i need a way to kill a process from C++ (one i also started in C++)
It can't be that hard, does no one know how to do it? I tried a lot of different ways...

 

by: Jimmyg22Posted on 2009-02-10 at 14:12:02ID: 23606112

Well there is one way to do it, but its not the best way. you could include windows.h and then use the system () call to exit the application. ex. system ("taskkill /im Program.exe");

 

by: jkrPosted on 2009-05-25 at 13:42:33ID: 24468604

Tend to object - in the above, there's a link to a fully-fledged MSDN article on how to do that, complete source code included.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...