- 2025-10-05 1.1.5 Nueva funcion EjecutarScript

This commit is contained in:
2025-10-05 12:38:25 +02:00
parent d822d4e579
commit 2cefca5f8b
2 changed files with 54 additions and 2 deletions

View File

@@ -1,8 +1,59 @@
Public Class Sistema Imports System.IO
Imports System.Diagnostics
Public Class Sistema
Public Shared Sub EjecutaFichero(Fichero As String) Public Shared Sub EjecutaFichero(Fichero As String)
Dim p As New Process Dim p As New Process
p.StartInfo = New ProcessStartInfo(Fichero) p.StartInfo = New ProcessStartInfo(Fichero)
p.StartInfo.UseShellExecute = True p.StartInfo.UseShellExecute = True
p.Start() p.Start()
End Sub 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 End Class

View File

@@ -16,11 +16,12 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<PackageId>tsUtilidades</PackageId> <PackageId>tsUtilidades</PackageId>
<PackageTags>net8.0, libreria</PackageTags> <PackageTags>net8.0, libreria</PackageTags>
<Version>1.1.4</Version> <Version>1.1.5</Version>
<Authors>Manuel</Authors> <Authors>Manuel</Authors>
<Company>Tecnosis S.A</Company> <Company>Tecnosis S.A</Company>
<Description>Utilidades Varias</Description> <Description>Utilidades Varias</Description>
<PackageReleaseNotes> <PackageReleaseNotes>
- 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.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.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 - 2025-09-05 1.1.2 Correccion en ValidarDocumentoIdentidad