8 Replies Latest reply on Apr 8, 2013 4:00 PM by jbaits

    Creating custom pkg with sleep.exe to get batch file to run

    pmaldonato

      Hello Thwack!

       

      Anyone familiar with this process? Overall im looking to have the patch manager push out a batch file that will remedy an issue. The issue has affected several hundred PCs im interested in trying to use the PM to distribute and execute the batch file which is why I ask.

       

       

      This is the XML view. I put in the bat file before and after the sleep.exe for a second opportunity to run....

       

       

      <?xml version="1.0" encoding="UTF-8"?>

      <packageboot version="2.0.0.0" id="dd53b76e-babc-410f-8901-426d0989f5f1">

        <instructions>

          <preexecution>

            <programs>

              <program failureaction="continue" enabled="true" name="HostIP.bat" type="exe" typeaction="runandwait" pathtype="simplepath" path="\\%networkdrive%\C$\Users\%username%\Desktop\Test Bats" successcode="0">/qn /norestart</program>

            </programs>

          </preexecution>

          <execution>

            <programs>

              <program failureaction="continue" enabled="true" name="sleep.exe" type="exe" typeaction="runandwait" successcode="0"></program>

            </programs>

          </execution>

          <postexecution>

            <programs>

              <program failureaction="continue" enabled="true" name="HostIP.bat" type="exe" typeaction="runandwait" successcode="0">HostIP.bat</program>

            </programs>

          </postexecution>

        </instructions>

      </packageboot>

       

      Any ideas?

        • Re: Creating custom pkg with sleep.exe to get batch file to run
          jbaits

          You can't call a batch file directly as you're trying. Instead of name="HostIP.bat" you need to call name="cmd.exe" with parameters that run your bat file. Since a normal command prompt cannot run a batch file over a network you will have to include your bat with the package and have it run from %modulepath%. The xml would look similar to this

           

          failureaction="stop"enabled="true"name="cmd.exe"type="exe"typeaction="runandwait"pathtype="simplepath"path="%windir%\system32"successcode="0">/c %MODULEPATH%\HostIP.bat</program>


          That example is taken directly from one of the Solarwinds provided Java packages with the exception of the bat file name if you want to look at it some more.

            • Re: Creating custom pkg with sleep.exe to get batch file to run
              pmaldonato

              I'll look over this over the next couple of days. What does that %modulepath% turn into? Is it the ' path="%windir%\system32 ' as in the above xml line?

                • Re: Creating custom pkg with sleep.exe to get batch file to run
                  jbaits

                  %MODULEPATH% is a packageboot specific variable that translates to the location where packageboot is running, typically "C:\Windows\SoftwareDistribution\Download\Install" during patch installation. Any files you include with the package will be located in %MODULEPATH%.

                    • Re: Creating custom pkg with sleep.exe to get batch file to run
                      pmaldonato

                      Still a bit lost on this one. If im going to call a bat in cmd, I must be in the directory of the said bat for it to start. How is this accomplished with the packageboot?  Shouldnt the underlined xml code cover that?

                       

                       

                      <program failureaction="stop" enabled="true" name="cmd.exe" type="exe" typeaction="runandwait" pathtype="simplepath" path="%windir%\system32">%MODULEPATH%\HostIP.bat</program>

                       

                      This is the current complete XML:

                       

                       

                      <?xml version="1.0" encoding="UTF-8"?>

                      <packageboot version="2.0.0.0" id="dd53b76e-babc-410f-8901-426d0989f5f1">

                        <instructions>

                          <preexecution>

                              <programs>

                                  <program failureaction="continue" enabled="true" name="cmd.exe" type="exe" typeaction="runandwait" pathtype="simplepath" path="%windir%\system32" successcode="0">/c %MODULEPATH%\HostIP.bat</program>

                              </programs>

                          </preexecution>

                          <execution>

                            <programs>

                              <program failureaction="continue" enabled="true" name="packageboot.exe" type="exe" typeaction="runandwait" successcode="0"></program>

                            </programs>

                          </execution>

                          <postexecution>

                            <programs>

                             <program failureaction="stop" enabled="true" name="cmd.exe" type="exe" typeaction="runandwait" pathtype="simplepath" path="%windir%\system32">%MODULEPATH%\HostIP.bat</program>

                            </programs>

                          </postexecution>

                        </instructions>

                      </packageboot>

                        • Re: Creating custom pkg with sleep.exe to get batch file to run
                          jbaits

                          The path specifies where the executable is located. In this case the executable is cmd.exe and is located in %windir%\system32. You run the bat by calling /c %MODULEPATH%\HostIP.bat. /c tells cmd.exe to exit once the command is complete. %MODULEPATH%\HostIP.bat expands to C:\Windows\SoftwareDistribution\Download\Install\HostIP.bat which should run your batch file since it is being called using the full path to it. I'm not sure why you're trying to run the bat twice. This is redundant and does not help you. Calling it once before sleep.exe using failureaction="stop" will make sure it is run and the package errors if it does not exit successfully. If your bat does not run the only thing I can think that may still be wrong is that you haven't included your bat as part of the package.

                           

                          I've modified your XML to make it work properly. This will run your batch file as long as it was included as an additional file with the package. It should return failed if the batch fails to execute properly and success if it runs all the way through.

                           

                          <?xml version="1.0" encoding="UTF-8"?>

                           

                          <packageboot version="2.0.0.0" id="dd53b76e-babc-410f-8901-426d0989f5f1">

                           

                            <instructions>

                           

                              <preexecution>

                           

                                  <programs>

                           

                                      <program failureaction="stop" enabled="true" name="cmd.exe" type="exe" typeaction="runandwait" pathtype="simplepath" path="%windir%\system32" successcode="0">/c %MODULEPATH%\HostIP.bat</program>

                           

                                  </programs>

                           

                              </preexecution>

                           

                              <execution>

                           

                                <programs>

                           

                                  <program failureaction="continue" enabled="true" name="packageboot.exe" type="exe" typeaction="runandwait" successcode="0"></program>

                           

                                </programs>

                           

                              </execution>

                           

                              <postexecution>

                           

                                <programs>

                           

                                </programs>

                           

                              </postexecution>

                           

                            </instructions>

                           

                          </packageboot>

                            • Re: Creating custom pkg with sleep.exe to get batch file to run
                              pmaldonato

                              Still no luck here. In the mean time I was able to get the results I was looking for via group policy. -- Getting back to this topic, maybe I should set up a goto meeting and look into this? You are support for Solarwinds correct?

                                • Re: Creating custom pkg with sleep.exe to get batch file to run
                                  Andrew M

                                  How did packageboot.exe get in your execution list? At the beginning of this thread you said you were using sleep.exe, but I don't see that in you XML anymore. Packageboot.exe is the executable that processes the xml file -- you shouldn't be calling it from within the configuration. I'm not sure what that will do, but probably nothing good.

                                   

                                  Try this instead:

                                  <?xml version="1.0" encoding="UTF-8"?>
                                  <packageboot version="2.0.0.0" id="dd53b76e-babc-410f-8901-426d0989f5f1">
                                    <instructions>
                                      <preexecution>
                                        <programs>
                                          <program failureaction="stop" enabled="true" name="cmd.exe" type="exe" typeaction="runandwait" pathtype="simplepath" path="%WinDir%\system32\" successcode="0">/c %ModulePath%\HostIP.bat</program>
                                        </programs>
                                      </preexecution>
                                      <execution>
                                        <programs>
                                          <program failureaction="continue" enabled="true" name="Sleep.exe" type="exe" typeaction="runandwait" successcode="0">1 /quiet</program>
                                        </programs>
                                      </execution>
                                    </instructions>
                                  </packageboot>
                                  
                                  
                                  

                                   

                                  Note that you must include the batch file and sleep.exe as additional files in your package. You also need the /quiet switch to prevent sleep.exe from displaying a dialog box that will stop execution. 1 is the number of seconds to sleep, you can use any value you want.

                                   

                                  For the record, neither jbaits nor I are Solarwinds employees. If you need a screen sharing session, you should open a ticket through the support portal