Kaseya Community

.bat File Not Executing

This question is answered

I have two .bat files trying to uninstall IE11 that puts it back to IE9. When I click on this .bat file locally it launches without a problem and does it's job. When I try to execute through Kaseya Agent Procedure nothing happens. 

The interesting thing is that I have an IE kill task .bat that is executing just fine. 

Penny for your thoughts! :) 

Here's the Uninstall that won't execute

c:\windows\system32\wusa.exe /uninstall /kb:2841134 /quiet /norestart

And here's the kill task that does 

taskkill /F /IM iexplore.exe 

And the script looks like this:



Added examples and photo
[edited by: h34th3r at 5:26 PM (GMT -7) on Aug 13, 2015]
Verified Answer
  • "Execute as System" is okay for killing tasks but not for uninstalling, you will need to elevate it to "Execute as User" and add a "useCredentials" line above the execute file. Your Agent Credentials will also need to have local admin rights.

    Question, why don't you run the commands from the batch file direct from a ExecuteShellCommand line instead?

  • that's correct. execute runs a file in it's context on the machine, and executeshellcommand runs whatever command you put in as if it were typed in command prompt.

    so for example if i wanted to open a jpg file automatically on a user's desktop in their default image viewer i would use execute and set it to run as the user.

    if i'm doing anything that i would think to run in command prompt or a bat file i use executeshellcommand

    the usecredentials command in kaseya is also useful if you have your credentials set to be an administrator account. this way you can run a command as the user, or as the system, or as an administrator using the credentials.

  • And remember to use execute as system/user in 64-bit shell if the OS is 64-bit.

All Replies
  • "Execute as System" is okay for killing tasks but not for uninstalling, you will need to elevate it to "Execute as User" and add a "useCredentials" line above the execute file. Your Agent Credentials will also need to have local admin rights.

    Question, why don't you run the commands from the batch file direct from a ExecuteShellCommand line instead?

  • I agree with hardknox, use executeShellCommand. There's also other ways to remove is versions without worrying about credentials, but I'm not at my desk so I'll have to post tomorrow.

  • What's the difference between execute and executeshellcommand? When I do executeshellcommand do I just enter

    wusa.exe /uninstall /kb:2841134 /quiet /norestart  into the Enter the command to execute in a command shell field

    And then run as system ?

  • that's correct. execute runs a file in it's context on the machine, and executeshellcommand runs whatever command you put in as if it were typed in command prompt.

    so for example if i wanted to open a jpg file automatically on a user's desktop in their default image viewer i would use execute and set it to run as the user.

    if i'm doing anything that i would think to run in command prompt or a bat file i use executeshellcommand

    the usecredentials command in kaseya is also useful if you have your credentials set to be an administrator account. this way you can run a command as the user, or as the system, or as an administrator using the credentials.

  • Hey Eric - if you're using ExecuteShellCommand do you still have to do the UseCredentials line?

  • And remember to use execute as system/user in 64-bit shell if the OS is 64-bit.

  • By default the ExecuteShellCommand is set to execute as the currently logged on user.

    In many cases the currently logged on user is not an admin, so if you need a command to run with administrator privileges it's a good idea to set your agent credentials tab to use an administrator account and then in your procedure you can put the UseCredentials command ahead of an ExecuteShellCommand as user and it will run as the credentials user instead of the logged on user.

    Lastly you can use ExecuteShellCommand as system and this is probably the highest level of elevated privileges you can have, and using this ignores the UseCredentials command, so it's really not needed when using system.

  • I'm going to try the 64bit option because I still can't get this uninstaller to work through a procedure with just ExecuteShellCommand

  • try these instead;

    // Remove IE11

    FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Windows-InternetExplorer-*11.*.mum /c "cmd /c echo Uninstalling package @fname && start /w pkgmgr /up:@fname /norestart"

    // Remove IE10

    FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Windows-InternetExplorer-*10.*.mum /c "cmd /c echo Uninstalling package @fname && start /w pkgmgr /up:@fname /norestart"

    // Remove IE9

    FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Windows-InternetExplorer-*9.*.mum /c "cmd /c echo Uninstalling package @fname && start /w pkgmgr /up:@fname /norestart"

    // Remove IE8

    FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Windows-InternetExplorer-*8.*.mum /c "cmd /c echo Uninstalling package @fname && start /w pkgmgr /up:@fname /norestart"

    Run any of those as system using executeshellcommand. in your case if you want to downgrade to 9 you'll want to remove 11 and 10 (and not the rest)

    after those complete I like to reinstall IE with these commands (also as system)

    // 64-bit

    dism /online /Disable-Feature /FeatureName:Internet-Explorer-Optional-amd64

    dism /online /Enable-Feature /FeatureName:Internet-Explorer-Optional-amd64

    // 32-bit

    dism /online /Disable-Feature /FeatureName:Internet-Explorer-Optional-x86

    dism /online /Enable-Feature /FeatureName:Internet-Explorer-Optional-x86

    I don't worry about running these commands with the special 64 bit executeshellcommand, because they work fine without changing that option.

    A reboot is REQUIRED after running ANY of these commands in order for everything to work out

    I've actually got a nice premade procedure for all of this but it seems like you're wanting to get the hang of procedures so im sure you can piece this all together ;)

  • I used that same wusa command to uninstall IE11 and the only way to get it to work was to run it in 64bit shell.

  • I must be blind I only see the powershell 64bit shell - is this what you meant neuvoja?

  • , when you have executeShellCommand selected then look under the Run as options

  • Thanks to all - finally have a working procedure!