Skip to content

Commit 7a62985

Browse files
Merge pull request #5706 from MahmoudGSaleh/main
Add a new guide to audit vcredist installs
2 parents 08eef88 + ad49542 commit 7a62985

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
---
2+
title: "How to audit Visual C++ Runtime version usage"
3+
description: "A detailed guide for auditing Visual C++ Runtime file usage."
4+
ms.date: 1/27/2025
5+
helpviewer_keywords:
6+
[
7+
"find redist version installed",
8+
"audit redist version installation",
9+
]
10+
author: MahmoudGSaleh
11+
ms.author: msaleh
12+
---
13+
14+
# How to audit Visual C++ Runtime version usage
15+
16+
The Microsoft Visual C++ Redistributable and the Visual Studio C++ Runtime (collectively, "VC Runtime") are critical components of many applications. Across your network, machines may still be running applications that install and use an out-of-support version of the VC Runtime. You can use NTFS file auditing to identify such usage as a step towards replacing those applications with ones that use a supported version of the VC Runtime. This guide walks you through setting up NTFS file auditing, provides troubleshooting tips, and highlights the benefits of regular audits.
17+
18+
For more information about the versions of VC Runtime that are no longer supported, see [Microsoft Visual C++ Redistributable latest supported downloads](/cpp/windows/latest-supported-vc-redist).
19+
20+
## Enable NTFS file auditing to determine VC Runtime usage
21+
22+
This guide provides the steps to manually enable NTFS file auditing and review audit events to determine which applications are calling the unsupported versions of the VC Runtime. Because there are several files that can be used by an application, this guide also shows how to use PowerShell's [`Get-Acl`](/powershell/module/microsoft.powershell.security/get-acl) and [`Set-Acl`](/powershell/module/microsoft.powershell.security/set-acl) cmdlets to update auditing permissions. For more information about how to configure audit policies for a file, see [Apply a basic audit policy on a file or folder](/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/apply-a-basic-audit-policy-on-a-file-or-folder).
23+
24+
### Manually enable object access auditing on the system
25+
26+
Object access must be enabled before you enable file level auditing:
27+
28+
1. Open the **Local Group Policy Editor** by pressing `Windows` + `R` to open the **Run** dialog. Then type `gpedit.msc` and press **Enter**.
29+
1. Navigate to **Computer Configuration** > **Windows Settings** > **Security Settings** > **Advanced Audit Policy Configuration** > **System Audit Policies** > **Object Access**.
30+
1. Double-click **Audit File System**. In the **Audit File System Properties** dialog, select **Configure the following audit events** > **Success** > **OK**.
31+
1. Close the **Local Group Policy Editor**.
32+
33+
Alternatively, you may use `auditpol.exe` to enable object access:
34+
35+
1. List the current settings from the command line with `AuditPol.exe /get /category:"Object Access"`.
36+
1. Enable object access with `AuditPol.exe /set /category:"Object Access" /subcategory:"File System" /success:enable`.
37+
38+
### Manually enable auditing on a file
39+
40+
To monitor which process accesses a VC Runtime file, enable auditing on the VC Runtime file:
41+
42+
1. Right-click the file that you want to audit, select **Properties**, and then select the **Security** tab. For more information about finding installed VC Runtime files, see [VC Runtime installed locations](#vcruntime_install_location).
43+
1. Select **Advanced**.
44+
1. In the **Advanced Security Settings** dialog box, select the **Auditing** tab and then select **Continue**.
45+
1. To add a new auditing rule, select **Add**. In the **Auditing Entry** dialog, select a principal, then type the name of the user or group you want to add such as **(Everyone)**, and then select **OK**.
46+
1. In **Type**, select ensure that **Success** is selected.
47+
1. Select **Show advance permissions** > **Clear all** > **Traverse folder / execute file** > **OK**.
48+
1. There should now be a new row in the **Auditing** entries matching what you have selected. Select **OK**.
49+
1. In the **Properties** Dialog, select **OK**.
50+
51+
The audit rule is now enabled for the file.
52+
53+
### Manually review audit logs
54+
55+
NTFS file auditing generates ["Event 4663: An attempt was made to access an object"](/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4663) for each file that includes the audit permission and is accessed by a process.
56+
57+
1. Open the **Event Viewer** by pressing `Windows` + `R` to open the **Run** dialog. Then type `eventvwr.msc`, and press **Enter**.
58+
1. Navigate to the **Security** logs in the **Event Viewer** by expanding **Windows Logs** > **Security**. The results pane lists security events.
59+
1. Find the audit events by choosing **Filter Current Log...** in the **Actions** pane. Narrow down the events to **Event ID 4663 (Audit Success for the File System Category)** by entering **4663 into the Includes/Excludes Event IDs** text box.
60+
61+
For an example of a File Access Auditing Event 4663, see ["4663(S): An attempt was made to access an object."](/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4663)
62+
63+
### Use PowerShell to audit VC Runtime usage
64+
65+
As an overview, updating File Auditing Permissions with PowerShell follows these steps:
66+
67+
1. Define the [file system audit rule](/dotnet/api/system.security.accesscontrol.filesystemauditrule.-ctor) to apply to the file(s).
68+
1. Obtain a file's security descriptor with [`Get-Acl`](/powershell/module/microsoft.powershell.security/get-acl).
69+
1. [Apply the audit rule](/dotnet/api/system.security.accesscontrol.filesystemsecurity.setaccessrule) to the security descriptor.
70+
1. Apply the updated security descriptor on the original file with [`Set-Acl`](/powershell/module/microsoft.powershell.security/set-acl).
71+
1. View File Access Auditing Event 4663 records with [`Get-WinEvent`](/powershell/module/microsoft.powershell.diagnostics/get-winevent).
72+
73+
### PowerShell: Audit out-of-support VC Runtime files
74+
75+
The following PowerShell code enables you to audit installed VC Runtime files that are no longer supported.
76+
77+
```powershell
78+
function Get-AuditRuleForFile {
79+
$auditRuleArguments = 'Everyone' <# identity #>,
80+
'ExecuteFile, Traverse' <# fileSystemRights #>,
81+
'Success' <# flags #>
82+
$auditRule = New-Object System.Security.AccessControl.FileSystemAuditRule($auditRuleArguments)
83+
84+
return $auditRule
85+
}
86+
87+
function Set-FileAuditRule {
88+
param (
89+
[Parameter(Mandatory = $true)]
90+
[ValidateNotNullOrEmpty()]
91+
[string]$file,
92+
[Parameter(Mandatory = $true)]
93+
[ValidateNotNullOrEmpty()]
94+
[System.Security.AccessControl.FileSystemAuditRule]$auditRule
95+
)
96+
97+
$existingAcl = Get-Acl -Path $file
98+
$existingAcl.AddAuditRule($auditRule) | Out-Null
99+
Set-Acl -Path $file -AclObject $existingAcl
100+
}
101+
102+
$newAuditRule = Get-AuditRuleForFile
103+
104+
# Visual Studio Redistributable for 2005 (VC++ 8.0) and 2008 (VC++ 9.0)
105+
Get-ChildItem "$ENV:SystemRoot\WinSxS\Fusion" -filter '*.dll' -ErrorAction SilentlyContinue -Recurse |
106+
Where-Object FullName -IMatch 'microsoft\.vc[89]0' |
107+
ForEach-Object {
108+
Set-FileAuditRule $_.FullName $newAuditRule
109+
}
110+
111+
# Visual Studio Redistributable for 2010 (VC++ 10.0), 2012 (VC++ 11.0) and 2013 (VC++ 12.0)
112+
$languageCodes = 'chs|cht|deu|enu|esn|fra|ita|jpn|kor|rus'
113+
$versions = '(1[012]0)'
114+
$regex = "^((atl|msvc[pr]|vcamp|vccorlib|vcomp)$versions|mfc$versions(u|$languageCodes)?|mfcm$versions(u)?)\.dll$"
115+
Get-ChildItem "$ENV:SystemRoot\SysWOW64","$ENV:SystemRoot\System32" -filter '*.dll' |
116+
Where-Object Name -imatch $regex |
117+
ForEach-Object {
118+
Set-FileAuditRule $_.FullName $newAuditRule
119+
}
120+
```
121+
122+
### PowerShell: View file audit events
123+
124+
PowerShell provides `Get-WinEvent` to get event records for various event logs as shown in the following PowerShell code that lists all of the Auditing Event 4663 records over the past 24 hours:
125+
126+
```powershell
127+
function Get-AuditEntries {
128+
param (
129+
[Parameter(Mandatory = $true)]
130+
[ValidateNotNullOrEmpty()]
131+
[System.DateTime]$oldestTime
132+
)
133+
Get-WinEvent -FilterHashtable @{LogName='Security';Id=4663;StartTime=(Get-Date $oldestTime)} |
134+
ForEach-Object {
135+
$record = [ordered]@{}
136+
$record['TimeCreated'] = $_.TimeCreated
137+
$accessName = ($_.Message |
138+
Select-String -Pattern "Accesses:[\t\s]+(?<Accesses>.+)").Matches.Groups[1]
139+
([xml]$_.ToXML()).Event.EventData.ChildNodes |
140+
ForEach-Object -Begin {
141+
$record[$accessName.Name]=$accessName.Value.Trim()
142+
} -Process {
143+
$record[$_.Name] = $_.'#text'
144+
}
145+
[PSCustomObject]$record
146+
} |
147+
Where-Object { $_.ObjectName -imatch '\.dll$'}
148+
}
149+
150+
Get-AuditEntries -oldestTime (Get-Date).AddHours(-24)
151+
```
152+
153+
```output
154+
TimeCreated : 11/20/2024 5:00:11 AM
155+
Accesses : Execute/Traverse
156+
SubjectUserSid : \*\*\*\*\*
157+
SubjectUserName : \*\*\*\*\*
158+
SubjectDomainName : WORKGROUP
159+
SubjectLogonId : \*\*\*\*\*
160+
ObjectServer : Security
161+
ObjectType : File
162+
ObjectName : C:\\Windows\\WinSxS\\amd64\_microsoft.vc90.crt\_1fc8b3b9a1e18e3b\_9.0.30729.9635\_none\_08e2c157a83ed5da\\msvcr90.dll
163+
HandleId : 0x93c
164+
AccessList : %%4421
165+
AccessMask : 0x20
166+
ProcessId : 0x24d4
167+
ProcessName : C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe
168+
ResourceAttributes : S:AI
169+
```
170+
171+
### Next steps after auditing VC Runtime usage
172+
173+
After you have determined which processes are using the VC Runtime files, or which applications have installed the VC Redistributable, uninstall those applications or upgrade them to newer versions that don't depend on unsupported VC Runtimes.
174+
175+
Some Microsoft applications require legacy versions of the VC Runtime. For details, see [Visual C++ Redistributable and runtime libraries FAQ | Microsoft Learn](/lifecycle/faq/visual-c-faq).
176+
177+
<a id="vcruntime_install_location"></a>
178+
179+
## VC Runtime installation locations
180+
181+
Here is where each version of the VC Runtime is installed:
182+
183+
| **Visual Studio Version**| **Installed Location(s)**|
184+
| ------------- | ------------- |
185+
| Visual Studio 2013 (VC++ 12.0) | `%SystemRoot%\\System32, %SystemRoot%\\SysWOW64` |
186+
| Visual Studio 2012 (VC++ 11.0) | `%SystemRoot%\\System32, %SystemRoot%\\SysWOW64` |
187+
| Visual Studio 2010 (VC++ 10.0) | `%SystemRoot%\\System32, %SystemRoot%\\SysWOW64` |
188+
| Visual Studio 2008 (VC++ 9.0) | `%SystemRoot%\\WinSxS\\Fusion` |
189+
| Visual Studio 2005 (VC++ 8.0) | `%SystemRoot%\\WinSxS\\Fusion` |
190+
191+
## See also
192+
193+
[Redistributing Visual C++ Files](redistributing-visual-cpp-files.md)\
194+
[The latest supported Visual C++ downloads](latest-supported-vc-redist.md)\
195+
[Lifecycle FAQ - Visual C++ Redistributable and runtime libraries](/lifecycle/faq/visual-c-faq)

docs/windows/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ items:
147147
href: ../windows/redistributing-an-atl-application.md
148148
- name: Latest Supported Visual C++ Redistributable Downloads
149149
href: ../windows/latest-supported-vc-redist.md
150+
- name: How to audit Visual C++ Runtime version usage
151+
href: ../windows/redist-version-auditing.md
150152
- name: Deployment examples
151153
expanded: false
152154
items:

0 commit comments

Comments
 (0)