Skip to content

Commit 461ffd4

Browse files
committed
Load TurnOffSystemSounds.ps1 from resource
1 parent fae02c7 commit 461ffd4

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

Main.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ static string Escape(string s)
160160
return RegistryCommand(@$"add ""{rootKey}\{subKey}\Software\Microsoft\Windows\CurrentVersion\Runonce"" /v ""{Escape(name)}"" /t REG_SZ /d ""{Escape(value)}"" /f");
161161
}
162162

163-
public static IEnumerable<string> RegistryDefaultUserCommand(Func<string, string, IEnumerable<string>> action)
163+
public delegate IEnumerable<string> RegistryDefaultUserAction(string rootKey, string subKey);
164+
165+
public static IEnumerable<string> RegistryDefaultUserCommand(RegistryDefaultUserAction action)
164166
{
165167
string rootKey = "HKU";
166168
string subKey = "DefaultUser";

UnattendGenerator.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<None Remove="resource\disable-defender-pe.cmd" />
1313
<None Remove="resource\ExtractScripts.ps1" />
1414
<None Remove="resource\GeoId.json" />
15+
<None Remove="resource\TurnOffSystemSounds.ps1" />
1516
<None Remove="resource\VBoxGuestAdditions.ps1" />
1617
<None Remove="resource\VMwareTools.ps1" />
1718
</ItemGroup>
@@ -27,6 +28,7 @@
2728
<EmbeddedResource Include="resource\Bloatware.json" />
2829
<EmbeddedResource Include="resource\known-writeable-folders.txt" />
2930
<EmbeddedResource Include="resource\TimeOffset.json" />
31+
<EmbeddedResource Include="resource\TurnOffSystemSounds.ps1" />
3032
<EmbeddedResource Include="resource\UserLocale.json" />
3133
<EmbeddedResource Include="resource\VMwareTools.ps1" />
3234
<EmbeddedResource Include="resource\VBoxGuestAdditions.ps1" />

modifier/Optimizations.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,7 @@ public override void Process()
137137
appender.Append(
138138
CommandBuilder.RegistryDefaultUserCommand((rootKey, subKey) =>
139139
{
140-
string script = $$"""
141-
New-PSDrive -PSProvider 'Registry' -Root 'HKEY_USERS' -Name 'HKU';
142-
$excludes = Get-ChildItem -LiteralPath 'HKU:\{{subKey}}\AppEvents\EventLabels' |
143-
Where-Object -FilterScript { ($_ | Get-ItemProperty).ExcludeFromCPL -eq 1; } |
144-
Select-Object -ExpandProperty 'PSChildName';
145-
Get-ChildItem -Path 'HKU:\{{subKey}}\AppEvents\Schemes\Apps\*\*' |
146-
Where-Object -Property 'PSChildName' -NotIn $excludes |
147-
Get-ChildItem -Include '.Current' | Set-ItemProperty -Name '(default)' -Value '';
148-
Remove-PSDrive -Name 'HKU';
149-
""";
140+
string script = $"$mountKey = '{subKey}';\r\n" + Util.StringFromResource("TurnOffSystemSounds.ps1");
150141
string ps1File = @"%TEMP%\sounds.ps1";
151142
AddTextFile(script, ps1File);
152143
return [

resource/TurnOffSystemSounds.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
New-PSDrive -PSProvider 'Registry' -Root 'HKEY_USERS' -Name 'HKU';
2+
$excludes = Get-ChildItem -LiteralPath "HKU:\${mountKey}\AppEvents\EventLabels" |
3+
Where-Object -FilterScript { ($_ | Get-ItemProperty).ExcludeFromCPL -eq 1; } |
4+
Select-Object -ExpandProperty 'PSChildName';
5+
Get-ChildItem -Path "HKU:\${mountKey}\AppEvents\Schemes\Apps\*\*" |
6+
Where-Object -Property 'PSChildName' -NotIn $excludes |
7+
Get-ChildItem -Include '.Current' | Set-ItemProperty -Name '(default)' -Value '';
8+
Remove-PSDrive -Name 'HKU';

0 commit comments

Comments
 (0)