-1

I want to execute a command to lock the drive through bit locker when button is clicked. How to do this? I'm new in c#

The command is:

manage-bde -lock x:

How it will be send to console? here is the code

private void btnlock_Click(object sender, EventArgs e)
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = "/C manage-bde -lock "+textBox1.Text+":";
    process.StartInfo = startInfo;
    process.Start();
}
Balagurunathan Marimuthu
  • 2,666
  • 4
  • 23
  • 37
mani1989
  • 19
  • 1
  • 1
  • 8

2 Answers2

3

You can use the Process class in System.Diagnostics namespace. It should be something like this:

System.Diagnostics.Process.Start("manage-bde", "-lock x:");
dan radu
  • 2,692
  • 4
  • 16
  • 23
0

The command isn't being executed because your command line doesn't know where to find the manage-bde program.

All you need to do is add the full path of the file like so:

startInfo.Arguments = @"/C C:\Program Files\Foo\manage-bde.exe -lock "+textBox1.Text+":";

Note: I'm not sure if the .exe part is necessary, but it doesn't hurt adding it in. Also, make sure you either use 2 backslashes (\\) or use the @ before the quotation mark at the start.

Yorrick
  • 377
  • 2
  • 6
  • 27