Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. run bat file using ShellExecute

run bat file using ShellExecute

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manju 3
    wrote on last edited by
    #1

    Hi all, How can i run the bat file using SghellExecute.I am trying with the below code. ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/C Test.bat"),0,SW_SHOW); Note : Test.bat file path is "C:\Test.bat" I am unable to run the bat file.Am i doing anything wrong..?? But when i manually click on Test.bat with the mouse,The bat file executes fine. Thanks in Advance Manju

    C P 2 Replies Last reply
    0
    • M manju 3

      Hi all, How can i run the bat file using SghellExecute.I am trying with the below code. ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/C Test.bat"),0,SW_SHOW); Note : Test.bat file path is "C:\Test.bat" I am unable to run the bat file.Am i doing anything wrong..?? But when i manually click on Test.bat with the mouse,The bat file executes fine. Thanks in Advance Manju

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      Try the following.

      ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/C C:\\Test.bat"),0,SW_SHOW);

      I suspect that when cmd.exe is run, it is unable to find the file Test.bat. :)

      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

      1 Reply Last reply
      0
      • M manju 3

        Hi all, How can i run the bat file using SghellExecute.I am trying with the below code. ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/C Test.bat"),0,SW_SHOW); Note : Test.bat file path is "C:\Test.bat" I am unable to run the bat file.Am i doing anything wrong..?? But when i manually click on Test.bat with the mouse,The bat file executes fine. Thanks in Advance Manju

        P Offline
        P Offline
        pasztorpisti
        wrote on last edited by
        #3

        Instead of

        ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/C Test.bat"),0,SW_SHOW);

        use either this:

        ShellExecute(NULL, _T("open"), _T("cmd.exe"), _T("/C C:\\Test.bat"), NULL, SW_SHOW);

        or this:

        ShellExecute(NULL, _T("open"), _T("cmd.exe"), _T("/C Test.bat"), _T("C:\\"), SW_SHOW);

        Note that the two solutions are not equivalent. In the second solution the current directory of your batch file will be C:\ while in the first case cmd.exe will inherit the current directory of the program from which you call ShellExecute().

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups