Now: Tutorial for Web and Software Design > Programming > c > Programming Content
> Using WinExec function [Bookmark it]
Using WinExec function

WinExec Function

   WinExec is a WINDOWS API function that can be used in case we want to execute legacy applications. This function is used with processes( Resources needed to execute a program ). The function expects the application name enclosed in quotation marks as shown.

    WinExec("\"C:\\Program Files\\MyApp.exe\" -L -S",SW_SHOWNORMAL)

   If a malicious user were to create an application called "Program.exe" on a system, any program that incorrectly calls WinExec using the Program Files directory will run this application instead of the intended application. To avoid the problem, use CreateProcess rather than WinExec. However, one can use WinExec function for legacy reasons.

    The following code is an example for using WinExec in an MFC Code where  Myface.exe is an existing application in the root directory.


#include <afxwin.h>
#include <afxext.h>
#include "resource.h"

class myFr : public CFrameWnd
{

 CMenu cm;
 public:
  myFr()
  {

  Create(NULL,"Sample Window");
  cm.LoadMenu(IDR_MENU1);
  SetMenu(&cm);

  }

  void msg()
  {
   _T(WinExec("c:\\MyFace.exe",SW_SHOWNORMAL));
  }

  void msg1()
  {
   PostQuitMessage(0);
  }

 DECLARE_MESSAGE_MAP()
 };

 BEGIN_MESSAGE_MAP(myFr,CFrameWnd)
  ON_COMMAND(ID_CLICK,msg)
  ON_COMMAND(ID_EXIT,msg1)
 END_MESSAGE_MAP()

class MyApp :public CWinApp
 {
 myFr *wnd;
 public:
 BOOL InitInstance()
 {
        wnd = new myFr();
        m_pMainWnd = wnd;
        m_pMainWnd->ShowWindow(1);
        return 1;
     }
 };

 MyApp anApp;


   Use the above code with Microsoft Visual C++ 6.0.


[Bookmark][Print] [Close][To Top]
  • Prev Article-Programming:

  • Next Article-Programming:
  • Related Materias
    Passing an Array to and fr
    Using the ForEach Stateme
    Executing a VB Program wit
    Sorting Viewer Tutorial - 
    Crystal Reports Tutorial -
    Creating a Toolbar - Visua
    Random Numbers - Randomize
    File Dialog Box - Tutorial
    Using Office applications 
    Visual Basic Explorer - Tu
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial