0

I'm trying to start manage-bde.exe as a new process in VB.net but when it tries to start the proc, Bitlocker crashes. Could anyone please tell me what I'm doing wrong here? This code was converted from C# where it works all day long....

Code:

Private Sub btnLock_Click(sender As Object, e As EventArgs) Handles btnLock.Click
    Dim drvSelected As String = cmbDriveSelect.SelectedValue.ToString()
    Dim sysDirWithBDE As String = Environment.SystemDirectory + "\manage-bde.exe"
    Dim lockStatus As String = String.Empty

    ' This is the code for the base process
    Dim myProcess As New Process()

    ' Start a new instance of this program
    Dim myProcessStartInfo As New ProcessStartInfo(sysDirWithBDE, " -lock " + drvSelected.Remove(2))
    'Set Use Shell to false so as to redirect process run info to application
    myProcessStartInfo.UseShellExecute = False
    myProcessStartInfo.RedirectStandardOutput = True
    myProcess.StartInfo = myProcessStartInfo
    Try
        myProcess.Start()
        lblDriveLockMsg.Show()
    Catch err As Exception
        lblDriveLockMsg.Text = err.Message
    End Try
    'Read the standard output of the process.
    lockStatus = myProcess.StandardOutput.ReadToEnd()
    If lockStatus.Contains("code 0x80070057") Then
        lblDriveLockMsg.Text = "Drive selected is not Bit Locker encrypted"
    ElseIf lockStatus.Contains("code 0x80070005") Then
        lblDriveLockMsg.Text = "Drive selected is in use by an application on your machine, force dismounting might result in data loss, please check and close any applications using the drive"
    Else
        lblDriveLockMsg.Text = lockStatus
    End If

    myProcess.WaitForExit()
    myProcess.Close()
End Sub
NMEwithin
  • 11
  • 2
  • What means "crashes". Do you get any error message? Btw.: in VB, the string concatenation operator is `&`. The operator `+` might do unexpected things if numbers are involved. See: http://stackoverflow.com/questions/734600/the-difference-between-and-for-joining-strings-in-vb-net – Olivier Jacot-Descombes Feb 23 '17 at 20:20
  • Hi...It tries to launch and I then get a windows dialog that states Bitlocker Drive Encryption: Configuration Tool Has Stopped Working and it has the JIT Debug option – NMEwithin Feb 23 '17 at 20:26
  • Also...I changed the "+" to a "&" but it made no difference – NMEwithin Feb 23 '17 at 20:28
  • `drvSelected.Remove(2)` expects that the drive is given as "C:\" and is supposed to remove the ":\" part. Better take `Left(drvSelected, 1)` instead of assuming a certain format. Debug the code in order to see whether the parameters are as expected. – Olivier Jacot-Descombes Feb 23 '17 at 20:29
  • This is the JIT Debug: Unhandled exception at 0x00007FF9B5F8DA9E (ntdll.dll) in manage-bde.exe: 0xC0000005: Access violation reading location 0x0000000000000072. If there is a handler for this exception, the program may be safely continued. – NMEwithin Feb 23 '17 at 20:29
  • Try running your app as administrator. – Olivier Jacot-Descombes Feb 23 '17 at 20:33
  • Thanks....didnt help though. I just hardcoded the drive letter as a test and it makes no difference and yet if I run the same thing from command line there is no issue: "manage-bde -status E:" works great from command line – NMEwithin Feb 23 '17 at 20:34
  • Tried that as well....no change :( – NMEwithin Feb 23 '17 at 20:36
  • You code says " -lock " not " -status ". – Olivier Jacot-Descombes Feb 23 '17 at 20:36
  • I know...I was trying status as a test because it only returns the status of the drive. Neither work. – NMEwithin Feb 23 '17 at 20:37
  • 1
    Thank you for your help...I was able to fix it by calling out "CMD /C" for the Prc.Start() Call..... Dim sysDirWithBDE As String = Environment.SystemDirectory + "\manage-bde.exe -lock %systemdrive%" Try Dim myProcessInfo As New ProcessStartInfo("cmd") myProcessInfo.Arguments = "/C " & sysDirWithBDE – NMEwithin Feb 23 '17 at 21:40
  • You can add your solution as an answer to your own question and accept it. This can be helpful for others encountering the same problem and at the same time closes the question. – Olivier Jacot-Descombes Feb 23 '17 at 21:47

0 Answers0