Skip to content

ManagementEventWatcher.Start throws an exception when a power plan doesn't have a name #125296

@wcruppel

Description

@wcruppel

Description

I've created a System.Management.ManagementEventWatcher instance that I'm using to monitor for creation of new power plans. But, if a power plan exists that does not have a name, calling Start throws System.IO.FileNotFoundException.

Reproduction Steps

Export the standard Balanced power plan, delete it, reimport, but do not give it a name.

powercfg /export %TEMP%\Balanced.pow 381b4222-f694-41f0-9685-ff5bb260df2e
powercfg /delete 381b4222-f694-41f0-9685-ff5bb260df2e
powercfg /import %TEMP%\Balanced.pow 381b4222-f694-41f0-9685-ff5bb260df2e

Then, run this code:

ManagementEventWatcher watcherCreate = new ManagementEventWatcher (
new ManagementScope ("\root\cimv2\power"),
new WqlEventQuery (
"__InstanceCreationEvent",
new TimeSpan (0, 0, 5),
"TargetInstance isa "Win32_PowerPlan""
)
);
watcherCreate.Start (); // BOOM!

Expected behavior

Start the watcher without throwing an exception. i.e. should not care if a power plan has a name or not.

Actual behavior

Throws System.IO.FileNotFoundException

Regression?

Dunno. Probably not.

Known Workarounds

None

Configuration

.NET 10.0.3
Windows 10 19045.6937
x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions