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. execute .bat file

execute .bat file

Scheduled Pinned Locked Moved C / C++ / MFC
c++cssquestion
19 Posts 5 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.
  • M Madan Chauhan

    I am receiving the returning value in an integer. It is executing but giving me the error 32 "process can not access file because it is being used by another process."

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #6

    Madan Chauhan wrote:

    I am receiving the returning value in an integer

    show out how you're doing this man ! show your code !!!

    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

    M 1 Reply Last reply
    0
    • M Madan Chauhan

      ERROR Return = 32 ".....file used by another precess"

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #7

      Madan Chauhan wrote:

      file used by another precess

      The error message is descriptive enough for me.

      Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

      T 1 Reply Last reply
      0
      • R Rajesh R Subramanian

        Madan Chauhan wrote:

        file used by another precess

        The error message is descriptive enough for me.

        Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #8

        Rajesh R Subramanian wrote:

        The error message is descriptive enough for me

        so you read in my mind ? damned MVP :rolleyes:

        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        1 Reply Last reply
        0
        • T toxcct

          Madan Chauhan wrote:

          I am receiving the returning value in an integer

          show out how you're doing this man ! show your code !!!

          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          M Offline
          M Offline
          Madan Chauhan
          wrote on last edited by
          #9

          CString csFilePath = _T("D:\\myFolder\\mybat.bat"); //contains the path of my bat file. int iReturn = (int)ShellExecute(NULL,_T("Open"),csFilePath,NULL,NULL,SW_SHOWNORMAL); In MSDN it is written that if iReturn is greater than 32 then shellexecute() is successfull and if it is less than 32 then unsuccessfull. and I have written the error message already to you.

          T 1 Reply Last reply
          0
          • M Madan Chauhan

            CString csFilePath = _T("D:\\myFolder\\mybat.bat"); //contains the path of my bat file. int iReturn = (int)ShellExecute(NULL,_T("Open"),csFilePath,NULL,NULL,SW_SHOWNORMAL); In MSDN it is written that if iReturn is greater than 32 then shellexecute() is successfull and if it is less than 32 then unsuccessfull. and I have written the error message already to you.

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #10

            Madan Chauhan wrote:

            I have written the error message already to you

            and so, the message doesn't talk to you ? What it means is perfectly clear to me. maybe you should read it again ;) You could use Process Explorer[^] and close the handles of the applications using this file...

            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            M V 3 Replies Last reply
            0
            • T toxcct

              Madan Chauhan wrote:

              I have written the error message already to you

              and so, the message doesn't talk to you ? What it means is perfectly clear to me. maybe you should read it again ;) You could use Process Explorer[^] and close the handles of the applications using this file...

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              M Offline
              M Offline
              Madan Chauhan
              wrote on last edited by
              #11

              Anyway Dear sir, may be I am wrong or doing some fault in code. My problem is only that how can I execute a batch file in vc++? I am not concerning only in Shellexecute(), if there is any other way, please guide me.

              T 1 Reply Last reply
              0
              • M Madan Chauhan

                Anyway Dear sir, may be I am wrong or doing some fault in code. My problem is only that how can I execute a batch file in vc++? I am not concerning only in Shellexecute(), if there is any other way, please guide me.

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #12

                Madan Chauhan wrote:

                My problem is only that how can I execute a batch file in vc++?

                exactly the way you do ! if you had ask me to launch a .bat from my exe, I would have written the same code for sure !

                Madan Chauhan wrote:

                I am not concerning only in Shellexecute(), if there is any other way, please guide me.

                yes, there are, but i find them not as much elegant than ShellExecute(), and this cannot be the reason. The reason is (as the error message said), that some file is being used by another process (another application. use ProcessExplorer (very lightweight) to find which is the culprit...

                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                V R 2 Replies Last reply
                0
                • T toxcct

                  Madan Chauhan wrote:

                  I have written the error message already to you

                  and so, the message doesn't talk to you ? What it means is perfectly clear to me. maybe you should read it again ;) You could use Process Explorer[^] and close the handles of the applications using this file...

                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                  M Offline
                  M Offline
                  Madan Chauhan
                  wrote on last edited by
                  #13

                  Thanks Sir, My net got slow thats y I could not read your latest reply. Now I am doing it well after closing the handle. Thank you very much.

                  1 Reply Last reply
                  0
                  • M Madan Chauhan

                    Hi all, How can I execute .bat file using vc++. I am trying to execute it by using ShellExecute() function but it is not executing. ShellExecute(NULL,_T("Open"),"_T("D:\\myBat.bat"),NULL,NULL,SW_HIDE); It is returning less than 32, but if it is successfully executed it should return greater than 32. Please provide me the solution. Thanks.

                    H Offline
                    H Offline
                    Hamid Taebi
                    wrote on last edited by
                    #14

                    You can also use of CreateProcess.

                    1 Reply Last reply
                    0
                    • T toxcct

                      Madan Chauhan wrote:

                      I have written the error message already to you

                      and so, the message doesn't talk to you ? What it means is perfectly clear to me. maybe you should read it again ;) You could use Process Explorer[^] and close the handles of the applications using this file...

                      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                      V Offline
                      V Offline
                      vcprog
                      wrote on last edited by
                      #15

                      Hi toxcct I have a error in my code.And Mr. Rajesh R Subramanian tell me that i talk to you about that problem.My problem is that .exe file is not copy and .txt file is copy.I am useing get last error then i have found Error no. 32.

                      The process cannot access the file because it is being used by another process.

                      I am useing this code

                      CString cs = _T("C:\\Backup\\");
                      cs += PathSkipRoot(strFileName);
                      //CopyFile(strFileName, cs, TRUE);
                      if ( !CopyFile(strFileName, cs, TRUE))
                      {
                      DWORD dwError = GetLastError();
                      CString szMsg;
                      szMsg.Format(_T("Error number %d"), dwError);
                      AfxMessageBox(szMsg);
                      }
                      else
                      {
                      AfxMessageBox(_T("Success"));
                      }

                      Sir plz help me

                      1 Reply Last reply
                      0
                      • T toxcct

                        Madan Chauhan wrote:

                        My problem is only that how can I execute a batch file in vc++?

                        exactly the way you do ! if you had ask me to launch a .bat from my exe, I would have written the same code for sure !

                        Madan Chauhan wrote:

                        I am not concerning only in Shellexecute(), if there is any other way, please guide me.

                        yes, there are, but i find them not as much elegant than ShellExecute(), and this cannot be the reason. The reason is (as the error message said), that some file is being used by another process (another application. use ProcessExplorer (very lightweight) to find which is the culprit...

                        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                        V Offline
                        V Offline
                        vcprog
                        wrote on last edited by
                        #16

                        Hello toxcct Sir I need your help.Plz help me

                        1 Reply Last reply
                        0
                        • T toxcct

                          Madan Chauhan wrote:

                          My problem is only that how can I execute a batch file in vc++?

                          exactly the way you do ! if you had ask me to launch a .bat from my exe, I would have written the same code for sure !

                          Madan Chauhan wrote:

                          I am not concerning only in Shellexecute(), if there is any other way, please guide me.

                          yes, there are, but i find them not as much elegant than ShellExecute(), and this cannot be the reason. The reason is (as the error message said), that some file is being used by another process (another application. use ProcessExplorer (very lightweight) to find which is the culprit...

                          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                          R Offline
                          R Offline
                          Rajesh R Subramanian
                          wrote on last edited by
                          #17

                          FYI[^], tox.

                          Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                          T 1 Reply Last reply
                          0
                          • R Rajesh R Subramanian

                            FYI[^], tox.

                            Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                            T Offline
                            T Offline
                            toxcct
                            wrote on last edited by
                            #18

                            i'm aware of this. that's why I didn't answer his today's post to me... the OP doesn't take in account the answers he got, so i stopped wasting my time and energy with him :cool:

                            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                            V 1 Reply Last reply
                            0
                            • T toxcct

                              i'm aware of this. that's why I didn't answer his today's post to me... the OP doesn't take in account the answers he got, so i stopped wasting my time and energy with him :cool:

                              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                              V Offline
                              V Offline
                              vcprog
                              wrote on last edited by
                              #19

                              Sorry sir ok as you wish.But i always waiting for responce.. Thx's in advance

                              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