How to run shell command by MFC ?

CK CK 3788 
Created at  
436 0 0

Followings are the useful example can run shell command.
 

/*

    Programmed 1998 by Kurapa Chunun Kang (kurapa@kurapa.com)

    By below function, you can run shell command easily.

*/

#include <shellapi.h>

void KShellExecute(HWND handle, LPCTSTR exe, LPCTSTR param, LPCTSTR dir)
{
    DWORD ExitCode;
    SHELLEXECUTEINFO SEInfo;

    memset( &SEInfo, 0, sizeof(SEInfo));
    SEInfo.cbSize = sizeof(SHELLEXECUTEINFO);

    SEInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    SEInfo.hwnd = handle;
    SEInfo.lpFile = exe;
    SEInfo.lpParameters = param;
    SEInfo.lpDirectory = dir;
    SEInfo.nShow = SW_HIDE; // SW_SHOWNORMAL;


    if (ShellExecuteEx(&SEInfo)==TRUE)
    {
        do
        {
            GetExitCodeProcess(SEInfo.hProcess, &ExitCode);
            Sleep(500);
        } while (ExitCode); // wait until the command is finished
    }
}


If you want to launch browser for specific URL, simple run as below:

.
.
.
above source
.
.
.

KShellExecute( NULL, "http://strcpy.com",NULL, NULL);

* Note: The above code must be included in the same source.

Tags BrowseDialog C++ ShellExecute ShellExecuteEx Facebook X
Comments 0
Similar posts
  1. Binary Search Sample Code
    405
  2. Double Linked List based in C++
    796
  3. Display Standard Windows Properties dialog
    1,129
  4. How to install an INF file using Delphi ?
    462
  5. MFC based World Wide Web HTTP Server Source Code
    459
  6. Creating and Using a CAsyncSocket Object to use CAsyncSocket
    472
  7. Fast and Good Keyboard/Mouse Test without the message handler
    982
  8. Simple CGI Programming in C
    545
  9. C++ CGI Example working on Apache
    484
  10. How To Open Url In Default Webbrowser
    458
  11. How to search file on certain directory ?
    630
  12. How to call SetTimer function on MFC CDialog class ?
    650
  13. Makefile to automate the build process for C++
    279
  14. How to load HTML resource on MFC ?
    841
  15. URL Encode, Decode function for MFC
    605
  16. How to print external document ?
    414
  17. How to launch the external application in Delphi ?
    1,069
  18. KMP String Matching Algorithm
    672
  19. Delphi Program can command level execution program with hidden mode
    699
  20. Run command with Administrator permission in Delphi on Microsoft Windows
    762
  21. Run PowerShell Command as Administrator in Delphi
    655
  1. Makefile to automate the build process for C++
    279
  2. Finding process name on OS
    408
  3. Convert System.DateTime to UNIX timestamp
    381
  4. Retrieve system information
    495
  5. How to call SetTimer function on MFC CDialog class ?
    650
  6. How to rename(change file name) in C# ?
    1,075
  7. Find Files in certain directory
    926
  8. Implementing C#'s foreach loop in Delphi 8
    459
  9. How to detect resource leaks in a Form
    939
  10. The best way to enable and disable buttons, menu items and toolbar buttons
    667
  11. How to exit from a console application
    811
  12. How to restrict a program to a single instance
    729
  13. Compress and decompress strings in C#
    971
  14. Graphics in C# - Irregular Forms
    908
  15. Extracting the Country from IP Address
    468
  16. Binary Search Sample Code
    405
  17. Double Linked List based in C++
    796
  18. String Replace Function For C#
    1,547
  19. How to print character in C# by ASCII code
    477
  20. MFC based World Wide Web HTTP Server Source Code
    459
  21. Creating and Using a CAsyncSocket Object to use CAsyncSocket
    472
  22. UDP Send and Receive Using CAsyncSocket
    1,204
  23. Using the shell to receive notification of removable media being inserted or removed
    681
  24. Adding Custom Paper Sizes To Named Printers
    647
  25. Print HTML In C# With Or Without The Web Browser Control And The Print Dialog
    972
  26. A Customizable Printing Text Class
    432
  27. Simplified .NET Printing In C#
    692
  28. How To Print Text In C#
    455
  29. C# Lists
    1,151
  30. Simple Example of IF/THEN using C#
    1,265
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    40
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    34
  3. How do I create animated background for Google Meet?
    20,613
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    244
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    514
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    287
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    230
  16. TPU & GPU Cluster Management Tools
    244
  17. The Concept of Scaffolding in AI Agents
    233
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    258
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    221
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    220
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    195
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    217
  30. Understanding Data Lineage
    260