Skip to content

Instantly share code, notes, and snippets.

@Clijsters
Created April 17, 2016 17:35
Show Gist options
  • Save Clijsters/e4e3c1a50cd0a8a654b8d39ee353fb64 to your computer and use it in GitHub Desktop.
Save Clijsters/e4e3c1a50cd0a8a654b8d39ee353fb64 to your computer and use it in GitHub Desktop.
RunProcess - executes process hidden, minimized, or shown
Module Module1
Sub Main(ByVal Args() As String)
Try
If Args.Length = 2 Then
Dim fileName As String = Args(1)
If Not String.IsNullOrEmpty(fileName) Then
If System.IO.File.Exists(fileName) Then
Dim startInfo As New ProcessStartInfo(fileName)
Select Case Args(0).ToLower()
Case "hide"
startInfo.WindowStyle = ProcessWindowStyle.Hidden
Case "minimize"
startInfo.WindowStyle = ProcessWindowStyle.Minimized
Case Else
Console.WriteLine(Args(0) & " is unknown. Showing Window.")
startInfo.WindowStyle = ProcessWindowStyle.Normal
End Select
Process.Start(startInfo)
Else
Throw New System.IO.FileNotFoundException("The file specified was not found. (""" & fileName & """)")
End If
Else
Throw New System.ArgumentOutOfRangeException("No file specified.")
End If
Else
Throw New System.Exception("Invalid count of arguments")
End If
Catch ex As Exception 'Optional: Catch ex As System.IO.FileNotFoundException
Console.Error.WriteLine("ERROR" & vbCrLf & ex.Message)
End
End Try
End Sub
End Module
@Clijsters
Copy link
Author

Another way to define the WindowStyle in scripts is PowerShell: Start-Process -WindowStyle Hidden "chrome.exe" "www.google.com"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment