Skip to content

Commit c06ff4c

Browse files
committed
Disable ‘LockedStartLayout’ registry value via scheduled task
#139 #142
1 parent fb01d81 commit c06ff4c

File tree

5 files changed

+91
-6
lines changed

5 files changed

+91
-6
lines changed

Main.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,15 @@ string ToPrettyString()
10871087
AddFile(ToPrettyString(), path, ContentTransformation.Text);
10881088
}
10891089

1090+
public string AddXmlFile(string xml, string name)
1091+
{
1092+
string path = $@"C:\Windows\Setup\Scripts\{name}";
1093+
var doc = new XmlDocument();
1094+
doc.LoadXml(xml);
1095+
AddXmlFile(doc, path);
1096+
return path;
1097+
}
1098+
10901099
public string AddXmlFile(string resourceName)
10911100
{
10921101
string path = $@"C:\Windows\Setup\Scripts\{resourceName}";

UnattendGenerator.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<EmbeddedResource Include="resource\KeyboardIdentifier.json" />
4141
<EmbeddedResource Include="resource\Bloatware.json" />
4242
<EmbeddedResource Include="resource\known-writeable-folders.txt" />
43+
<EmbeddedResource Include="resource\UnlockStartLayout.xml" />
4344
<EmbeddedResource Include="resource\MoveActiveHours.xml" />
4445
<EmbeddedResource Include="resource\PauseWindowsUpdate.xml" />
4546
<EmbeddedResource Include="resource\RestartExplorer.ps1" />
@@ -51,6 +52,7 @@
5152
<EmbeddedResource Include="resource\SetWallpaper.ps1" />
5253
<EmbeddedResource Include="resource\MakeEdgeUninstallable.ps1" />
5354
<EmbeddedResource Include="resource\SetStartPins.ps1" />
55+
<EmbeddedResource Include="resource\UnlockStartLayout.vbs" />
5456
<EmbeddedResource Include="resource\ShowAllTrayIcons.vbs" />
5557
<EmbeddedResource Include="resource\ShowAllTrayIcons.ps1" />
5658
<EmbeddedResource Include="resource\RemoveBloatware.ps1" />

modifier/Optimizations.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,21 @@ public override void Process()
8080
{
8181
void SetTaskbarIcons(string xml)
8282
{
83-
string path = AddTextFile("TaskbarLayoutModification.xml", xml);
84-
SpecializeScript.Append($"""
85-
reg.exe add "HKLM\Software\Policies\Microsoft\Windows\Explorer" /v "StartLayoutFile" /t REG_SZ /d "{path}" /f;
86-
reg.exe add "HKLM\Software\Policies\Microsoft\Windows\Explorer" /v "LockedStartLayout" /t REG_DWORD /d 1 /f;
87-
reg.exe add "HKLM\Software\Policies\Microsoft\Windows\CloudContent" /v "DisableCloudOptimizedContent" /t REG_DWORD /d 1 /f;
88-
""");
83+
{
84+
string path = AddXmlFile(xml, "TaskbarLayoutModification.xml");
85+
SpecializeScript.Append($"""
86+
reg.exe add "HKLM\Software\Policies\Microsoft\Windows\CloudContent" /v "DisableCloudOptimizedContent" /t REG_DWORD /d 1 /f;
87+
""");
88+
DefaultUserScript.Append($$"""
89+
reg.exe add "HKU\DefaultUser\Software\Policies\Microsoft\Windows\Explorer" /v "StartLayoutFile" /t REG_SZ /d "{{path}}" /f;
90+
reg.exe add "HKU\DefaultUser\Software\Policies\Microsoft\Windows\Explorer" /v "LockedStartLayout" /t REG_DWORD /d 1 /f;
91+
""");
92+
}
93+
{
94+
AddTextFile("UnlockStartLayout.vbs");
95+
string path = AddXmlFile("UnlockStartLayout.xml");
96+
SpecializeScript.Append($@"Register-ScheduledTask -TaskName 'UnlockStartLayout' -Xml $( Get-Content -LiteralPath '{path}' -Raw );");
97+
}
8998
}
9099

91100
switch (Configuration.TaskbarIcons)

resource/UnlockStartLayout.vbs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
HKU = &H80000003
2+
Set reg = GetObject("winmgmts://./root/default:StdRegProv")
3+
Set fso = CreateObject("Scripting.FileSystemObject")
4+
5+
If reg.EnumKey(HKU, "", sids) = 0 Then
6+
If Not IsNull(sids) Then
7+
For Each sid In sids
8+
If reg.GetStringValue(HKU, sid + "\Volatile Environment", "USERPROFILE", userprofile) = 0 Then
9+
Set folder = fso.GetFolder(userprofile)
10+
If DateDiff("s", folder.DateCreated, Now) > 30 Then
11+
reg.SetDWORDValue HKU, sid + "\Software\Policies\Microsoft\Windows\Explorer", "LockedStartLayout", 0
12+
End If
13+
End If
14+
Next
15+
End If
16+
End If

resource/UnlockStartLayout.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
2+
<Triggers>
3+
<BootTrigger>
4+
<Repetition>
5+
<Interval>PT2M</Interval>
6+
<StopAtDurationEnd>false</StopAtDurationEnd>
7+
</Repetition>
8+
<Enabled>true</Enabled>
9+
</BootTrigger>
10+
<RegistrationTrigger>
11+
<Repetition>
12+
<Interval>PT2M</Interval>
13+
<StopAtDurationEnd>false</StopAtDurationEnd>
14+
</Repetition>
15+
<Enabled>true</Enabled>
16+
</RegistrationTrigger>
17+
</Triggers>
18+
<Principals>
19+
<Principal id="Author">
20+
<UserId>S-1-5-18</UserId>
21+
<RunLevel>LeastPrivilege</RunLevel>
22+
</Principal>
23+
</Principals>
24+
<Settings>
25+
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
26+
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
27+
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
28+
<AllowHardTerminate>true</AllowHardTerminate>
29+
<StartWhenAvailable>false</StartWhenAvailable>
30+
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
31+
<IdleSettings>
32+
<StopOnIdleEnd>true</StopOnIdleEnd>
33+
<RestartOnIdle>false</RestartOnIdle>
34+
</IdleSettings>
35+
<AllowStartOnDemand>true</AllowStartOnDemand>
36+
<Enabled>true</Enabled>
37+
<Hidden>false</Hidden>
38+
<RunOnlyIfIdle>false</RunOnlyIfIdle>
39+
<WakeToRun>false</WakeToRun>
40+
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
41+
<Priority>7</Priority>
42+
</Settings>
43+
<Actions Context="Author">
44+
<Exec>
45+
<Command>C:\Windows\System32\wscript.exe</Command>
46+
<Arguments>C:\Windows\Setup\Scripts\UnlockStartLayout.vbs</Arguments>
47+
</Exec>
48+
</Actions>
49+
</Task>

0 commit comments

Comments
 (0)