0

I want to run the below code from my application:

manage-bde -protectors -disable C:

It is working perfectly if I open up a command prompt and run from there (win8).

But if I try to run it from my app, I get: 'manage-bde' is not a recognized program.

My code:

process1.StartInfo.RedirectStandardOutput = true;
            process1.StartInfo.UseShellExecute = false;
            process1.StartInfo.CreateNoWindow = false;
            process1.StartInfo.FileName = @"cmd.exe";
            process1.StartInfo.Arguments = @"/C manage-bde -protectors -disable C:";
            process1.Start();

What am I missing?

fishmong3r
  • 1,414
  • 4
  • 24
  • 51

1 Answers1

2

Reason for Failure:

cmd.exe could not identify your filemanage-bde to proceed further.

You can solve this issue by providing proper path for the file manage-bde.

Solution 1: When you run any console Commands from C# they will run from the following path by default:

if you run the project in Release Mode --> <Solution FolderName>\<Project FolderName>\bin\Release

if you run the project in Debug Mode --> <Solution FolderName>\<Project FolderName>\bin\Debug

So if you want to run any thirdparty exe files from your c# code you make sure to copy them(exe files) into respective folders.

Solution 2 : You can set the path for manage-bde in Environment Variables

Solution 3: You can give the Full Path of manage-bde in your code.

Sample Code : here i'm providing complete path of exe/bat file which i would like to execute:

Process process1 = new Process();
process1.StartInfo.RedirectStandardOutput = true;
process1.StartInfo.UseShellExecute = false;
process1.StartInfo.CreateNoWindow = false;
process1.StartInfo.FileName = @"cmd.exe";
process1.StartInfo.Arguments = @"/C C:\apache-jmeter-2.9\apache-jmeter-2.9\bin\jmeter.bat";
process1.Start();
Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
  • Hi, thanks for your answer. I defined the full path, but I get the same: "'C:\Windows\System32\manage-bde.exe' is not recognized as an internal or external command, operable program or batch file." The executable exists. – fishmong3r Nov 07 '13 at 15:13
  • @fishmong3r : it is because version mismatch as you running it in windows 7. so from Visual Studio please right click on project -> properties->Build->change your platform Target from anycpu to X64, then build and run the project it should be able to execute your exe :) – Sudhakar Tillapudi Nov 07 '13 at 15:33
  • OK, I admit I'm a noob but I can't find this option. I'm using VS C# Express 2010. In the project properties -> build tab I have no 'Target'. – fishmong3r Nov 08 '13 at 07:13
  • 1
    @fishmong3r : From the "Tools" menu, select the "Options" item, and then select the "Projects and Solutions" option in the listbox on the left-hand side of the Options dialog. (You might have to check "Show all settings" first.) Check the box that says "Show advanced build configurations". -->Source>http://stackoverflow.com/questions/4104228/change-target-cpu-settings-in-visual-studio-2010-express – Sudhakar Tillapudi Nov 08 '13 at 07:18
  • Ok, wait a sec, I'm checking. – fishmong3r Nov 08 '13 at 07:33
  • Yeah, no. I followed the instructions on that link but I can't get to Configuration Manager. Now I can see the 'Platform' on the Build tab, but I can't choose anything but 'Active(x86)'. – fishmong3r Nov 08 '13 at 07:39
  • I made it. And I really appreciate your help with this. – fishmong3r Nov 08 '13 at 07:58
  • :) you are welcome. could you please tell me how did you manage to get X64 bit option in build settings? – Sudhakar Tillapudi Nov 08 '13 at 08:03
  • Sure, I could finally add from Soulution Explorer -> Property pages -> Configuration Properties -> Configuration -> and I've changed the platform to x64 – fishmong3r Nov 08 '13 at 09:35
  • But now I'm facing the issue that I can't run my app on a Win7 32-bit OS. Can I somehow make the app working regardless of the OS architecture? – fishmong3r Nov 08 '13 at 09:36