Advertisement
JayBeeOH

ProcessCmdDemo

Dec 12th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.41 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2015. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   Process Command Demo
  13. '
  14. ' Author:         Joseph L. Bolen
  15. ' Date Created:   Dec 2015
  16. '
  17. ' Description:    Issues the MsConfig program from a Visual Basic program.
  18. '
  19. ' Compiling Note: Change program to Compile Target CPU - x64 (or uncheck Prefer 32-bit).
  20. '-------------------------------------------------------------------------------------------
  21.  
  22. Imports System.IO
  23.  
  24. Public Class MainlineForm
  25.  
  26.     Private Sub startProcessButton_Click(sender As Object, e As EventArgs) _
  27.         Handles startProcessButton.Click
  28.  
  29.         ' Quick and dirty approach ...
  30.  
  31.         'Try
  32.         '    Process.Start("msconfig.exe")  ' Path is assumed.
  33.         'Catch ex As Exception
  34.         '    MessageBox.Show(ex.Message,
  35.         '                    "Process Error",
  36.         '                    MessageBoxButtons.OK,
  37.         '                    MessageBoxIcon.Error)
  38.         'End Try
  39.  
  40.         ' More sophisticated approach ...
  41.  
  42.         Dim pgmFilePath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "msconfig.exe")
  43.         Dim myProcess As New Process    ' System.Diagnostics namespace
  44.  
  45.         With myProcess.StartInfo
  46.             .FileName = pgmFilePath
  47.             .UseShellExecute = True
  48.             .Verb = "runas"
  49.             .WindowStyle = ProcessWindowStyle.Normal
  50.         End With
  51.  
  52.         Try
  53.             myProcess.Start()
  54.             myProcess.WaitForExit()
  55.         Catch ex As Exception
  56.             MessageBox.Show(ex.Message,
  57.                             "Process Error",
  58.                             MessageBoxButtons.OK,
  59.                             MessageBoxIcon.Error)
  60.         End Try
  61.     End Sub
  62. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement