1

I am trying to run the following code in a click event. However because it executes the command in the cmd shell, I don't know why it wont run. What I can do is open cmd.exe as Administrator by commenting out the Arguments. As well as stick these arguments in a .bat file, then running from process.start.

However, why I cant run the shell with the arguments? I'd prefer this method over putting the arguments in a .bat file.

    Dim process As New System.Diagnostics.Process()
        Dim startInfo As New System.Diagnostics.ProcessStartInfo()
        ' startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden

        startInfo.FileName = "cmd.exe"
        If System.Environment.OSVersion.Version.Major >= 6 Then ' Windows Vista or higher
            startInfo.Verb = "runas"
        Else
            ' No need to prompt to run as admin
        End If
        startInfo.Arguments = "/C bcdedit /set {current} safeboot network"
        process.StartInfo = startInfo
        process.Start()
Benjamin Jones
  • 987
  • 4
  • 22
  • 50

1 Answers1

0

Figured it out. I had to copy bcdedit.exe to my project. I had thought that calling cmd.exe would go to the location bcdedit.exe was located.

Benjamin Jones
  • 987
  • 4
  • 22
  • 50