Windows API equivalent to "WMIC QFE Get" - windows

I am a newbie in C++ and currently working to get Windows Hotfix/Patch information in C++ DLL.
I have evaluated the following ways:
By executing a sub process in C++ code and running wmic qfe get and read all the data.
By using the C++ APIs to initialize COM, Connect to Wbem and execute select * from win32_quickfixengineering query.
Apart from above two methods,
Is there any direct Windows API that does all the job for me and gives the list of KB Info currently installed on the machine?

You can use the Windows Update Agent API and the IUpdateSearcher interface.

Related

Difference between WUA IUpdateSearcher and wmic qfe

I am trying to figure out what are the differences between WUA (Windows Update Agent API) IupdateSearcher and wmic qfe list.
When I use WUA IupdateSearcher I get these updates:
(New-Object -ComObject Microsoft.Update.Session).CreateUpdateSearcher().Search('IsInstalled=1').Updates | Format-Table -AutoSize
And when using wmic qfe list:
wmic qfe list brief
The latter includes updates that the former doesn't and vice versa. Why is that?
For example, KB5007273 appears on wmic but doesn't appear on WUA
and vice versa, for example, KB4023057 appears on WUA but doesn't appear on wmic
This post (Windows Update Agents Vs WMIC QFE GET) from #RRUZ should get you started:
WMIC QFE GET command is equivalent to execute a query with the
Win32_QuickFixEngineering WMI class, since with Windows Vista, this
class returns only the updates supplied by Component Based Servicing,
in olders windows versions uses the
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix
and HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates registry keys to
enumerate the updates.
The IUpdateSearcher interface which is part of the Windows Update
Agent API (WUA), can be used to enumerate all the fixes including the
installed via the CBS, Updates supplied by Microsoft Windows Installer
(MSI) or the Windows update site, and so on.
And to get a deeper dive, check this article search for installed windows updates using Delphi, WMI and WUA shown in this post Windows API equivalent to "WMIC QFE Get" by #RRUZ:
WMI (Windows Management Instrumentation) using the
Win32_QuickFixEngineering class, you can retrieve a small system-wide
update, commonly referred to as a quick-fix engineering (QFE) update.
Starting with Windows Vista, the Win32_QuickFixEngineering class
returns only the updates supplied by Component Based Servicing (CBS),
so some updates are not listed.
WUA (Windows Update Agent) using the Windows Update Agent API is a
best option to retrieve the list of updates, you can access the
interfaces and objects from this API from delphi importing the
wuapi.dll file or creating a late-binding com object using the
Microsoft.Update.Session GUID. the next samples uses the late-binding
way.
Additionally for people searching for the way to get all installed updates in the system, which would work for a very wide range of Windows Server Versions (WS 2003 to WS2022 - PS 1.0 or higher) you will need to query both QFE and WUA updates. This might get you duplicate updates so you just got to parse those out.

How to check if a given KB is installed on Windows?

Is there a way to check if a given KB is installed on Windows? Specifically, I'd like to find out if KB2999226 is installed on Windows Server 2012 R2.
Thanks.
As already mentioned in the comment section of the question, you need to explore the Windows Update Agent API to exactly achieve this.
To search for an update say KBDDDDDDD using cmd, you can use the following:
wmic qfe get hotfixid | find "KBDDDDDDD"
You can directly call this query in C++ with the help of system() function. Please check this post to know about how to Execute CMD commands using C++.

cannot create windows cluster file share using powershell/wmi

The win32_clustershare does not have a Create method on win2008r2? How does one create file shares using ideally wmi?
I thought the Win32_ClusterShare class was read only, but could be mistaken.
To do it without WMI, you can use the cmdlets in the FailoverClusters module, but you'll probably have to install Windows Management Framework 3 or (preferably) WMF 4 on your Windows 2008 R2 machine since these cmdlets aren't available in Powershell 2.0.
With 3.0+, you should be able to use Add-ClusterResource and the related cmdlets.
Apparently the win32_clustershare.create does not work as expected and is broken. Previously this class was absent altogether from windows as indicated here-
http://support.microsoft.com/kb/971403
Apparently Using win32_share does the needful even for clusters. I confirmed in HKLM\Cluster\Resources that the share is properly registered in the cluster.
Apparently windows is able to determine that the share upon creation is properly associated with a clustered disk.
I know I am not calling the win32_clustershare wrong, because I confirmed that the parameters are identical across the 2 wmi classes.
This is evident in inspecting both
(get-cimclass -ClassName win32_share).CimClassMethods["Create"].Parameters |fl *
(get-cimclass -ClassName win32_clustershare).CimClassMethods["Create"].Parameters |fl *
If you are using Windows Server 2012 R2/Windows 8.1, you can use the new and much improved SMB PowerShell modules. Have a look at https://technet.microsoft.com/en-us/library/jj635726(v=wps.630).aspx and http://windowsitpro.com/powershell/managing-file-shares-windows-powershell

How to run a Metro-App from PowerShell on Windows 8?

Related to another question on Superuser, I'm trying to run a Metro based application from the command-line. According to a comment on my superuser question, I could maybe find an answear on a PowerShell command or script. I already tried but found anything on any internet reference about PowerShell and Windows 8...
So, there is some specific way/command to call and run a Metro-style application from a PowerShell command on Windows 8?
There is no direct way to do this but there are a couple indirect ways.
vsdebuglaunchnotify, which comes with Visual Studio, can be called from PowerShell.
You could create your own exe that uses IApplicationActivationManager.
If the app is associated with any file types you could launch an associated file.
More information is covered in this thread on MSDN:
http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/8d1b0861-5903-4289-8cb8-541ddaa012fb
Here's a blog post by Powertoe that uses the IApplicationActivationManager way of doing it:
http://powertoe.wordpress.com/2012/11/02/get-a-list-of-metro-apps-and-launch-them-in-windows-8-using-powershell/
He provides code here http://poshcode.org/3740 that provides a Start-MetroApp commandlet for powershell.
Alternatively: I think some Metro Apps have protocol handlers, so that you can talk to them via a URI (e.g. "appname:dosomething") but I'm not sure how widely used this is.

Can I determine if Matlab is running as with elevated privileges in Windows?

I would like to detect if the current Matlab session is running with elevated privileges (i.e. the user started it with "Run as Administrator") under Windows. Ideally the solution would work on XP and Windows 7, but I'm happy to have two solutions if necessary.
This answer suggests that I may be able to get the information I need via the .Net external interface from Matlab (at least for Vista and later), but I'm wondering if there is a more "native" Matlab solution.
The "Matlab .NET Bridge" is for going the other way - calling Matlab from .NET. Calling .NET classes from Matlab can be done pretty directly using the .NET external interfaces support.
function out = isWindowsAdmin()
%ISWINDOWSADMIN True if this user is in admin role.
wi = System.Security.Principal.WindowsIdentity.GetCurrent();
wp = System.Security.Principal.WindowsPrincipal(wi);
out = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
That should work on any Windows version with .NET installed. The more "native" way would probably require writing a MEX to call win32 API functions, which would be more work. Works on my XP machine.

Resources