Hi all,
Using Workflow and SDK (C#), I want to execute a batch's file.
I tried this one but unsucess.
//Executer le process Process.Start(@"C:\Users\Olivier\Desktop\print.bat");
Someone can help me please?
Thanks in advance.
Regards
Hi all,
Using Workflow and SDK (C#), I want to execute a batch's file.
I tried this one but unsucess.
//Executer le process Process.Start(@"C:\Users\Olivier\Desktop\print.bat");
Someone can help me please?
Thanks in advance.
Regards
Hi Olivier,
Try the below:
protected override void Execute() { ExecuteCommand("C:\\test.bat"); } public void ExecuteCommand(string command) { int ExitCode; ProcessStartInfo ProcessInfo; Process Process; ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command); ProcessInfo.CreateNoWindow = true; ProcessInfo.UseShellExecute = false; Process = Process.Start(ProcessInfo); Process.WaitForExit(); ExitCode = Process.ExitCode; Process.Close(); }
Hi Henry,
I have some errors.
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Data.SqlClient Imports System.Text Namespace WorkflowActivity.Scripting.Script '''<summary> '''Offre une ou plusieurs méthodes qui peuvent être exécutées au moment de l'exécution de l'activité de scriptage du flux de travail. '''</summary> Public Class Script1 Inherits ScriptClass90 '''<summary> '''Cette méthode est exécutée quand l'activité est effectuée. '''</summary> Protected Overrides Sub Execute() 'Ecrivez ici votre code. { ExecuteCommand("C:\\test.bat"); } public void ExecuteCommand(string command) { int ExitCode; ProcessStartInfo ProcessInfo; Process Process; ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command); ProcessInfo.CreateNoWindow = true; ProcessInfo.UseShellExecute = false; Process = Process.Start(ProcessInfo); Process.WaitForExit(); ExitCode = Process.ExitCode; Process.Close(); } End Sub End Class End Namespace
I realised that you're not using c# no?
Any in both cases you should add some imports / using.
I can send them to you on Moday if you didn't receive any help.
Good luck!
Hey Henry,
You right, sorry for my mistake.
It's working!
Thank you very much.
Henry,
With my message.bat, I don't have problem.
Msg * "insert your message here"
I create a new bat's file (print.bat).
With this one, the workflow don't execute the bat's file and I don't understand why.
@echo off start "" "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /t "C:\Users\Olivier\Desktop\FORPRINT\FI_8854.pdf" timeout /t 10 taskkill /IM AcroRd32.exe /f
Because your batch file tries to launch Adobe Reader. Workflow runs as a service without a user session, so there's no place for the Adobe Reader window to open.
Hi Miruna,
thank you for your return.
Understood.
In this case, do you have another way to automatically print a pdf?
See the following discussions on why direct printing from Workflow is not likely to work and possible workarounds.
https://answers.laserfiche.com/questions/83738/Print-from-Workflow--Has-anyone-tried-this
Have you seen:
Hi Bert,
Thank you for your help.
Yes I tried this but doesnt work for me.
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Data.SqlClient Imports System.Text Namespace WorkflowActivity.Scripting.Script '''<summary> '''Offre une ou plusieurs méthodes qui peuvent être exécutées au moment de l'exécution de l'activité de scriptage du flux de travail. '''</summary> Public Class Script1 Inherits ScriptClass90 '''<summary> '''Cette méthode est exécutée quand l'activité est effectuée. '''</summary> Protected Overrides Sub Execute() 'Ecrivez ici votre code. Dim processID As String = "" Dim stdOut As String = "" Dim exitCode As String = "" 'Create a process (which will not start running until later) which will eventually start the program we wish to call. Using process As System.Diagnostics.Process = New System.Diagnostics.Process Try 'Retrieve the token values... Dim cmdLineParameters As String = Me.GetTokenValue("CmdLineParameters") Dim externalProgram As String = Me.GetTokenValue("ExternalProgram") Dim waitForExit As Boolean = Me.GetTokenValue("WaitForExit") ' Empty externalProgram token is ignored... If (Not String.IsNullOrWhiteSpace(externalProgram)) Then 'These settings let us specify the file name and location, and specify to the process that we wish to handle stdout and stderr ourselves. UseShellExecute = false is 'a requirement for this to work. process.StartInfo.UseShellExecute = False process.StartInfo.RedirectStandardOutput = True process.StartInfo.FileName = externalProgram 'If there are command line arguments then set them... If (Not String.IsNullOrWhiteSpace(cmdLineParameters)) Then ' The arguments are specified in the input property box process.StartInfo.Arguments = cmdLineParameters End If 'Starts the process with all the settings we chose via Process.StartInfo... process.Start() 'Set the processId variable for return as a token... processID = process.Id 'If True then wait for the process to terminate before continuing the workflow... If (waitForExit) Then 'As recommended in http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput%28v=vs.71%29.aspx, stdout should be read before 'WaitForExit. Here the stdout is read and stored, and then we wait for the process to complete, if applicable. Dim output As String = process.StandardOutput.ReadToEnd process.WaitForExit() 'Set the return values to return as tokens... stdOut = output exitCode = process.ExitCode End If End If Finally 'Once we are done, make sure to free the process' handle if the process exists. If (Not process Is Nothing) Then process.Dispose() End If End Try End Using 'Set the token values to be evaluated later in the workflow... 'Me.SetTokenValue("ProcessID", processID) 'Me.SetTokenValue("StdOut", stdOut) 'Me.SetTokenValue("ExitCode", exitCode) End Sub End Class End Namespace
Olivier,
Is the workflow throwing any errors that you can report? Also, the batch file you are trying to run is located on the users desktop. How about moving that batch file to a more 'neutral' folder on the C: drive? Perhaps the issue running the batch file is a permissions issue?
Olivier
You could add a catch to your Try-Finally and pump any caught exception into an output so you can see it. Something like this:
Try 'Do your Work Catch ex As Exception WorkflowApi.TrackError(ex.message) Finally 'Clean up here End Try
Cliff
Have not seen you posting on here recently so it is great to see you respond and know that you are still out there.
Keep up the great work and thanks for all your help over the years!
Similar to what Bert and Cliff are saying, your batch file is called "print.bat". What is it trying to do?
Hi all,
thank you to your return.
For my exemple, my bat just open a message box ("Hello").
From Windows, I have the message.
Since Workflow is a service and has no desktop environment, your message box will never show when it is called by workflow. The applications that you start from a workflow must run without direct user input (command line arguments are the only input available) and without a gui (there is no desktop environment to display application forms or windows).
Hi Bert.
Sorry I don't really understand.
Do you means this is not possible?
You put C# code/syntax into a VB program.