Skip to content

Commit f5d57bf

Browse files
committed
Address review feedback
1 parent fd37a13 commit f5d57bf

File tree

1 file changed

+78
-78
lines changed

1 file changed

+78
-78
lines changed
Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "How To Audit Visual C++ Runtime Version Usage"
2+
title: "cpp-redist-version-auditing"
33
description: "This article provides a detailed guide for auditing usage of Visual C++ Runtime versions within your organization."
44
ms.date: 12/2/2024
55
helpviewer_keywords:
@@ -15,13 +15,13 @@ ms.author: msaleh
1515

1616
The Microsoft Visual C++ Redistributable and the Visual C++ Studio Runtime (collectively, "VC Runtime") is a critical component to thousands of applications. Across your enterprise network, machines may still be running applications that install and use an out-of-support version of the VC Runtime. NTFS File Auditing can be used to identify such usage as a step towards helping you replace these applications with ones that take a dependency on a supported version of the VC Runtime. This guide will walk you through setting up NTFS File Auditing, provide troubleshooting tips, and highlight the benefits of regular audits.
1717

18-
For details on the versions of VC Runtime no longer supported, see [Microsoft Visual C++ Redistributable latest supported downloads](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist).
18+
For details on the versions of VC Runtime no longer supported, see [Microsoft Visual C++ Redistributable latest supported downloads](/cpp/windows/latest-supported-vc-redist).
1919

2020
## Enabling NTFS File Auditing to determine usage of VC Runtime
2121

2222
NTFS File Auditing can be used to determine which process is calling VC Runtime files. You can use this information on machines with legacy versions of the VC Runtime already installed to determine which applications are calling the unsupported versions of the VC Runtime.
2323

24-
This guide will first provide steps to manually enable NTFS File Auditing and review logs. Because there are several component files that can be used by an application, this guide also provides and recommends that you use PowerShell's [Get-Acl](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-acl?view=powershell-5.1) and [Set-Acl](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-acl?view=powershell-5.1) cmdlets to update Auditing permissions. For details on how to configure the audit policies on a file, see [Apply a basic audit policy on a file or folder.](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/apply-a-basic-audit-policy-on-a-file-or-folder)
24+
This guide will first provide steps to manually enable NTFS File Auditing and review logs. Because there are several component files that can be used by an application, this guide also provides and recommends that you 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 details on how to configure the audit policies on 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)
2525

2626
### Manually enable object access auditing on the system
2727

@@ -34,8 +34,8 @@ Object access must be enabled before you enable file level auditing.
3434

3535
Alternatively, you may use auditpol.exe to enable object access.
3636

37-
1. List the current settings with AuditPol.exe /get /category:"Object Access".
38-
2. Enable/Disable with AuditPol.exe /set /category:"Object Access" /subcategory:"File System" /success:enable.
37+
1. List the current settings with `AuditPol.exe /get /category:"Object Access"`.
38+
2. Enable/Disable with `AuditPol.exe /set /category:"Object Access" /subcategory:"File System" /success:enable`.
3939

4040
### Manually enable auditing on a file
4141

@@ -63,78 +63,78 @@ The audit rule is enabled now.
6363

6464
### Manually review audit logs
6565

