Hello.
I am creating a small helper program that will apply the right UWF configurations.
A part of it is to protect the C:/ drive.
Now with a fresh install there is only one UWF_Volume instance, which is for the current session. uwfmgr.exe volume protect c: creates the instance.
The docs hint at creating the UWF_Volume instance yourself, but i was not able to do this.
I used Mgmtclassgen.exe to generate strongly typed wmi classes, and i then tried the following code:
string CreatedWmiNamespace = "ROOT\\StandardCimv2\\embedded";
string CreatedClassName = "UWF_Volume";
var managementScope = new ManagementScope();
managementScope.Path.NamespacePath = CreatedWmiNamespace;
managementScope.Path.Server = Environment.UserDomainName;
managementScope.Path.RelativePath = "UWF_Volume.CurrentSession=false,DriveLetter=\"C:\",VolumeName=\"Volume{61f048ac-d2e8-48b3-973d-1d14ac35c409}\"";
var managementPath = new ManagementPath(CreatedClassName);
var managementClass = new ManagementClass(managementScope, managementPath, null);
var mgtmObject = managementClass.CreateInstance();
var putoptions = new PutOptions();
putoptions.Type = PutType.UpdateOrCreate;
mgtmObject.Put(putoptions);
Both the strongly typed class and this give an exception:
System.Management.ManagementException was unhandled
HResult=-2146233087
Message=Invalid parameter
Source=System.Management
How can I create the UWF_Volume instance correctly?