Windows .bat fails when running from Scheduled tasks; runs fine when running from command line





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am trying to start a virtual machine via a batch file. The .bat file runs fine when I run it from the Windows command line. But when I run it from scheduled tasks, it exits with error code 1.



I am running the command line under the same user which the scheduled task is scheduled to run under. I have checked the permissions on the Scheduled Task, and it appears that I have all access which I need to the task. The "Run As" dialog has the proper password for the user which it is using.



The batch file is very simple:



"C:Program FilesOracleVirtualBoxVBoxHeadless.exe" -startvm "Debian"









share|improve this question

























  • Why are you putting that command in batch file, instead of running it directly?

    – kreemoweet
    Feb 16 '13 at 17:47











  • @kreemoweet: I intend to add more commands later, and don't want to have to set up the scheduled task yet.

    – loneboat
    Feb 17 '13 at 0:17


















0















I am trying to start a virtual machine via a batch file. The .bat file runs fine when I run it from the Windows command line. But when I run it from scheduled tasks, it exits with error code 1.



I am running the command line under the same user which the scheduled task is scheduled to run under. I have checked the permissions on the Scheduled Task, and it appears that I have all access which I need to the task. The "Run As" dialog has the proper password for the user which it is using.



The batch file is very simple:



"C:Program FilesOracleVirtualBoxVBoxHeadless.exe" -startvm "Debian"









share|improve this question

























  • Why are you putting that command in batch file, instead of running it directly?

    – kreemoweet
    Feb 16 '13 at 17:47











  • @kreemoweet: I intend to add more commands later, and don't want to have to set up the scheduled task yet.

    – loneboat
    Feb 17 '13 at 0:17














0












0








0








I am trying to start a virtual machine via a batch file. The .bat file runs fine when I run it from the Windows command line. But when I run it from scheduled tasks, it exits with error code 1.



I am running the command line under the same user which the scheduled task is scheduled to run under. I have checked the permissions on the Scheduled Task, and it appears that I have all access which I need to the task. The "Run As" dialog has the proper password for the user which it is using.



The batch file is very simple:



"C:Program FilesOracleVirtualBoxVBoxHeadless.exe" -startvm "Debian"









share|improve this question
















I am trying to start a virtual machine via a batch file. The .bat file runs fine when I run it from the Windows command line. But when I run it from scheduled tasks, it exits with error code 1.



I am running the command line under the same user which the scheduled task is scheduled to run under. I have checked the permissions on the Scheduled Task, and it appears that I have all access which I need to the task. The "Run As" dialog has the proper password for the user which it is using.



The batch file is very simple:



"C:Program FilesOracleVirtualBoxVBoxHeadless.exe" -startvm "Debian"






windows-xp virtualbox batch-file scheduled-tasks






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 30 '16 at 18:19









Hennes

59.4k793144




59.4k793144










asked Feb 15 '13 at 17:42









loneboatloneboat

2892817




2892817













  • Why are you putting that command in batch file, instead of running it directly?

    – kreemoweet
    Feb 16 '13 at 17:47











  • @kreemoweet: I intend to add more commands later, and don't want to have to set up the scheduled task yet.

    – loneboat
    Feb 17 '13 at 0:17



















  • Why are you putting that command in batch file, instead of running it directly?

    – kreemoweet
    Feb 16 '13 at 17:47











  • @kreemoweet: I intend to add more commands later, and don't want to have to set up the scheduled task yet.

    – loneboat
    Feb 17 '13 at 0:17

















Why are you putting that command in batch file, instead of running it directly?

– kreemoweet
Feb 16 '13 at 17:47





Why are you putting that command in batch file, instead of running it directly?

– kreemoweet
Feb 16 '13 at 17:47













@kreemoweet: I intend to add more commands later, and don't want to have to set up the scheduled task yet.

– loneboat
Feb 17 '13 at 0:17





@kreemoweet: I intend to add more commands later, and don't want to have to set up the scheduled task yet.

– loneboat
Feb 17 '13 at 0:17










4 Answers
4






active

oldest

votes


















0














