0% found this document useful (0 votes)
9 views3 pages

Pin Application

The script checks for the existence of specific application paths and a registry value, exiting if any path is missing. If the registry value does not exist, it deletes the registry key, restarts Windows Explorer, and creates a new registry value along with a taskbar layout XML file. Finally, it applies registry settings to lock the start layout and ensure the taskbar is configured correctly.

Uploaded by

aron.kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Pin Application

The script checks for the existence of specific application paths and a registry value, exiting if any path is missing. If the registry value does not exist, it deletes the registry key, restarts Windows Explorer, and creates a new registry value along with a taskbar layout XML file. Finally, it applies registry settings to lock the start layout and ensure the taskbar is configured correctly.

Uploaded by

aron.kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

$Regpath = "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\

Taskband"
$regName = "DoNotDelete-Entry"
# Define paths to check
$paths = @(
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
"C:\Program Files\Google\Chrome\Application\chrome.exe",
"C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE",
"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE",
"C:\Program Files\Microsoft Office\root\Office16\POWERPNT.EXE",
"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE"
)
# Loop through each path and check if it exists
foreach ($path in $paths) {
if (-Not (Test-Path $path)) {
Write-Host "The application path '$path' does not exist. Exiting..."
exit
}
}
Write-Host "All application paths exist. Proceeding with registry check..."

# Check if the registry value exists


try {
# Attempt to retrieve the registry value
$regValue = Get-ItemProperty -Path $RegPath -Name $regName -ErrorAction Stop
Write-Host "The registry value '$regName' exists."
exit
} catch {
# If the registry value does not exist, perform cleanup
Write-Host "The registry value '$regName' does not exist. Deleting the registry
key..."
Remove-Item -Path $Regpath -Recurse -Force -ErrorAction SilentlyContinue

# Restart Windows Explorer to apply the changes


Write-Host "Restarting Windows Explorer..."
Stop-Process -Name explorer -Force

# Wait for 2 seconds before continuing


Start-Sleep -Seconds 2
Write-Host "Operation completed."
}
# Define the taskbar layout XML
$taskbar_layout =
@"
<?xml version="1.0" encoding="utf-8"?>
<LayoutModificationTemplate
xmlns="http://schemas.microsoft.com/Start/2014/LayoutModification"
xmlns:defaultlayout="http://schemas.microsoft.com/Start/2014/FullDefaultLayout"
xmlns:start="http://schemas.microsoft.com/Start/2014/StartLayout"
xmlns:taskbar="http://schemas.microsoft.com/Start/2014/TaskbarLayout"
Version="1">
<CustomTaskbarLayoutCollection PinListPlacement="Replace">
<defaultlayout:TaskbarLayout>
<taskbar:TaskbarPinList>
<taskbar:DesktopApp DesktopApplicationID="Microsoft.Windows.Explorer" />
<taskbar:DesktopApp DesktopApplicationLinkPath="C:\Program Files (x86)\Microsoft\
Edge\Application\msedge.exe" />
<taskbar:DesktopApp DesktopApplicationLinkPath="C:\Program Files\Google\Chrome\
Application\chrome.exe" />
<taskbar:DesktopApp DesktopApplicationLinkPath="C:\Program Files\Microsoft Office\
root\Office16\OUTLOOK.EXE" />
<taskbar:DesktopApp DesktopApplicationLinkPath="C:\Program Files\Microsoft Office\
root\Office16\WINWORD.EXE" />
<taskbar:DesktopApp DesktopApplicationLinkPath="C:\Program Files\Microsoft Office\
root\Office16\POWERPNT.EXE" />
<taskbar:DesktopApp DesktopApplicationLinkPath="C:\Program Files\Microsoft Office\
root\Office16\EXCEL.EXE" />
</taskbar:TaskbarPinList>
</defaultlayout:TaskbarLayout>
</CustomTaskbarLayoutCollection>
</LayoutModificationTemplate>
"@
# Prepare provisioning folder
[System.IO.FileInfo]$provisioning = "$($env:ProgramData)\provisioning\
tasbar_layout.xml"
if (!$provisioning.Directory.Exists) {
$provisioning.Directory.Create()
}
# Write the taskbar layout to the file
$taskbar_layout | Out-File $provisioning.FullName -Encoding utf8
# Define registry settings
$settings = @(
[PSCustomObject]@{
Path = "SOFTWARE\Policies\Microsoft\Windows\Explorer"
Value = $provisioning.FullName
Name = "StartLayoutFile"
Type = [Microsoft.Win32.RegistryValueKind]::ExpandString
},
[PSCustomObject]@{
Path = "SOFTWARE\Policies\Microsoft\Windows\Explorer"
Value = 1
Name = "LockedStartLayout"
}
)
# Apply the registry settings
foreach ($setting in $settings) {
$registry = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($setting.Path,
$true)
if ($null -eq $registry) {
$registry =
[Microsoft.Win32.Registry]::LocalMachine.CreateSubKey($setting.Path, $true)
}
if ($setting.Type) {
$registry.SetValue($setting.Name, $setting.Value, $setting.Type)
} else {
$registry.SetValue($setting.Name, $setting.Value)
}
$registry.Dispose()
}

Stop-process -Name explorer -force


try {
$regValue = Get-ItemProperty -Path $Regpath -Name $regName -ErrorAction Stop
Write-Host "The registry value '$regName' exists."
exit
} catch

{
Write-Host "The registry path '$Regpath' or value '$regName' does not exist.
Creating them now..."
# Create the registry path if it doesn't exist
if (-not (Test-Path $Regpath)) {
New-Item -Path $Regpath -Force | Out-Null
Write-Host "Registry path '$Regpath' created."
}
# Create the registry value
New-ItemProperty -Path $Regpath -Name $regName -Value "" -PropertyType String -
Force
Write-Host "The registry value '$regName' has been created."
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy