Since I couldn't find a complete solution to finding the intersection point between two lines (rather just snippets and hints), see below a full class which provides this functionality.
Change the namespace as required.
A scratchpad for interesting code or thoughts I have as I start my journey as a professional developer.
Wednesday, 7 September 2016
Tuesday, 2 August 2016
Getting the value of a setting in the power plan
Here is another one that was a pain!
First of all I was led down the garden path of attempting to do this through the use of C++ libraries:
This had its own problems of attempting to convert items to and from IntPtr in order to leverage the PowerEnumerate method within powerprof.dll.
Luckily while googling something else I came across the WMI classes of "Win32_PowerSetting" and "Win32_PowerPlan".
I needed to get the current value for the sleep timeout. The first thing to do is check the currently active power plan, and then get all the settings from different plans that match the GUID for the sleep timeout.
Once that is retrieved as a collection, I check which one is the one used by the currently active plan, and then read and return the value. See below:
First of all I was led down the garden path of attempting to do this through the use of C++ libraries:
This had its own problems of attempting to convert items to and from IntPtr in order to leverage the PowerEnumerate method within powerprof.dll.
Luckily while googling something else I came across the WMI classes of "Win32_PowerSetting" and "Win32_PowerPlan".
I needed to get the current value for the sleep timeout. The first thing to do is check the currently active power plan, and then get all the settings from different plans that match the GUID for the sleep timeout.
Once that is retrieved as a collection, I check which one is the one used by the currently active plan, and then read and return the value. See below:
Thursday, 28 July 2016
Checking the current OS for an element in the BCDStore
Since I found this such a huge pain in the arse I decided to commit it to a blog for posterity. May someone find this someday and save themselves a few hours of frustration. Note that this code works for retrieving an element of type "integer" but could be altered to cast other base types, such as "string", "boolean" etc.
Subscribe to:
Posts (Atom)