Hi. I’m working with custom power schemes in Windows, which generate unique GUID’s every time they’re applied (thus, I can’t just search by GUID), so I have to search for the scheme by “FriendlyName” in the relevance to see if it exists in the registry. On top of that, not only does it have to exist, but it also has to be the “ActivePowerScheme”.
In a perfect world, it’d be as simple as: “exists power scheme with FriendlyName = Plan 1” AND “ActivePowerScheme = Plan 1”
But, in reality I imagine it is more like: exists power scheme with ‘FriendlyName = Plan 1’ and you somehow take that Plan 1’s GUID and see if it equals the ActivePowerScheme
Anyone have any ideas on how to make that work out?
Personally I prefer the approach of auditing the settings of the current power scheme rather than the name of it, or set & assert the preferred settings on all power schemes in the case of a desktop so that you know the settings will always be in use. This doesn’t work if you want users to be able to switch power schemes however.
I do think I have written relevance similar to what you are asking for though, I’ll have to dig it up.
The approach I would recommend is to query what the ActivePowerScheme is, then query what it’s name is.
Do you have any relevance or at least the registry locations to locate this information? Any URL of documents that can be used to figure this out?
unique values of (it as string as trimmed string) of values "PreferredPlan" of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\{025A5937-A6BE-4686-A844-36FE4BEC8B6D}" of (x64 registries;x32 registries)
unique values of (it as string as trimmed string) of values "ActivePowerScheme" of keys "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Power\User\PowerSchemes" of (x64 registries;x32 registries)
I’m not sure if this is the correct / best way to query the friendly names of the systems power plans, but it appears to work:
unique values of (preceding texts of lasts "%00" of following texts of lasts "," of it) of (it as string as trimmed string) of values "FriendlyName" of keys of keys "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes" of (x64 registries;x32 registries)
unique values of (preceding texts of lasts "%00" of following texts of lasts "," of it) of (it as string as trimmed string) of values "FriendlyName" of keys whose( (set of unique values of (it as string as trimmed string) of values "PreferredPlan" of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\{025A5937-A6BE-4686-A844-36FE4BEC8B6D}" of (x64 registries;x32 registries) ) contains (name of it)) of keys "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes" of (x64 registries;x32 registries)
jgstew, I appreciate all the help you’re posting. Thank you very much. I’m going to have to do some studying and research on everything you provided…gonna take some time.
Not sure if I mentioned, but what I’m doing is… I’ve create power scheme tasks (just call them Plan 1, 2, 3)…those plans are done and functional in the action script. This part I’m working on now is the Relevance to those tasks. Simply put (I hope), I want to run these tasks as an Offer and the applicable (Relevant) machines should be:
(Plan __ does not exist in registry), OR
(Plan __ exists in registry AND not the ActivePowerScheme)
This way users can switch plans around, and only seeing what’s available in the Offers.
OR… We can forget this whole thing and if you let me know a way I can continuously “RE-Offer” a task even after it being accepted (have it keep popping up in the IEM Support Manager Offers non-stop)… that might work.
One thing I’m not certain of is are these power plans per user or per machine?
Assuming they are per machine and not per user, then my relevance should work.
The above combined relevance will give you the current active power plan, so you can use this to be the relevance of your tasks/offers.
This is what you would use for the relevance for the offer that sets “Plan 1”:
not exists unique values whose(it contains "Plan 1") of (preceding texts of lasts "%00" of following texts of lasts "," of it) of (it as string as trimmed string) of values "FriendlyName" of keys whose( (set of unique values of (it as string as trimmed string) of values "ActivePowerScheme" of keys "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Power\User\PowerSchemes" of (x64 registries;x32 registries) ) contains (name of it) ) of keys "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes" of (x64 registries;x32 registries)
Also, I should note I wrote this against Windows 8, but I think it works for Vista+
Sorry, but your statement is not working… In fact, I cannot find “Plan 1” anywhere within that registry path under …namespace{025A5937-A6BE-4686-A844-36FE4BEC8B6D}. All I find in there is the built in (Win7) “Balanced” scheme. Isn’t the “PreferredPlan” merely the “Recommended” scheme (in Power Options)? I’m finding the active scheme under: …\CurrentControlSet\Control\Power\User\PowerSchemes\ActivePowerScheme
Anyway, here’s what I have (and the only place I can find my plan):
NOT exists key whose (value “FriendlyName” of it as string contains “Plan 1”) of keys "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes" of (registry; native registry)
That is only the “NOT exists” part. I need the “OR ‘Exists, but not active’ (ActivePowerScheme)” part. How to get (an existing) Plan 1’s GUID to match the value of ActivePowerScheme is where I’m stuck.
The relevance was correct, I was just getting the GUID of the currently active power plan from the wrong place.
This is fixed:
unique values of (preceding texts of lasts "%00" of following texts of lasts "," of it) of (it as string as trimmed string) of values "FriendlyName" of keys whose( (set of unique values of (it as string as trimmed string) of values "ActivePowerScheme" of keys "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Power\User\PowerSchemes" of (x64 registries;x32 registries) ) contains (name of it) ) of keys "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes" of (x64 registries;x32 registries)
This relevance is identical to the relevance to return all friendly names of all power plans, but relevance was added to only return the friendly names of the power plans with a GUID that matches the currently active power plan. This is 2 different relevance statements nested together using a WHOSE clause.
The individual relevance clauses are above seperated.