Kaseya Community

VB Script will not run via Kaseya

  • I have a 2 line script. The first line copies the file from the Kserver to c:\temp, and this works.

    The second line is and "execute shell command" and the command is:

    cscript c:\temp\scriptname.vbs

    But while I get a success on the script, nothing happens.

    I can then cut the exact line right out of the kaseya interface and paste it into a command window and it works fine. So I know it isn't a typo in the command line.

    What is up with this?

    -Jim

    Legacy Forum Name: VB Script will not run via Kaseya,
    Legacy Posted By Username: jtpryan
  • Could you please paste the content of the script to identify the problem.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: jay.paul
  • jay.paul
    Could you please paste the content of the script to identify the problem.


    And please use [code] tag when doing so.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: thirteentwenty
  • Agreed with above, but if you're using that vbs to work with something like Exchange, I'd bet that the issue can lie with permissions. Try using an Impersonate User step before executing the vbs, entering a credential that has appropriate permissions, if that was the case. Most often with this type of issue where the vbs doesn't execute via kaseya but works locally, whether with exchange or something else, is quite possibly permission related.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: josh.tipping
  • Since my colleague Jim is too busy.
    The script is very simple:
    Step 1: upload .vbs to c:\temp\somefile.vbs
    Step 2: execute command wscript c:\temp\somefile.vbs as user

    The agent credentials are those of a Domain Admin. My understanding is that he's also tried "as system". I don't know if he tried "use credentials" at any point, but the script doesn't reflect it at this point.

    The vbs script simply detects the default printer, and if it is "X", then switch it to "Y". Running the script manually on the system causes the change to take place. Running it via Kaseya causes no change.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: Lmhansen
  • Lars, thank you.
    
    Actually, I just tried this with a simple .bat file that states dir > test.txt
    
    The Kaseya script is 2 lines, this is the xml:
    
    <?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="Test" treePres="3">
    - <Body>
    - <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="c:\temp\test.bat" /> 
      <Parameter xsi:type="StringParameter" name="ManagedFile" value="VSASharedFiles\Client Specific\SGA\test.bat" /> 
      </Statement>
    - <Statement description="Execute the given command as if it were typed in at a command prompt." name="ExecuteShellCommand" continueOnFail="false">
      <Parameter xsi:type="StringParameter" name="Command" value="c:\temp\test.bat" /> 
      <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User" /> 
      <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" /> 
      </Statement>
      </Body>
      </Procedure>
      </ScriptExport>
    
    
    So basically all I do is copy test.bat to the c:\temp directory and then try and execute it.
    
    The test.bat file shows up in the temp directory, but test.txt never shows  up so it doesn't run.
    
    Bottom line, the execute file from command shell is not working.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: jtpryan


    [edited by: Brendan Cosgrove at 5:50 PM (GMT -8) on 12-20-2010] .
  • jtpryan
    Lars, thank you. Actually, I just tried this with a simple .bat file that states dir > test.txt The Kaseya script is 2 lines, this is the xml: <?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="Test" treePres="3"> - <Body> - <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="c:\temp\test.bat" /> <Parameter xsi:type="StringParameter" name="ManagedFile" value="VSASharedFiles\Client Specific\SGA\test.bat" /> </Statement> - <Statement description="Execute the given command as if it were typed in at a command prompt." name="ExecuteShellCommand" continueOnFail="false"> <Parameter xsi:type="StringParameter" name="Command" value="c:\temp\test.bat" /> <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User" /> <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" /> </Statement> </Body> </Procedure> </ScriptExport> So basically all I do is copy test.bat to the c:\temp directory and then try and execute it. The test.bat file shows up in the temp directory, but test.txt never shows up so it doesn't run. Bottom line, the execute file from command shell is not working.

    Thanks for wrapping that in code tags, t'was much fun to read... anyways... If your batch file constists of only
    dir > test.txt
    
    it won't work. and Execute Shell Command works fine... it's your batch file thats screwed up... And I'm willing to bet your VBS file is too... can you post it so we can see whats going on with it? And now the explination... The below will work (for anyone else messing with this one edit the second line to match your #vAgentConfiguration.agentTempDir# location. I've writen it for the original poster as he said that his temp dir was c:\temp
    @echo off
    cd c:\temp
    dir > %CD%\test.txt
    
    Everyone makes the assumption, incorrect assumption based on the below
    "Execute the given command as if it were typed in at a command prompt."
    When you use Execute Shell Command, it's as though command were launched in root. here's how you test it: make a batch file with the below, name it blah.bat, and save to your desktop
    @echo off
    dir > test.txt
    
    then fire up command and type
    cd ../
    
    until you've hit root (in most cases it'll be c:\ then execute it... by typing
    blah.bat
    
    not gonna work right? why? because the CLI isn't on your desktop... OK now try this
    %userprofile%\desktop\blah.bat
    No funky errors... every thing seems to have been executed alright... but no text file... well thats exactly what you're doing when you do this:
    jtpryan
    <?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="Test" treePres="3">
    - <Body>
    - <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="c:\temp\test.bat" /> 
      <Parameter xsi:type="StringParameter" name="ManagedFile" value="VSASharedFiles\Client Specific\SGA\test.bat" /> 
      </Statement>
    - <Statement description="Execute the given command as if it were typed in at a command prompt." name="ExecuteShellCommand" continueOnFail="false">
      <Parameter xsi:type="StringParameter" name="Command" value="c:\temp\test.bat" /> 
      <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User" /> 
      <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" /> 
      </Statement>
      </Body>
      </Procedure>
      </ScriptExport>
    Now go through the same process but edit the blah.bat file to read as follows:
    @echo off
    cd c:\temp
    dir > %CD%\test.txt
    
    You'll find that the last entry now works as advertised... the wanted text file goes to the C:\temp directory and happens to pull the dir info from it too... if you want to pull dir from say "%userprofile%\desktop\" that is doable too... you'll just have to find the correct syantax... Bottom line, Execute Command Shell does work... it is everyone else that is broken... EDIT/ADDITION: If you think I'm being an <insert explitive here> about this, it's only because we've gone through this about half a dozen times since I've been here... and it seems like no one is searching for the answer... My appologies to anyone I've offended... P.S. I'm guilty of doing the same thing when first using batch files and Kaseya. I eventually found the answers that I needed by searching the forums.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: thirteentwenty



    [edited by: Brendan Cosgrove at 5:51 PM (GMT -8) on 12-20-2010] .
  • Thanks for putting in the time to clarify this for everyone reading the forum.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: garry
  • Ahhh, how do I respond to this...

    First, my apologies for the lack of a code tag.
    Second, thank you for your very verbose explanation that you provided.

    However; *nothing* is wrong with my .bat file. Dir > test.txt is a perfectly legitimate batch file. My VB script is a perfect good VB Script. I know this because I can go to the target machine and execute either of them from the command prompt and get the results I expect. This is what any user would (and should) expect to be able to do when a tool states “execute file from command shell”. So please, do not make statements that would paint me to be a moron for acting under this belief. Getting a test.txt file with the incorrect contents might be one thing, and easy to debug. But nothing happening at all? Just the fact that you have write such a long explanation to point out how amazingly convoluted this is points to the difficulty of using this product. My logic is more than sound and if this company had anybody employed in QA this would have come to light before. Do not defend a bad product when faults are pointed out, they will never improve. The way I approached this problem was absolutely correct, I should not have to go through the hoops you explained to accomplish such a basic task. The statement that you make “Bottom line, Execute Command Shell does work... it is everyone else that is broken...” is absurd. Like the guy in the Psychiatric ward saying “I’m fine, everybody else in the world is crazy”.

    ‘nuff said, I’ll revisit this with your write up in mind and see if it works.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: jtpryan

  • dir > test.txt


    Says "Give me *this* directory and put it in a text file *here*" When you run it interactively from c:\temp, it gives you the directory of c:\temp and puts the file in c:\temp.

    However, when you run stuff from the scripting engine in Kaseya, what is the context? You can't possibly know, and so when you are scripting a .bat file or similar you *must* specify or you will almost certainly not get the results you want. (although in truth, I think the context is %systemroot% by default)

    Analogy time: Imagine the following instructions for having dinner:
    1. Ask the clerk for a #1 combo
    2. Pay
    3. Take the tray to your table
    4. Eat the food

    This works fine at a fast food restaurant, once you've walked in and are standing inside. However, if you were in the drive-through, or at a tire store, these instructions would be either confusing, or actually dangerous!

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: Matthew Bartels
  • Thank you, I see this now. However, once I did see this it is still confusing in that a "test.txt" does not appear anywhere on the system. I would have thought it would appear at least in %systemroot%, but it didn't. Adding a CD to \temp did in fact make it work.

    That being said, the problem with running the VB Script from Kaseya was I needed to put a "use credential" statement at the beginning of the script. Of course, like so many things Kaseya, there was no logic to this as I was logged into the target machine as the same user (Administrator) that I used for the "use credential" setup. What I'm saying is I go to the machine and log in as administrator(domain admin), then go to another machine and launch the script via Kaseya with the "use logged in user" radio button checked. Nothing happens. I then insert the "use credential" statment in the beginning or the script, the credentials being the same as the currently logged in user, and it works.

    Go figure.

    Thank you for your post.

    -Jim

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: jtpryan
  • Unless you have the 'Use Credentials' step the script will run under the security context that the Kaseya Service is running under. Typically this will be 'Local System'

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: PeterS
  • OK, then what is the difference between that and "system"? Also, why does the statement say it will run as the logged on user?

    Unbelievable.


    Does this company ever sit somebody down that has never worked with the product to see how they interpret the interface? It seems that nothing is what it is advertised to be.

    "Execute the given command as if it were typed in at a command prompt"
    "Execute as the logged on user"

    None of this is true. If you execute "dir > test.txt" at the command prompt you will get a test.txt file. You don't, not anywhere. But if you CD to a directory within the .bat file you will get one in that directory

    If you execute a .VBS file as the logged on user, you don't, you execute it as the Kaseya service. What the hell is the radio button for?

    Thank you for he reply.

    -Jim

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: jtpryan
  • Matthew Bartels

    dir > test.txt


    Says "Give me *this* directory and put it in a text file *here*" When you run it interactively from c:\temp, it gives you the directory of c:\temp and puts the file in c:\temp.

    However, when you run stuff from the scripting engine in Kaseya, what is the context? You can't possibly know, and so when you are scripting a .bat file or similar you *must* specify or you will almost certainly not get the results you want. (although in truth, I think the context is %systemroot% by default)

    Analogy time: Imagine the following instructions for having dinner:
    1. Ask the clerk for a #1 combo
    2. Pay
    3. Take the tray to your table
    4. Eat the food

    This works fine at a fast food restaurant, once you've walked in and are standing inside. However, if you were in the drive-through, or at a tire store, these instructions would be either confusing, or actually dangerous!


    Yes eating tires can be dangerous!....

    Nice analogy...

    I think you're right about it being %systemroot%, which was the orginal reason why I put the %CD% in there. It's no longer needed because of the line before it, but I use it as a reminder to change that line for the output directory.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: thirteentwenty
  • jtpryan
    OK, then what is the difference between that and "system"? Also, why does the statement say it will run as the logged on user?

    All the scripting engine (or procedure engine as it's known now) does is run the command it is given and checks to see if that comman was completed succesfully. it does not look for exit/error codes on your script (read: vbs or batch file). To get around this, on the more complicated things that I've tried I make sure I create an error log (read: somthing that pumps out the exit code) then run another script to parse it.

    jtpryan

    Does this company ever sit somebody down that has never worked with the product to see how they interpret the interface? It seems that nothing is what it is advertised to be.

    Yes it's called the bootcamp (well the name may have changed but still it's out there). It sounds as though you did not go through them, or if you did you didn't as very many questions. And you are correct, well IMO kind of correct, things are not quite as advertised. If you were sold on the previous version of Kaseya and got K2 or K6 or what ever it's called then things must be wildly different.

    jtpryan

    None of this is true. If you execute "dir > test.txt" at the command prompt you will get a test.txt file. You don't, not anywhere. But if you CD to a directory within the .bat file you will get one in that directory


    If you fire up command prompt normally you will be in %userprofile%, so if you do a "dir > test.txt" then do "%userprofile%\test.txt" it should open

    jtpryan

    If you execute a .VBS file as the logged on user, you don't, you execute it as the Kaseya service. What the hell is the radio button for?

    I've often wondered this myself... I don't ever use the system option, I've only used the user option and impersonated a user if need be. (This was something that I was never given a clear answer to that could have been verified by script)

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: thirteentwenty