I've tried the Win32_DesktopMonitor and checked the "Availability", but the value returned is always 3 (powered on), even when the monitor is physically turned off.
Is the data cached and there's a "force refresh" command in WMI, or in this particular case, the "Availability" is just not reliable ?
I think there is caching going on somewhere. I've observed it recently.
I wrote code that was polling for updates to Win32_PnPSignedDriver via SelectQuery / ManagementObjectSearcher and the results appear to be cached because it never realizes that a new device/driver has been added. Running the query from a separate app instantly sees that it was updated.
You may have a look to your driver. According to the documentation, starting with Windows Vista, hardware that is not compatible with Windows Display Driver Model (WDDM) returns inaccurate property values for instances of this class. For me it's an another way to say that it's not reliable.
Related
I want to detect current windows 10 update status programmatically.
I tried wuapi and it works well but there are some problems in wuapi.
First, it takes long time to get update information.
Second, it can not be used at offline.
Is there any other method to detect current windows 10 update status?
Is there any registry or system file to detect it?
I tried procmon to analyse but there are too many files and registries linked with windows udpate.
Thank you...
There is no documented way to access the search results that Automatic Updates is using (the results that the Windows Update page in Settings displays).
However, there are two things that might be of use to you:
You can use IAutomaticUpdatesResults::LastInstallationSuccessDate to immediately see the last time the computer installed updates successfully. If all you want to know is "Is this PC processing updates successfully?", then this may be all you need.
You can use a Windows Update API search to see what updates are needed. Here's a script you can use as a starting point. If you use this script as written, it will go online to find newly-released updates, which isn't what you want in your scenario. But you can set your IUpdateSearcher object's Online property to false before calling Search. Doing that will perform an offline scan, in which WU just re-evaluates the updates it already knows about. This will work offline and will also return faster results.
"COM API
The COM API is a good way to directly access Windows Update without having to parse logs. Applications of this API range from finding available updates on the computer to installing and uninstalling updates.
You could use the Microsoft.Update.Session class to run an update search and then count the number of updates available to see if there are any updates for the computer.
PowerShell Example:
$updateObject = New-Object -ComObject Microsoft.Update.Session
$updateObject.ClientApplicationID = "Serverfault Example Script"
$updateSearcher = $updateObject.CreateUpdateSearcher()
$searchResults = $updateSearcher.Search("IsInstalled=0")
Write-Host $searchResults.Updates.Count
If the returned result is more than 0 then there are updates for the computer that need to be installed and/or downloaded. You can easily update the powershell script to fit your application.
Just a heads up, it appears that the search function is not async so it would freeze your application while searching. In that case you will want to make it async."
Registry method
Source:
https://serverfault.com/questions/891188/is-it-possible-to-detect-the-windows-update-status-via-registry-to-see-if-the-s
I get the following error after upgrading via Migration Assistant my laptop from a 2-core to a 4-core processor:
cpum#1: X86_CPUID_FEATURE_ECX_MOVBE is not supported by the host but
has already exposed to the guest [ver=17 pass=final]
(VERR_SSM_LOAD_CPUID_MISMATCH).
How can i resolve the same?
The solution may be as simple as clicking the big yellow "Discard" button, which will delete the saved state (same as pulling the power cord).
Reference: https://forums.virtualbox.org/viewtopic.php?f=6&t=19351
For people working via a terminal.
The accepted answer correctly mentions to discard the current state of the VM. This basically means pull the power cord, so that the next time you start it, the machine reboots.
You can do this using
VBoxManage discardstate "your machine's name"
Click on the name of the virtual machine, right click on the menu and discard saved status
The Discard button worked for me. Thanks #Justin!
I've been chasing this exact error message off and on for months (fortunately my VM is not part of my daily work). The whole time I thought that it was an issue of being on a new CPU (based on CPUID_MISMATCH) so I was looking at how to move a VM from one CPU to another and how to change the expected CPUID. But everything I found in that searching required that you save and shut down properly on the original CPU, which I no longer have.
Simply "Discard"-ing the "Current State (changed)" version worked for me on all of my saved machines.
Whoda thunk that the fix for a virtual Windows machine was a hard reboot? Not like that works for hardware-based Windows boxes, right? ;-) I guess that's why they call rebooting "the Windows Panacea".
Thanks again.
I'm developing a server application that preforms various (probably hundreds to thousands) of MySQL Queries a day (SELECTS, INSERTS, & UPDATES).
The querying works great, until....
For some reason after the Server has been up for roughly 1 to 2 days it generates a MySQL Error any time I try to preform any MySQL Query from the Server... The Server was developed using C++.
The error says that The MySQL Client has run out of memory.
I'm Using
MySQL Community Server 5.6.24
Is there some kind of hidden cache of data stored in memory that I don't know about that gets occupied anytime a MySQL Query gets executed....? That's the only thing I can think of.
This is probably related to the queries you're using.
Indexing can help as well as limiting the results returned from these queries.
I'm guessing you're loading a certain amount of data using SELECT commands and the returned values need to be stored somewhere, which is the memory.
http://dev.mysql.com/doc/refman/5.7/en/out-of-memory.html
This link offers some possible solutions.
To remedy the problem, first check whether your query is correct. Is it reasonable that it should return so many rows? If not, correct the query and try again. Otherwise, you can invoke mysql with the --quick option. This causes it to use the mysql_use_result() C API function to retrieve the result set, which places less of a load on the client (but more on the server).
Also if you have enough RAM you could try to increase the memory limit in the config file.
To be more specific this is what you want to adjust:
InnoDB Settings
innodb_buffer_pool_size - Defaults to 128M. This is the main setting you want to change, since it sets how much memory InnoDB will use for data+indexes loaded into memory. For a dedicated MySQL server, the recommended size is 50-80% of installed memory. So for example, a server with 64G of RAM should have around a 50G buffer pool.
The danger of setting this value too high is that there will be no memory left for the operating system and some MySQL-subsystems that rely on filesystem cache such as binary logs, and InnoDB's transaction logs.
Taken from:
http://www.tocker.ca/2013/09/17/what-to-tune-in-mysql-56-after-installation.html
Another possibility is that something in the c++ code is not allocating the memory and after it's done deallocating the memory properly.
Another thing that could be leaking is connections. Database connections are very expensive, and hang around. I googled "mysql connection pooling". If you're using Connector/J, you could look at http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-j2ee-concepts-connection-pooling.html, and if you're using connector/net you could try http://dev.mysql.com/doc/connector-net/en/connector-net-programming-connection-pooling.html.
I'm coding using C++ with WinAPIs, and to hibernate the computer I use the following call:
SetSuspendState(TRUE, NULL, FALSE);
But what happens is that if the computer has larger RAM array installed the hibernation fails.
So I was wondering, does Windows send any notifications if hibernation fails? And if not, how to tell if my request to hibernate failed?
Looks like there's no direct way to detect hibernation [CORRECTION: I was wrong about this. See Fowl's answer.] until Windows 8 (see PowerRegisterSuspendResumeNotification). But I suppose you could idle-loop and watch the system time. If the time suddenly jumps forwards, you've successfully hibernated (and resumed!) and if this hasn't happened within a minute or so the request probably failed. I think you can use the GetTickCount64 function, which is insensitive to system time changes but apparently includes a bias for time spent sleeping. If this doesn't work, use GetSystemTimeAsFileTime but also watch for WM_TIMECHANGE messages.
You could also check on the system in question whether Windows writes anything to the event log when hibernation fails. If so, your application could monitor the event log for the relevant entry. This would be a more reliable approach.
Register for (RegisterPowerSettingNotification), then listen for WM_POWERBROADCAST, and then interrogate the event log to get more detail.
There's a bit of messing around if you want to handle multiple OS versions, but it's doable.
Hm... maybe I'm missing the point here, but according to the docs it should return FALSE if it failed. Does it still return TRUE in your case?
I would like to do some microbenchmarks, and try to do them right. Unfortunately dynamic frequency scaling makes benchmarking highly unreliable.
Is there a way to programmatically (C++, Windows) find out if dynamic frequency scaling is enabled? If, can this be disabled in a program?
Ive tried to just use a warmup phase that uses 100% CPU for a second before the actual benchmark takes place, but this turned out to be not reliable either.
UPDATE: Even when I disable SpeedStep in the BIOS, cpu-z shows that the frequency changes between 1995 and 2826 GHz
In general, you need to do the following steps:
Call CallNtPowerInformation() and pass SystemPowerCapabilities to InformationLevel parameter, set lpInputBuffer and nInputBufferSize to NULL, then set lpOutputBuffer to SYSTEM_POWER_CAPABILITIES structure, and set nOutputBufferSize to the size of the structure. After this first call, SYSTEM_POWER_CAPABILITIES structure containing the current system power capabilities. To check whether the system supports processor throttling, read the value of ProcessorThrottle.
There are other two members we are interested in, they are, ProcessorMinThrottle and ProcessorMaxThrottle; they represents the minimum and maximum level of system processor throttling supported, expressed as a percentage. If both members has already values 100%, this means CPU throttling is currently disabled, so you don't need to reconfigure it.
To disable CPU throttling, you need to set ProcessorMinThrottle and ProcessorMaxThrottle to 100%. To do this, call CallNtPowerInformation() again and pass SystemPowerCapabilities to InformationLevel parameter; but now, set lpInputBuffer to the SYSTEM_POWER_CAPABILITIES structure in which the two members has been set to 100%. I'm sure you know what to do next.
In non-programmatic way, you can also get/set Windows Power Options using the Windows built-in command-line tools, that is, PowerCfg.
Further Reading
Power Management
Power Management Functions
So far, none of the above CallNtPowerInformation options worked for me. The relevant ProcessorThrottle field of SYSTEM_POWER_CAPABILITIES was FALSE and changing some SYSTEM_POWER_POLICYs didn't work.
However, https://www.geeks3d.com/20170213/how-to-disable-intel-turbo-boost-technology-on-a-notebook/#_24 outlines a way to make an option available in the power management settings.
With ProcMon, I was able to trace it back to the following registry manipulations:
Read the ActivePowerScheme SZ value under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes to get the active power plan
Set the ACSettingIndex and/or DCSettingIndex DWORD under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\<above active power plan GUID>\54533251-82be-4824-96c1-47b60b740d00\be337238-0d82-4146-a960-4f3749d470c7 to 0 (Disabled, or whatever you choose) from 2 (High)
Unfortunately, the relevant keys are owned by the system, which either means you have to prompt the user (which has to have admin access) to change the permissions of the key or you have to use powercfg to manipulate the setting. The latter is preferrable and actually seems to work, even without admin access (courtesy of https://learn.microsoft.com/en-us/windows-server/administration/performance-tuning/hardware/power/power-performance-tuning#processor-performance-boost-mode):
powercfg -setacvalueindex scheme_current sub_processor PERFBOOSTMODE 0
powercfg -setdcvalueindex scheme_current sub_processor PERFBOOSTMODE 0
powercfg -setactive scheme_current
In Windows XP and later CPU speed is managed by power policy. Doesn't it turn off the scaling if you set "Max performance" mode in Windows power management dialog?
There're also some third party tools - SpeedSwitchXP for example.
Programmatically this could be done, I suppose, using CallNtPowerInformation function.