Skip to content

Commit

Permalink
Use scheduled task instead of PowerShell logon script
Browse files Browse the repository at this point in the history
  • Loading branch information
cschneegans committed Sep 22, 2024
1 parent 7b0dea1 commit ea73181
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
4 changes: 4 additions & 0 deletions UnattendGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<None Remove="resource\RemovePackages.ps1" />
<None Remove="resource\SetWallpaper.ps1" />
<None Remove="resource\ShowAllTrayIcons.ps1" />
<None Remove="resource\ShowAllTrayIcons.vbs" />
<None Remove="resource\ShowAllTrayIcons.xml" />
</ItemGroup>

<ItemGroup>
Expand All @@ -32,8 +34,10 @@
<EmbeddedResource Include="resource\known-writeable-folders.txt" />
<EmbeddedResource Include="resource\DeleteTaskbarIcons.ps1" />
<EmbeddedResource Include="resource\SetWallpaper.ps1" />
<EmbeddedResource Include="resource\ShowAllTrayIcons.vbs" />
<EmbeddedResource Include="resource\ShowAllTrayIcons.ps1" />
<EmbeddedResource Include="resource\RemoveBloatware.ps1" />
<EmbeddedResource Include="resource\ShowAllTrayIcons.xml" />
<EmbeddedResource Include="resource\TimeOffset.json" />
<EmbeddedResource Include="resource\TurnOffSystemSounds.ps1" />
<EmbeddedResource Include="resource\UserLocale.json" />
Expand Down
2 changes: 2 additions & 0 deletions modifier/Optimizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ IEnumerable<string> SetExplorerOptions(string rootKey, string subKey)
appender.Append(
CommandBuilder.InvokePowerShellScript(ps1File)
);
AddXmlFile(Util.XmlDocumentFromResource("ShowAllTrayIcons.xml"), @"C:\Windows\Setup\Scripts\ShowAllTrayIcons.xml");
AddTextFile(Util.StringFromResource("ShowAllTrayIcons.vbs"), @"C:\Windows\Setup\Scripts\ShowAllTrayIcons.vbs");
}

if (Configuration.DeleteTaskbarIcons)
Expand Down
18 changes: 6 additions & 12 deletions resource/ShowAllTrayIcons.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
reg.exe load 'HKU\DefaultUser' 'C:\Users\Default\NTUSER.DAT';

if( [System.Environment]::OSVersion.Version.Build -lt 20000 ) {
# Windows 10
reg.exe load 'HKU\DefaultUser' 'C:\Users\Default\NTUSER.DAT';
Set-ItemProperty -LiteralPath 'Registry::HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\Explorer' -Name 'EnableAutoTray' -Type 'DWord' -Value 0 -Force;
reg.exe unload 'HKU\DefaultUser';
} else {
# Windows 11
$command = 'powershell.exe -NoProfile -Command "{0}"' -f {
Set-Location -LiteralPath 'HKCU:\';
Get-Item -Path 'HKCU:\Control Panel\NotifyIconSettings\*' -ErrorAction 'SilentlyContinue' | ForEach-Object -Process {
$_ | Set-ItemProperty -Name 'IsPromoted' -Value 1 -Type 'DWord';
};
};
Set-ItemProperty -LiteralPath 'Registry::HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\Run' -Name 'ShowAllTrayIcons' -Type 'String' -Value $command -Force;
}

reg.exe unload 'HKU\DefaultUser';
Register-ScheduledTask -TaskName 'ShowAllTrayIcons' -Xml $(
Get-Content -LiteralPath "C:\Windows\Setup\Scripts\ShowAllTrayIcons.xml" -Raw;
);
}
10 changes: 10 additions & 0 deletions resource/ShowAllTrayIcons.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Set shell = CreateObject( "WScript.Shell" )
Set exec = shell.Exec( "reg.exe QUERY ""HKCU\Control Panel\NotifyIconSettings""" )
Set re = New RegExp
re.Pattern = "^HKEY_CURRENT_USER\\Control Panel\\NotifyIconSettings\\\d+$"
While Not exec.StdOut.AtEndOfStream
line = exec.StdOut.ReadLine
If re.Test( line ) Then
shell.RegWrite line + "\IsPromoted", 1, "REG_DWORD"
End If
Wend
Binary file added resource/ShowAllTrayIcons.xml
Binary file not shown.

0 comments on commit ea73181

Please sign in to comment.