66-
NTFS File Auditing will generate [_Event 4663: An attempt was made to access an object_](https://learn.microsoft.com/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4663) for each file that includes + audit permission and the+ process accessing process namethe file.
66+
NTFS File Auditing will generate ["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 + audit permission and the+ process accessing process namethe file.
6767

68-
1. Open Event Viewer: Press Windows + R, type eventvwr.msc, and press Enter.
68+
1. Open Event Viewer: Press Windows + R, type `eventvwr.msc`, and press Enter.
6969

7070
2. Navigate to Security Logs: In the Event Viewer, expand Windows Logs and select Security. The results pane lists individual security events.
7171

7272
3. Filter and Analyze the Logs: Use the Filter Current Log option to narrow down the events to Event ID 4663 (Audit Success for the File System Category).
7373

74-
For an example of a File Access Auditing Event 4663, see [4663(S): An attempt was made to access an object.](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4663)
74+
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)
7575

7676
![Event Viewer showing security logs](media/windows-events.png)
7777

7878
### Using PowerShell to enable auditing of VC Runtime usage
7979

8080
The general workflow for updating the File Auditing Permissions with PowerShell is as follows:
8181

82-
1. Define the [file system audit rule](https://learn.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.filesystemauditrule.-ctor) to be applied to the file(s).
82+
1. Define the [file system audit rule](/dotnet/api/system.security.accesscontrol.filesystemauditrule.-ctor) to be applied to the file(s).
8383

84-
2. Obtain a file's security descriptor with [Get-Acl](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-acl?view=powershell-5.1).
84+
2. Obtain a file's security descriptor with [Get-Acl](/powershell/module/microsoft.powershell.security/get-acl).
8585

86-
3. [Apply the audit rule](https://learn.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.filesystemsecurity.setaccessrule) to the security descriptor.
86+
3. [Apply the audit rule](/dotnet/api/system.security.accesscontrol.filesystemsecurity.setaccessrule) to the security descriptor.
8787

88-
4. Apply the updated security descriptor on the original file with [Set-Acl](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-acl?view=powershell-5.1).
88+
4. Apply the updated security descriptor on the original file with [Set-Acl](/powershell/module/microsoft.powershell.security/set-acl).
8989

90-
5. View File Access Auditing Event 4663 records with [Get-WinEvent](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-winevent?view=powershell-5.1).
90+
5. View File Access Auditing Event 4663 records with [Get-WinEvent](/powershell/module/microsoft.powershell.diagnostics/get-winevent).
9191

9292
### PowerShell: Enable auditing on out-of-support VC Runtime files
9393

9494
The following PowerShell section of code will enable usage auditing of the currently installed out-of-support VC Runtime files.
9595

9696
```sh
97-
function Get-AuditRuleForFile {
98-
$auditRuleArguments = 'Everyone' <# identity #>,
99-
'ExecuteFile, Traverse' <# fileSystemRights #>,
100-
'Success' <# flags #>
101-
$auditRule = New-Object System.Security.AccessControl.FileSystemAuditRule($auditRuleArguments)
102-
103-
return $auditRule
104-
}
105-
106-
function Set-FileAuditRule {
107-
param (
108-
[Parameter(Mandatory = $true)]
109-
[ValidateNotNullOrEmpty()]
110-
[string]$file,
111-
[Parameter(Mandatory = $true)]
112-
[ValidateNotNullOrEmpty()]
113-
[System.Security.AccessControl.FileSystemAuditRule]$auditRule
114-
)
115-
116-
$existingAcl = Get-Acl -Path $file
117-
$existingAcl.AddAuditRule($auditRule) | Out-Null
118-
Set-Acl -Path $file -AclObject $existingAcl
119-
}
120-
121-
$newAuditRule = Get-AuditRuleForFile
122-
123-
# Visual Studio Redistributable for 2005 (VC++ 8.0) and 2008 (VC++ 9.0)
124-
Get-ChildItem "$ENV:SystemRoot\WinSxS\Fusion" -filter '*.dll' -ErrorAction SilentlyContinue -Recurse |
125-
Where-Object FullName -IMatch 'microsoft\.vc[89]0' |
126-
ForEach-Object {
127-
Set-FileAuditRule $_.FullName $newAuditRule
128-
}
129-
130-
# Visual Studio Redistributable for 2010 (VC++ 10.0), 2012 (VC++ 11.0) and 2013 (VC++ 12.0)
131-
$languageCodes = 'chs|cht|deu|enu|esn|fra|ita|jpn|kor|rus'
132-
$versions = '(1[012]0)'
133-
$regex = "^((atl|msvc[pr]|vcamp|vccorlib|vcomp)$versions|mfc$versions(u|$languageCodes)?|mfcm$versions(u)?)\.dll$"
134-
Get-ChildItem "$ENV:SystemRoot\SysWOW64","$ENV:SystemRoot\System32" -filter '*.dll' |
135-
Where-Object Name -imatch $regex |
136-
ForEach-Object {
137-
Set-FileAuditRule $_.FullName $newAuditRule
97+
function Get-AuditRuleForFile {
98+
$auditRuleArguments = 'Everyone' <# identity #>,
99+
'ExecuteFile, Traverse' <# fileSystemRights #>,
100+
'Success' <# flags #>
101+
$auditRule = New-Object System.Security.AccessControl.FileSystemAuditRule($auditRuleArguments)
102+
103+
return $auditRule
104+
}
105+
106+
function Set-FileAuditRule {
107+
param (
108+
[Parameter(Mandatory = $true)]
109+
[ValidateNotNullOrEmpty()]
110+
[string]$file,
111+
[Parameter(Mandatory = $true)]
112+
[ValidateNotNullOrEmpty()]
113+
[System.Security.AccessControl.FileSystemAuditRule]$auditRule
114+
)
115+
116+
$existingAcl = Get-Acl -Path $file
117+
$existingAcl.AddAuditRule($auditRule) | Out-Null
118+
Set-Acl -Path $file -AclObject $existingAcl
119+
}
120+
121+
$newAuditRule = Get-AuditRuleForFile
122+
123+
# Visual Studio Redistributable for 2005 (VC++ 8.0) and 2008 (VC++ 9.0)
124+
Get-ChildItem "$ENV:SystemRoot\WinSxS\Fusion" -filter '*.dll' -ErrorAction SilentlyContinue -Recurse |
125+
Where-Object FullName -IMatch 'microsoft\.vc[89]0' |
126+
ForEach-Object {
127+
Set-FileAuditRule $_.FullName $newAuditRule
128+
}
129+
130+
# Visual Studio Redistributable for 2010 (VC++ 10.0), 2012 (VC++ 11.0) and 2013 (VC++ 12.0)
131+
$languageCodes = 'chs|cht|deu|enu|esn|fra|ita|jpn|kor|rus'
132+
$versions = '(1[012]0)'
133+
$regex = "^((atl|msvc[pr]|vcamp|vccorlib|vcomp)$versions|mfc$versions(u|$languageCodes)?|mfcm$versions(u)?)\.dll$"
134+
Get-ChildItem "$ENV:SystemRoot\SysWOW64","$ENV:SystemRoot\System32" -filter '*.dll' |
135+
Where-Object Name -imatch $regex |
136+
ForEach-Object {
137+
Set-FileAuditRule $_.FullName $newAuditRule
138138
}
139139
```
140140

@@ -145,30 +145,30 @@ PowerShell provides Get-WinEvent to obtain event records for various event logs.
145145
The following PowerShell section of code will list all of the Auditing Event 4663 records over the past 24 hours.
146146

147147
```sh
148-
function Get-AuditEntries {
149-
param (
150-
[Parameter(Mandatory = $true)]
151-
[ValidateNotNullOrEmpty()]
152-
[System.DateTime]$oldestTime
153-
)
154-
Get-WinEvent -FilterHashtable @{LogName='Security';Id=4663;StartTime=(Get-Date $oldestTime)} |
155-
ForEach-Object {
156-
$record = [ordered]@{}
157-
$record['TimeCreated'] = $_.TimeCreated
158-
$accessName = ($_.Message |
159-
Select-String -Pattern "Accesses:[\t\s]+(?<Accesses>.+)").Matches.Groups[1]
160-
([xml]$_.ToXML()).Event.EventData.ChildNodes |
161-
ForEach-Object -Begin {
162-
$record[$accessName.Name]=$accessName.Value.Trim()
163-
} -Process {
164-
$record[$_.Name] = $_.'#text'
165-
}
166-
[PSCustomObject]$record
167-
} |
168-
Where-Object { $_.ObjectName -imatch '\.dll$'}
148+
function Get-AuditEntries {
149+
param (
150+
[Parameter(Mandatory = $true)]
151+
[ValidateNotNullOrEmpty()]
152+
[System.DateTime]$oldestTime
153+
)
154+
Get-WinEvent -FilterHashtable @{LogName='Security';Id=4663;StartTime=(Get-Date $oldestTime)} |
155+
ForEach-Object {
156+
$record = [ordered]@{}
157+
$record['TimeCreated'] = $_.TimeCreated
158+
$accessName = ($_.Message |
159+
Select-String -Pattern "Accesses:[\t\s]+(?<Accesses>.+)").Matches.Groups[1]
160+
([xml]$_.ToXML()).Event.EventData.ChildNodes |
161+
ForEach-Object -Begin {
162+
$record[$accessName.Name]=$accessName.Value.Trim()
163+
} -Process {
164+
$record[$_.Name] = $_.'#text'
165+
}
166+
[PSCustomObject]$record
167+
} |
168+
Where-Object { $_.ObjectName -imatch '\.dll$'}
169169
}
170170

171-
Get-AuditEntries -oldestTime (Get-Date).AddHours(-24)
171+
Get-AuditEntries -oldestTime (Get-Date).AddHours(-24)
172172
```
173173
174174
Example output from the above block of code is as follows:
@@ -195,7 +195,7 @@ ResourceAttributes : S:AI
195195
196196
After you have determined which processes are using the VC Runtime files or installing the VC Redistributable, uninstall those applications or upgrade them to newer versions that do not depend on unsupported VC Runtimes.
197197
198-
Note that some Microsoft applications do require legacy versions of the VC Runtime. For details, see [Visual C++ Redistributable and runtime libraries FAQ | Microsoft Learn](https://learn.microsoft.com/lifecycle/faq/visual-c-faq).
198+
Note that some Microsoft applications do require legacy versions of the VC Runtime. For details, see [Visual C++ Redistributable and runtime libraries FAQ | Microsoft Learn](/lifecycle/faq/visual-c-faq).
199199
200200
<a id="vcruntime_install_location"></a>
201201
@@ -215,4 +215,4 @@ The following section lists where each version of the VC Runtime component files
215215
216216
* [Redistributing Visual C++ Files](redistributing-visual-cpp-files.md)
217217
* [The latest supported Visual C++ downloads](latest-supported-vc-redist.md)
218-
* [Lifecycle FAQ - Visual C++ Redistributable and runtime libraries](https://learn.microsoft.com/en-us/lifecycle/faq/visual-c-faq)
218+
* [Lifecycle FAQ - Visual C++ Redistributable and runtime libraries](/lifecycle/faq/visual-c-faq)

0 commit comments

Comments
 (0)