You are viewing limited content. For full access, please sign in.

Discussion

Discussion

Execute a .bat local file with Workflow

posted on August 14, 2018

I know that this has been asked before but I just can't seem to find the answer that works. Which activity (SDK Script or Script) and which Scripting Language and setup does one use to setup a script that will run a .bat file located on the local server?

Thanks!

0 0
replied on August 15, 2018

Aquí adjunto un vb script, en el encontrarás los pasos para ejecutar .bat, recuerda de retirar la extensión .txt de los objetos.

0 0
replied on August 14, 2018

Here's a screenshot of our script that runs a bat file on the WF server:

Like Cliff said, what you use is up to your preference and needs. C# is our primary language, and in this case we didn't need to interact with anything in the repository so we just chose the "Script" activity, not the "SDK Script". 

1 0
replied on January 26, 2021 Show version history

I keep getting this error when trying to build the script: 

Error    1    'System.Diagnostics.Process' does not contain a definition for 'Startinfo' and no extension method 'Startinfo' accepting a first argument of type 'System.Diagnostics.Process' could be found (are you missing a using directive or an assembly reference?)    \Script\Script 1.cs    25    26    Akron Trip Sheet Day - EST

This is my code:

namespace WorkflowActivity.Scripting.Script
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using System.Diagnostics;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : ScriptClass90
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {
            try
            {
                System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
                pProcess.StartInfo.FileName = @"C:\Users\laserproven\Desktop\killOmni.bat";
                pProcess.Startinfo.UseShellExecute = false;
                pProcess.StartInfo.RedirectStandardOutput = true;
                pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                pProcess.StartInfo.CreateNoWindow = true;
                pProcess.Start();
                pProcess.WaitForExit();
            }
            catch (Exception ex)
            {
                SetActivityTokenValue("Errors", ex.ToString());
            }
        }
    }
}

I can't figure it out for the life of me and I know it's something simple I'm missing like a namespace or something.

0 0
replied on May 10, 2021

What version of System.Diagnostics are you referencing? You might be running into this issue.

0 0
replied on May 11, 2021

Also, your desktop location is going to be protected and the Workflow service will not be able to access the bat file.

pProcess.StartInfo.FileName = @"C:\Users\laserproven\Desktop\killOmni.bat";

Change to something like

pProcess.StartInfo.FileName = @"C:\Temp\killOmni.bat";

 

0 0
replied on April 20, 2022

I tried modifying this to run a script on a different server but it doesn't seem to be working. This is what I changed the pProcess.StartInfo.FileName to @"\\SERVERNAME\LF_Scripts\ssistest.bat"; This seems to build just fine but when I run it, it doesn't execute the script. 

0 0
replied on April 20, 2022

Is \\SERVERNAME\LF_Scripts  accessible to the WF Server's service user?

0 0
replied on April 20, 2022

Yes it is, MIruna. I have it set to share to everyone as well as the specific workflow service user. After I posted this I did question if it's even possible to run a bat file that exectures DTExec from a remote server. The script resides on the actual SQL server so I'm thinking it shouldn't matter. 

0 0
replied on August 14, 2018

The decision on which script activity to use depends solely on whether or not you need to also interact with a repository.  If you need to interact with a repository then you should use the SDK Script activity as it can supply the session object necessary to make that happen.  If you do not need to interact with a repository then you can use the Script activity.  As far as which scripting language to select that is purely a personal choice.  Both languages provide full access to .NET framework functionality.

There are several examples of posts that contain code to do just what you are looking to do.  Just do a search for 'workflow' and 'bat' and you will get several hits.

From a .NET perspective it is relatively simple; you are going to instantiate a new System.Diagnostics.Process, set the appropriate properties, and then call the Start method on the process.

 

2 0
You are not allowed to follow up in this post.

Sign in to reply to this post.