One thing to make sure is that your scheduled task instance of your user has access to all of your network shares. If your computer is part of a domain that setups network drives at login or you have any folder redirection it could cause problems.



It's important to remember that the scheduled task user runs in a limited instance of your account. No startup scripts are run and no local user cache is created. If your currently logged on user has a file locked, the scheduled task user will be unable to use it.



I know this is a long shot, but without a log of what the virtualbox executable is doing, we can't really do much to help. Most well written programs dump the "full text" error to a log file so you know what actually happened.






share|improve this answer
























  • Thanks for the suggestions - especially the one regarding locked files. That is a good suggestion, and I will investigate that when I'm back at my workstation later today. Regarding network shares, this is all happening locally - no network involved. I appreciate your reply. I was unaware that scheduled tasks were run in a limited environment - I'll also investigate that. Thanks again for your time!

    – loneboat
    Feb 15 '13 at 18:32





















0














I got stuck with the same trouble about 2 months ago, but on Win 7 - however, the solution might work for XP as well. I had a VB script instead of CMD or BAT file that also could not be executed when I placed it to D:TestData. As it turned out, Task Scheduler is very careful about allowed locations for such files.



Long story short, I ended up with the following: I created Scripts folder as C:UsersusernameAppDataLocalScripts - and it worked like charm)



For XP try to create it in e.g. %USERPROFILE% folder (this is C:Documents and Settingsusername by default).



Hope that was helpful.






