Created
April 17, 2016 17:35
-
-
Save Clijsters/e4e3c1a50cd0a8a654b8d39ee353fb64 to your computer and use it in GitHub Desktop.
RunProcess - executes process hidden, minimized, or shown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another way to define the WindowStyle in scripts is PowerShell:
Start-Process -WindowStyle Hidden "chrome.exe" "www.google.com"