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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Running batch script in MFC

Running batch script in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++securitytoolstutorial
4 Posts 4 Posters 0 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.
  • V Offline
    V Offline
    Vikas K
    wrote on last edited by
    #1

    Hi, I have a tricky issue here: A MFC dialog based App calls a Batch script. This batch script again calls a SSH tool to login to a remote PC. This is to enable FTP service on WinNT remote PC. This is done multiple times in my MFC app. SSH login take approximately 30 seconds and somehow I can not make the control waut there until the SSL login goes thru. I have used the following code to run the Sample BAT file: -TestFTP.bat- ssh.exe -pw @ net start ftp exit In MFC I use WaitForSingleObject to wait for completion of TestFTP.bat: SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "TestFTP.bat"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE); However, WaitForSingleObject returns immediately and Not sure whats wrong here. How to wait till the batch completes? Any help would be great! Thanks Vikas

    CPalliniC R D 3 Replies Last reply
    0
    • V Vikas K

      Hi, I have a tricky issue here: A MFC dialog based App calls a Batch script. This batch script again calls a SSH tool to login to a remote PC. This is to enable FTP service on WinNT remote PC. This is done multiple times in my MFC app. SSH login take approximately 30 seconds and somehow I can not make the control waut there until the SSL login goes thru. I have used the following code to run the Sample BAT file: -TestFTP.bat- ssh.exe -pw @ net start ftp exit In MFC I use WaitForSingleObject to wait for completion of TestFTP.bat: SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "TestFTP.bat"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE); However, WaitForSingleObject returns immediately and Not sure whats wrong here. How to wait till the batch completes? Any help would be great! Thanks Vikas

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Do you know WaitForSingleObject [^] function returns a value? Are you aware that you should check that value? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • V Vikas K

        Hi, I have a tricky issue here: A MFC dialog based App calls a Batch script. This batch script again calls a SSH tool to login to a remote PC. This is to enable FTP service on WinNT remote PC. This is done multiple times in my MFC app. SSH login take approximately 30 seconds and somehow I can not make the control waut there until the SSL login goes thru. I have used the following code to run the Sample BAT file: -TestFTP.bat- ssh.exe -pw @ net start ftp exit In MFC I use WaitForSingleObject to wait for completion of TestFTP.bat: SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "TestFTP.bat"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE); However, WaitForSingleObject returns immediately and Not sure whats wrong here. How to wait till the batch completes? Any help would be great! Thanks Vikas

        R Offline
        R Offline
        Rajkumar R
        wrote on last edited by
        #3

        May be it seems to you, while debugging it might completes. Try this,

        -TestFTP.bat-
        ssh.exe -pw @
        net start ftp
        pause // batch file execution waits here until user press any key.

        and check whether WaitForSingleObject returns immediately. And also, check your batch file executes correctly, ShExecInfo.nShow = SW_SHOW; // you can change it later. ssh.exe -pw @ // if ssh is not installed it returns error. similarly.

        1 Reply Last reply
        0
        • V Vikas K

          Hi, I have a tricky issue here: A MFC dialog based App calls a Batch script. This batch script again calls a SSH tool to login to a remote PC. This is to enable FTP service on WinNT remote PC. This is done multiple times in my MFC app. SSH login take approximately 30 seconds and somehow I can not make the control waut there until the SSL login goes thru. I have used the following code to run the Sample BAT file: -TestFTP.bat- ssh.exe -pw @ net start ftp exit In MFC I use WaitForSingleObject to wait for completion of TestFTP.bat: SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "TestFTP.bat"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE); However, WaitForSingleObject returns immediately and Not sure whats wrong here. How to wait till the batch completes? Any help would be great! Thanks Vikas

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          At one point in time, batch files were processed one line at a time, with an open and close each time. So technically, the batch file did complete, but there was no distinction between the first line completing vs. the whole thing being complete. One other thing to try is CreateProcess() instead of ShellExecuteEx().

          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          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