Kaseya Community

Agent procedure : run a batch file

  • Hi, 

    I'm trying to use agent procedure to run a batch file on a distant computer.

    So i use "execute file" in my procedure (this file is located on the distant server). But everytime i am running that procedure, it tells me success 

    but nothing happenned on the distant computer. My Batch is supposed to write in the eventlog it was executed, so i can see when it works or not.

    When i execute that bat file locally on the server it works but not with the procedure.

    I don't really understant what's wrong. I need some help!

    so here is my procedure :

    <?xml version="1.0" encoding="utf-8" ?>
    - <ScriptExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.kaseya.com/vsa/2008/12/Scripting">
    - <Procedure name="BasculeScript" treePres="3">
    - <Body description="">
    - <Statement description="Execute the specified file - full path to file required." name="ExecuteFile" continueOnFail="false" osType="2008">
      <Parameter xsi:type="StringParameter" name="Path" value="c:\Windows\System32\cmd.exe" />
      <Parameter xsi:type="StringParameter" name="Arguments" value="c:\execscript.bat" />
      <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User" />
      <Parameter xsi:type="BooleanParameter" name="WaitComplete" value="False" />

  • You don't need to execute file, just use 'execute shell command' and point it at the batch file.

  • Thank you for your answer.

    I've already try to lauch my batch. when you edit the procedure i put "c:\myscript.bat".

    It doesn't work. I also tried "run" and "start" comand before the script's path but the result is the same.

  • When troubleshooting i find it best to try and run through live connect as this runs it through kaseya but you get to see the output.

    I imagine the issue is kaseya is running as system and when you run the bat on the computer you are running as the user account. Try use the execute shell command as user.

  • If there is no one logged onto the machine, and the Execute File/Execute Shell Command step is set to "Execute as the logged on user", then it will run the step as Local System.  If the batch file is doing something that needs to be performed as an actual user (i.e. accessing an UNC or mapping a drive, etc.) then you need to either ensure that someone is logged on to the machine and that they have access to resource being referenced in the batch file, or you need to use an Impersonate User or Use Credential step prior to the Execute File/Execute Shell Command step.  As has been said already, you can use the Execute Shell Command instead of the execute file.  Also, when calling a batch file using CMD.EXE in an Execute File step you should really add the /c parameter prior to the name of the batch file.  This will instruct CMD.EXE to execute the command/batch file and then close the CMD.EXE shell upon completion of the command/batch file.  If the machine is an 64bit system, then you may also need to set the step accordingly if you are using 32bit OS shell commands/utilities inside the batch file (see msdn.microsoft.com/.../aa384187(v=vs.85).aspx  for more details). Further, when running CMD.EXE you generally do not need to pass in "C:\Windows\System32\" also because that folder should be in the Windows system PATH environment variable.  I also noticed upon importing your procedure that the Execute File step is set to only run on Windows 2008 systems, but you did not specify the OS of the remote system or whether it is 32bit of 64bit. If you post the specific batch file, and tell me the OS specifics, then I may be able to tell more definitively what is going on.


    Matt Warburton

    Kaseya Professional Services