share|improve this answer































    0














    On "Security options" group, there is an option about how to run the task. You can find this option at the first tab of "Properties" page.





    • Run only when user is logged on - It makes the task visible on your desktop.


    • Run whether user is logged on or not - It makes the task invisible as there is no way to display UI when no user is logged on.


    Would you please try the former option? I actually use that for a very similar situation of yours. By doing this, at least you will have chances to see what is happening there, which must be more informative than "error code 1".



    Not to mention, a user should be logged on there all the time to ensure the task runs but this can be workarounded by login automation and system lock.






    share|improve this answer

































      0














      Problem :
      - Startup physical machine and automatic launch of VMs by sheduled task
      - login later on with my mainaccount (days or weeks later...no matter)
      - start "cmd", typing "vboxmanage list runningvms" does not showup any vms



      My solution :
      1- first open the component service DCOM



      COMPONENTSERVICE



      2- edit the highlighted component as followed :



      Edit the accountsettings for launch



      upon 2- enter the credentials for your account which shall see the Vms
      on the commandline



      3- start task editor (in my case Windows 10) and follow the steps shown up.
      (i enabled the local administrator account and used it for the task.
      the DCOM component is launched by the settings defined in step 2)



      Task sheduler "simple task step 1"



      4- setup the starting parameters



      enter image description here



      Restart machine to bring the DCOM configuration changes on.



      It should now visible with your entered logon account in the DCOM panel
      to show up the "vboxmanage list runningvms".






      share|improve this answer


























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "3"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f552639%2fwindows-bat-fails-when-running-from-scheduled-tasks-runs-fine-when-running-fro%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        One thing to make sure is that your scheduled task instance of your user has access to all of your network shares. If your computer is part of a domain that setups network drives at login or you have any folder redirection it could cause problems.



        It's important to remember that the scheduled task user runs in a limited instance of your account. No startup scripts are run and no local user cache is created. If your currently logged on user has a file locked, the scheduled task user will be unable to use it.



        I know this is a long shot, but without a log of what the virtualbox executable is doing, we can't really do much to help. Most well written programs dump the "full text" error to a log file so you know what actually happened.






        share|improve this answer
























        • Thanks for the suggestions - especially the one regarding locked files. That is a good suggestion, and I will investigate that when I'm back at my workstation later today. Regarding network shares, this is all happening locally - no network involved. I appreciate your reply. I was unaware that scheduled tasks were run in a limited environment - I'll also investigate that. Thanks again for your time!

          – loneboat
          Feb 15 '13 at 18:32


















        0














        One thing to make sure is that your scheduled task instance of your user has access to all of your network shares. If your computer is part of a domain that setups network drives at login or you have any folder redirection it could cause problems.



        It's important to remember that the scheduled task user runs in a limited instance of your account. No startup scripts are run and no local user cache is created. If your currently logged on user has a file locked, the scheduled task user will be unable to use it.



        I know this is a long shot, but without a log of what the virtualbox executable is doing, we can't really do much to help. Most well written programs dump the "full text" error to a log file so you know what actually happened.






        share|improve this answer
























        • Thanks for the suggestions - especially the one regarding locked files. That is a good suggestion, and I will investigate that when I'm back at my workstation later today. Regarding network shares, this is all happening locally - no network involved. I appreciate your reply. I was unaware that scheduled tasks were run in a limited environment - I'll also investigate that. Thanks again for your time!

          – loneboat
          Feb 15 '13 at 18:32
















        0












        0








        0







        One thing to make sure is that your scheduled task instance of your user has access to all of your network shares. If your computer is part of a domain that setups network drives at login or you have any folder redirection it could cause problems.



        It's important to remember that the scheduled task user runs in a limited instance of your account. No startup scripts are run and no local user cache is created. If your currently logged on user has a file locked, the scheduled task user will be unable to use it.



        I know this is a long shot, but without a log of what the virtualbox executable is doing, we can't really do much to help. Most well written programs dump the "full text" error to a log file so you know what actually happened.






        share|improve this answer













        One thing to make sure is that your scheduled task instance of your user has access to all of your network shares. If your computer is part of a domain that setups network drives at login or you have any folder redirection it could cause problems.



        It's important to remember that the scheduled task user runs in a limited instance of your account. No startup scripts are run and no local user cache is created. If your currently logged on user has a file locked, the scheduled task user will be unable to use it.



        I know this is a long shot, but without a log of what the virtualbox executable is doing, we can't really do much to help. Most well written programs dump the "full text" error to a log file so you know what actually happened.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 15 '13 at 18:03









        DoltknuckleDoltknuckle

        5,46542027




        5,46542027













        • Thanks for the suggestions - especially the one regarding locked files. That is a good suggestion, and I will investigate that when I'm back at my workstation later today. Regarding network shares, this is all happening locally - no network involved. I appreciate your reply. I was unaware that scheduled tasks were run in a limited environment - I'll also investigate that. Thanks again for your time!

          – loneboat
          Feb 15 '13 at 18:32





















        • Thanks for the suggestions - especially the one regarding locked files. That is a good suggestion, and I will investigate that when I'm back at my workstation later today. Regarding network shares, this is all happening locally - no network involved. I appreciate your reply. I was unaware that scheduled tasks were run in a limited environment - I'll also investigate that. Thanks again for your time!

          – loneboat
          Feb 15 '13 at 18:32



















        Thanks for the suggestions - especially the one regarding locked files. That is a good suggestion, and I will investigate that when I'm back at my workstation later today. Regarding network shares, this is all happening locally - no network involved. I appreciate your reply. I was unaware that scheduled tasks were run in a limited environment - I'll also investigate that. Thanks again for your time!

        – loneboat
        Feb 15 '13 at 18:32







        Thanks for the suggestions - especially the one regarding locked files. That is a good suggestion, and I will investigate that when I'm back at my workstation later today. Regarding network shares, this is all happening locally - no network involved. I appreciate your reply. I was unaware that scheduled tasks were run in a limited environment - I'll also investigate that. Thanks again for your time!

        – loneboat
        Feb 15 '13 at 18:32















        0














        I got stuck with the same trouble about 2 months ago, but on Win 7 - however, the solution might work for XP as well. I had a VB script instead of CMD or BAT file that also could not be executed when I placed it to D:TestData. As it turned out, Task Scheduler is very careful about allowed locations for such files.



        Long story short, I ended up with the following: I created Scripts folder as C:UsersusernameAppDataLocalScripts - and it worked like charm)



        For XP try to create it in e.g. %USERPROFILE% folder (this is C:Documents and Settingsusername by default).



        Hope that was helpful.






        share|improve this answer




























          0














          I got stuck with the same trouble about 2 months ago, but on Win 7 - however, the solution might work for XP as well. I had a VB script instead of CMD or BAT file that also could not be executed when I placed it to D:TestData. As it turned out, Task Scheduler is very careful about allowed locations for such files.



          Long story short, I ended up with the following: I created Scripts folder as C:UsersusernameAppDataLocalScripts - and it worked like charm)



          For XP try to create it in e.g. %USERPROFILE% folder (this is C:Documents and Settingsusername by default).



          Hope that was helpful.






          share|improve this answer


























            0












            0








            0







            I got stuck with the same trouble about 2 months ago, but on Win 7 - however, the solution might work for XP as well. I had a VB script instead of CMD or BAT file that also could not be executed when I placed it to D:TestData. As it turned out, Task Scheduler is very careful about allowed locations for such files.



            Long story short, I ended up with the following: I created Scripts folder as C:UsersusernameAppDataLocalScripts - and it worked like charm)



            For XP try to create it in e.g. %USERPROFILE% folder (this is C:Documents and Settingsusername by default).



            Hope that was helpful.






            share|improve this answer













            I got stuck with the same trouble about 2 months ago, but on Win 7 - however, the solution might work for XP as well. I had a VB script instead of CMD or BAT file that also could not be executed when I placed it to D:TestData. As it turned out, Task Scheduler is very careful about allowed locations for such files.



            Long story short, I ended up with the following: I created Scripts folder as C:UsersusernameAppDataLocalScripts - and it worked like charm)



            For XP try to create it in e.g. %USERPROFILE% folder (this is C:Documents and Settingsusername by default).



            Hope that was helpful.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 16 '13 at 16:28









            Peter L.Peter L.

            8571714




            8571714























                0














                On "Security options" group, there is an option about how to run the task. You can find this option at the first tab of "Properties" page.





                • Run only when user is logged on - It makes the task visible on your desktop.


                • Run whether user is logged on or not - It makes the task invisible as there is no way to display UI when no user is logged on.


                Would you please try the former option? I actually use that for a very similar situation of yours. By doing this, at least you will have chances to see what is happening there, which must be more informative than "error code 1".



                Not to mention, a user should be logged on there all the time to ensure the task runs but this can be workarounded by login automation and system lock.






                share|improve this answer






























                  0














                  On "Security options" group, there is an option about how to run the task. You can find this option at the first tab of "Properties" page.





                  • Run only when user is logged on - It makes the task visible on your desktop.


                  • Run whether user is logged on or not - It makes the task invisible as there is no way to display UI when no user is logged on.


                  Would you please try the former option? I actually use that for a very similar situation of yours. By doing this, at least you will have chances to see what is happening there, which must be more informative than "error code 1".



                  Not to mention, a user should be logged on there all the time to ensure the task runs but this can be workarounded by login automation and system lock.






                  share|improve this answer




























                    0












                    0








                    0







                    On "Security options" group, there is an option about how to run the task. You can find this option at the first tab of "Properties" page.





                    • Run only when user is logged on - It makes the task visible on your desktop.


                    • Run whether user is logged on or not - It makes the task invisible as there is no way to display UI when no user is logged on.


                    Would you please try the former option? I actually use that for a very similar situation of yours. By doing this, at least you will have chances to see what is happening there, which must be more informative than "error code 1".



                    Not to mention, a user should be logged on there all the time to ensure the task runs but this can be workarounded by login automation and system lock.






                    share|improve this answer















                    On "Security options" group, there is an option about how to run the task. You can find this option at the first tab of "Properties" page.





                    • Run only when user is logged on - It makes the task visible on your desktop.


                    • Run whether user is logged on or not - It makes the task invisible as there is no way to display UI when no user is logged on.


                    Would you please try the former option? I actually use that for a very similar situation of yours. By doing this, at least you will have chances to see what is happening there, which must be more informative than "error code 1".



                    Not to mention, a user should be logged on there all the time to ensure the task runs but this can be workarounded by login automation and system lock.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 20 '17 at 10:17









                    Community

                    1




                    1










                    answered Mar 11 '14 at 21:43









                    Scott RheeScott Rhee

                    1,888911




                    1,888911























                        0














                        Problem :
                        - Startup physical machine and automatic launch of VMs by sheduled task
                        - login later on with my mainaccount (days or weeks later...no matter)
                        - start "cmd", typing "vboxmanage list runningvms" does not showup any vms



                        My solution :
                        1- first open the component service DCOM



                        COMPONENTSERVICE



                        2- edit the highlighted component as followed :



                        Edit the accountsettings for launch



                        upon 2- enter the credentials for your account which shall see the Vms
                        on the commandline



                        3- start task editor (in my case Windows 10) and follow the steps shown up.
                        (i enabled the local administrator account and used it for the task.
                        the DCOM component is launched by the settings defined in step 2)



                        Task sheduler "simple task step 1"



                        4- setup the starting parameters



                        enter image description here



                        Restart machine to bring the DCOM configuration changes on.



                        It should now visible with your entered logon account in the DCOM panel
                        to show up the "vboxmanage list runningvms".






                        share|improve this answer






























                          0














                          Problem :
                          - Startup physical machine and automatic launch of VMs by sheduled task
                          - login later on with my mainaccount (days or weeks later...no matter)
                          - start "cmd", typing "vboxmanage list runningvms" does not showup any vms



                          My solution :
                          1- first open the component service DCOM



                          COMPONENTSERVICE



                          2- edit the highlighted component as followed :



                          Edit the accountsettings for launch



                          upon 2- enter the credentials for your account which shall see the Vms
                          on the commandline



                          3- start task editor (in my case Windows 10) and follow the steps shown up.
                          (i enabled the local administrator account and used it for the task.
                          the DCOM component is launched by the settings defined in step 2)



                          Task sheduler "simple task step 1"



                          4- setup the starting parameters



                          enter image description here



                          Restart machine to bring the DCOM configuration changes on.



                          It should now visible with your entered logon account in the DCOM panel
                          to show up the "vboxmanage list runningvms".






                          share|improve this answer




























                            0












                            0








                            0







                            Problem :
                            - Startup physical machine and automatic launch of VMs by sheduled task
                            - login later on with my mainaccount (days or weeks later...no matter)
                            - start "cmd", typing "vboxmanage list runningvms" does not showup any vms



                            My solution :
                            1- first open the component service DCOM



                            COMPONENTSERVICE



                            2- edit the highlighted component as followed :



                            Edit the accountsettings for launch



                            upon 2- enter the credentials for your account which shall see the Vms
                            on the commandline



                            3- start task editor (in my case Windows 10) and follow the steps shown up.
                            (i enabled the local administrator account and used it for the task.
                            the DCOM component is launched by the settings defined in step 2)



                            Task sheduler "simple task step 1"



                            4- setup the starting parameters



                            enter image description here



                            Restart machine to bring the DCOM configuration changes on.



                            It should now visible with your entered logon account in the DCOM panel
                            to show up the "vboxmanage list runningvms".






                            share|improve this answer















                            Problem :
                            - Startup physical machine and automatic launch of VMs by sheduled task
                            - login later on with my mainaccount (days or weeks later...no matter)
                            - start "cmd", typing "vboxmanage list runningvms" does not showup any vms



                            My solution :
                            1- first open the component service DCOM



                            COMPONENTSERVICE



                            2- edit the highlighted component as followed :



                            Edit the accountsettings for launch



                            upon 2- enter the credentials for your account which shall see the Vms
                            on the commandline



                            3- start task editor (in my case Windows 10) and follow the steps shown up.
                            (i enabled the local administrator account and used it for the task.
                            the DCOM component is launched by the settings defined in step 2)



                            Task sheduler "simple task step 1"



                            4- setup the starting parameters



                            enter image description here



                            Restart machine to bring the DCOM configuration changes on.



                            It should now visible with your entered logon account in the DCOM panel
                            to show up the "vboxmanage list runningvms".







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jun 17 '16 at 1:43









                            fixer1234

                            19.4k145082




                            19.4k145082










                            answered Jun 17 '16 at 1:13









                            MichaelMichael

                            11




                            11






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Super User!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f552639%2fwindows-bat-fails-when-running-from-scheduled-tasks-runs-fine-when-running-fro%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Probability when a professor distributes a quiz and homework assignment to a class of n students.

                                Aardman Animations

                                Are they similar matrix