假设我的系统上有一个由 Windows 安装程序放置在那里的文件,但我不确定是哪一个(在这种情况下,它是 Microsoft SQL Server 的众多子安装程序之一)。
我可以查询任何内容来将该文件与安装程序绑定,以便我可以卸载它?
答案1
我认为您无法跟踪每个单独的文件到 MSI 安装程序。但是,您可以跟踪安装位置(如果它由此注册表项中的 MSI 填充)
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\]
这里有一个脚本可以帮助您解决这个问题。
#Get MOF File Method
$mof = @'
#PRAGMA AUTORECOVER
[dynamic, provider("RegProv"),
ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),ClassContext("local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")]
class InstalledProducts {
[key] string KeyName;
[read, propertycontext("DisplayName")] string DisplayName;
[read, propertycontext("DisplayVersion")] string DisplayVersion;
[read, propertycontext("InstallDate")] string InstallDate;
[read, propertycontext("InstallLocation")] string InstallLocation;
[read, propertycontext("InstallSource")] string InstallSource;
[read, propertycontext("Publisher")] string Publisher;
[read, propertycontext("EstimatedSize")] string EstimatedSize;
[read, propertycontext("UninstallString")] string UninstallString;
[read, propertycontext("WindowsInstaller")] string WindowsInstaller;
};
[dynamic, provider("RegProv"),
ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),ClassContext("local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432node\\Microsoft\\Windows\\CurrentVersion\\Uninstall")]
class InstalledProducts32 {
[key] string KeyName;
[read, propertycontext("DisplayName")] string DisplayName;
[read, propertycontext("DisplayVersion")] string DisplayVersion;
[read, propertycontext("InstallDate")] string InstallDate;
[read, propertycontext("InstallLocation")] string InstallLocation;
[read, propertycontext("InstallSource")] string InstallSource;
[read, propertycontext("Publisher")] string Publisher;
[read, propertycontext("EstimatedSize")] string EstimatedSize;
[read, propertycontext("UninstallString")] string UninstallString;
[read, propertycontext("WindowsInstaller")] string WindowsInstaller;
};
'@
$mof | Out-file -encoding ascii $env:TMP\InstalledProductsMof.txt -Force
mofcomp.exe $env:TMP\InstalledProductsMof.txt
Get-WmiObject -Namespace root\default -class InstalledProducts | Select DisplayName,DisplayVersion,InstallDate,InstallLocation, InstallSource,Publisher,EstimatedSize,UninstallString,WindowsInstaller
# CLEAN-UP: Remove the WMI Classes you just created
Remove-WmiObject -Namespace root\default -class InstalledProducts
Remove-WmiObject -Namespace root\default -class InstalledProducts32