diff --git a/Sistema.vb b/Sistema.vb
index 14b65a2..ade34f5 100644
--- a/Sistema.vb
+++ b/Sistema.vb
@@ -1,8 +1,59 @@
-Public Class Sistema
+Imports System.IO
+Imports System.Diagnostics
+
+Public Class Sistema
Public Shared Sub EjecutaFichero(Fichero As String)
Dim p As New Process
p.StartInfo = New ProcessStartInfo(Fichero)
p.StartInfo.UseShellExecute = True
p.Start()
End Sub
+
+
+
+ Public Shared Function EjecutarScript(rutaScript As String, Optional argumentos As String = "") As Integer
+ Try
+
+ Dim extension As String = Path.GetExtension(rutaScript).ToLower()
+ Dim proceso As New Process()
+ proceso.StartInfo.UseShellExecute = False
+ proceso.StartInfo.RedirectStandardOutput = True
+ proceso.StartInfo.RedirectStandardError = True
+ proceso.StartInfo.CreateNoWindow = True
+
+ Select Case extension
+ Case ".bat", ".cmd"
+ proceso.StartInfo.FileName = "cmd.exe"
+ proceso.StartInfo.Arguments = "/c """ & rutaScript & """ " & argumentos
+
+ Case ".ps1"
+ proceso.StartInfo.FileName = "powershell.exe"
+ proceso.StartInfo.Arguments = "-ExecutionPolicy Bypass -File """ & rutaScript & """ " & argumentos
+
+ Case ".exe"
+ proceso.StartInfo.FileName = rutaScript
+ proceso.StartInfo.Arguments = argumentos
+ Case Else
+ proceso.StartInfo.FileName = rutaScript
+ proceso.StartInfo.Arguments = argumentos
+ proceso.StartInfo.UseShellExecute = True
+ End Select
+
+ AddHandler proceso.OutputDataReceived, Sub(sender, e)
+ If e.Data IsNot Nothing Then Console.WriteLine("OUT: " & e.Data)
+ End Sub
+
+ AddHandler proceso.ErrorDataReceived, Sub(sender, e)
+ If e.Data IsNot Nothing Then Console.WriteLine("ERR: " & e.Data)
+ End Sub
+
+ proceso.Start()
+ proceso.BeginOutputReadLine()
+ proceso.BeginErrorReadLine()
+ proceso.WaitForExit()
+ Return proceso.ExitCode
+ Catch ex As Exception
+ Throw New Exception("Error al ejecutar el script: " & rutaScript & " parámetros: " & ex.Message)
+ End Try
+ End Function
End Class
diff --git a/tsUtilidades.vbproj b/tsUtilidades.vbproj
index cade2df..53eba30 100644
--- a/tsUtilidades.vbproj
+++ b/tsUtilidades.vbproj
@@ -16,11 +16,12 @@
net8.0
tsUtilidades
net8.0, libreria
- 1.1.4
+ 1.1.5
Manuel
Tecnosis S.A
Utilidades Varias
+ - 2025-10-05 1.1.5 Nueva funcion EjecutarScript
- 2025-09-05 1.1.4 No se eliminan los caracteres especiales ni se mayusculiza en ValidarDocumentoIdentidad
- 2025-09-05 1.1.3 Se marcan como obsoletas las clases de zip correos y la función validateNIF dentro de utilidades
- 2025-09-05 1.1.2 Correccion en ValidarDocumentoIdentidad