how set value of current operating system to default operating system -by c# code or by script. manually : control panel -> System -> change system -> advanced ->setting -> (startup and recovery) checked the default operating system. I do it by this script, I want to set in the current operating id: bcdedit /default
Asked
Active
Viewed 7,549 times
0
-
5Sorry, I don't understand your question. Can you clarify exactly what you want to do? – Frédéric Hamidi Nov 25 '10 at 13:14
3 Answers
4
The answer you are looking for is:
bcdedit /default {current}
You should execute this command line from a c# program which has aquired administrative rights or else it will fail.
Windows BCD store is accessible only with admin rights.
Alternatively you can use WMI to access BCD store programmatically. The equivalent program code for the command line above is 10-20 lines of c# code.
You set the "DefaultObject" element of {bootmgr} object to {current}.

snayob
- 311
- 2
- 11
-
1It worked for me. Just make sure that you'll run CMD as admin. – Arkadiusz Lendzian May 17 '15 at 09:13
-1
You can use the Process.Start() method:
Process.Start("bcdedit.exe", "/default " + yourOSId);

Frédéric Hamidi
- 258,201
- 41
- 486
- 479
-
-
@FrédéricHamidi I've tried `Process.Start("bcdedit.exe", "/v" );` but got error message `System.ComponentModel.Win32Exception: 'The system cannot find the file specified'` (here is the [screenshot](https://i.imgur.com/kvJFDKt.png)). When I am doing same things manually via cmd, it works fine. What am I doing wrong? Thanks in advance. – Andrey Kotov Feb 26 '19 at 23:12
-2