0

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

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
sari k
  • 2,051
  • 6
  • 28
  • 34

3 Answers3

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
-1

You can use the Process.Start() method:

Process.Start("bcdedit.exe", "/default " + yourOSId);
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • how can I get the current operating id? (yourOSId) – sari k Nov 25 '10 at 13:59
  • @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

You cannot change/set the OS version. You can only read it.

Rhapsody
  • 6,017
  • 2
  • 31
  • 49