Kaseya Community

Running a VBScript from an Agent Procedure within Kaseya

  • I have a neat little VBScript that I want to push out across all PCs in my domain through an Agent Procedure.

    I see an option to run a VBScript within Agent Procedures:

     

    However, I am not sure how or where this file is going to run.  Do I copy it to the VSASharedFiles folder on the server and then just put "VSASharedFiles\script.vbs" in the full path field?  Incidentally, I have tried that and it doesn't work.  Do I need to somehow push it out to every machine first and then run it locally?

    I could do this so easy through a GPO, but I'm really trying to start using Kaseya for as much deployment as I can :-).

    Can someone please tell me the best way that I can use an Agent Procedure to run this .vbs file on all of my machines?

    Thank you kindly!

  • Yes you need to use write file first to write the file to the machines then use the run vbs from the location you copied it too

  • So under your Agent Procedures you want to use the Manage File option to upload your Vbscript to your Kaseya server, then in your agent procedure you want to use the write file step to write the vbscript to the kworking folder and then you execute the Vbscript from the machine.

  • Thank you for your response!  Is there an environment variable in Kaseya for the working directory that I can use?  Typically most of the machines will have the "c:\kworking" directory, but there are some out there that have different folders names.

    I'd like to be able to just signify in the agent procedure that I want the file to write to and run the script from the "Kaseya Working Directory" regardless of what the folder name is on the local machine.

    Also, could you give an example of the entire string that I would put in the Agent Procedure?  For example, if my vbscript was called "script.vbs", what exactly would I type in the "Enter the full path and filename of the destination file" field of the agent procedure?

    Thanks again!!!

  • dgerald69

    Thank you for your response!  Is there an environment variable in Kaseya for the working directory that I can use?  Typically most of the machines will have the "c:\kworking" directory, but there are some out there that have different folders names.

    I'd like to be able to just signify in the agent procedure that I want the file to write to and run the script from the "Kaseya Working Directory" regardless of what the folder name is on the local machine.

    Also, could you give an example of the entire string that I would put in the Agent Procedure?  For example, if my vbscript was called "script.vbs", what exactly would I type in the "Enter the full path and filename of the destination file" field of the agent procedure?

    Thanks again!!!

    import this and change it

    <?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="Citrix Receiver" treePres="3" id="466359094" folderId="31393972254181531721751791">
    <Body description="">
    <Statement description="Create a named procedure variable and assign a value retrieved from the managed machine by the agent." name="GetVariable" continueOnFail="false">
    <Parameter xsi:type="EnumParameter" name="VariableType" value="AgentTempDirectory" />
    <Parameter xsi:type="StringParameter" name="SourceContent" value="" />
    <Parameter xsi:type="StringParameter" name="VariableName" value="agentdir" />
    </Statement>
    <Statement description="Write the selected file to the machine at the path specified - full path required." name="WriteFile" continueOnFail="false">
    <Parameter xsi:type="StringParameter" name="Path" value="#Agentdir#\CitrixReceiver.vbs" />
    <Parameter xsi:type="StringParameter" name="ManagedFile" value="VSASharedFiles\Clients\OCG\CitrixReceiver.vbs" />
    <Parameter xsi:type="BooleanParameter" name="DeleteAfter" value="False" />
    </Statement>
    <Statement description="Executes a Windows VBScript" name="Execute VBScript" continueOnFail="false">
    <Parameter xsi:type="StringParameter" name="Parameter1" value="#Agentdir#\CitrixReceiver.vbs" />
    <Parameter xsi:type="StringParameter" name="Parameter2" value="" />
    <Parameter xsi:type="StringParameter" name="Parameter3" value="True" />
    </Statement>
    </Body>
    </Procedure>
    </ScriptExport>

  • Thank you very much!  I will give this a shot.

  • This does everything except for execute the .vbs file.  It copied to the kworking directory just beautifully, but it doesn't appear to run.  To make sure there is nothing wrong with the .vbs file, I launched it from the kwroking directory manually and it ran just fine.

  • Try unticking the Executes a Windows VBScript"

    Your issue is probably with assumptions made in the VBS

    When kaseya executes the VBS there is no "Start in location"

    When you type it in manually there is a start in location

  • I do not see where I can untick "Executes a Windows VBScript."  I can only click the down arrow next to it and choose another Step Type.

    Is there some other Step Type I can choose, or can I modify the .vbs file to start in a location?  I don't understand why the script isnt just starting in the directory it resides.

    Thanks again for all your help so far!

  • I changed the type from "Execute VBScript" to "Execute Shell Command", making sure to select "Run as Logged in User" and the script executed.

  • That's great to here

  • I was only half-correct I discovered.  The procedure runs just fine in Windows 7 when I choose "Execute Shell Command", but NOT in XP.  

    The procedure will write the file, but will not launch it.  Are there any other ideas that would help me be able to have this VBScript launch through an agent procedure?

  • I know this is old, but I use cscript to execute the VBScript the same way you would on a desktop through CMD. Here is what I use:

    Execute Shell Command (as System): cscript "c:\ktemp\scriptname.vbs" >> c:\ktemp\scriptname.txt