Spector Training
четверг, 4 декабря 2025 г.
суббота, 26 августа 2023 г.
Disable Edge Browser Initial Questions
cls
# Parameters
$registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Edge"
$registryName = "HideFirstRunExperience"
$registryValue = 1
# Function to disable Edge initial questions
function Disable-EdgeFirstRunExperience {
# Check if the registry key exists
if (-Not (Test-Path $registryPath)) {
# Create the registry key if it doesn't exist
New-Item -Path $registryPath -Force
}
# Set the registry value to disable the first-run experience
Set-ItemProperty -Path $registryPath -Name $registryName -Value $registryValue
}
# GUI Design
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.Text = "Disable Edge Initial Questions"
$form.Size = New-Object System.Drawing.Size(300,150)
$form.StartPosition = "CenterScreen"
$button = New-Object System.Windows.Forms.Button
$button.Location = New-Object System.Drawing.Point(75,40)
$button.Size = New-Object System.Drawing.Size(150,30)
$button.Text = "Disable Questions"
$button.Add_Click({
Disable-EdgeFirstRunExperience
[System.Windows.Forms.MessageBox]::Show("Edge initial questions have been disabled.", "Success")
})
$form.Controls.Add($button)
$form.ShowDialog()
Set new WINS in Windows with PoSH GUI script
It is a good GUI script which checks if the new WINS IP is the same as the previous, and checks if the IP is kosher. You can't use 1.2.3.4.5.6 or 900.900.900.900 or 10.10, for example.
cls
# Load necessary assemblies for GUI
Add-Type -AssemblyName System.Windows.Forms
# Function to get current WINS IP
Function GetCurrentWINS {
$currentWinsInfo = netsh interface ip show config "Ethernet" | Select-String "WINS"
$currentWinsIP = if ($currentWinsInfo) { ($currentWinsInfo -split ":")[1].Trim() } else { "Not Set" }
return $currentWinsIP
}
# Function to validate IP address
Function Validate-IPAddress {
param (
[string]$IPAddress
)
return ([System.Net.IPAddress]::TryParse($IPAddress, [ref]0))
}
# Initial Old WINS IP
$oldWINS = GetCurrentWINS
# Create the main form
$form = New-Object System.Windows.Forms.Form
$form.Text = "Set WINS IP Address"
$form.Size = New-Object System.Drawing.Size(400, 250)
$form.StartPosition = "CenterScreen"
$form.BackColor = [System.Drawing.Color]::LightBlue
# Create a GroupBox for Old WINS IP
$groupOld = New-Object System.Windows.Forms.GroupBox
$groupOld.Text = "Old WINS IP for adapter `Ethernet`:"
$groupOld.Location = New-Object System.Drawing.Point(10, 10)
$groupOld.Size = New-Object System.Drawing.Size(370, 50)
$form.Controls.Add($groupOld)
# Create a label for Old WINS IP address
$labelOldWINS = New-Object System.Windows.Forms.Label
$labelOldWINS.Text = $oldWINS
$labelOldWINS.AutoSize = $true
$labelOldWINS.Location = New-Object System.Drawing.Point(10, 20)
$groupOld.Controls.Add($labelOldWINS)
# Create a text box for WINS IP address input
$textBoxWINS = New-Object System.Windows.Forms.TextBox
$textBoxWINS.Location = New-Object System.Drawing.Point(10, 70)
$textBoxWINS.Size = New-Object System.Drawing.Size(260, 20)
$textBoxWINS.Text = GetCurrentWINS
$textBoxWINS.Add_KeyDown({
if ($_.KeyCode -eq 'Enter') {
$buttonSet.PerformClick()
}
})
$form.Controls.Add($textBoxWINS)
# Create a GroupBox for New WINS IP
$groupNew = New-Object System.Windows.Forms.GroupBox
$groupNew.Text = "New WINS IP for adapter `Ethernet`:"
$groupNew.Location = New-Object System.Drawing.Point(10, 100)
$groupNew.Size = New-Object System.Drawing.Size(370, 50)
$form.Controls.Add($groupNew)
# Create a label for displaying the new WINS IP
$labelNewWINS = New-Object System.Windows.Forms.Label
$labelNewWINS.AutoSize = $true
$labelNewWINS.Location = New-Object System.Drawing.Point(10, 20)
$groupNew.Controls.Add($labelNewWINS)
# Create a button to set the WINS IP address
$buttonSet = New-Object System.Windows.Forms.Button
$buttonSet.Text = "Set WINS IP"
$buttonSet.Location = New-Object System.Drawing.Point(280, 70)
$buttonSet.Add_Click({
$newWINS = $textBoxWINS.Text
if (Validate-IPAddress $newWINS) {
if ($newWINS -eq $oldWINS) {
$labelNewWINS.Text = "IP is the same as Old WINS. No changes made."
} else {
netsh interface ip set wins "Ethernet" static $newWINS
$labelNewWINS.Text = $newWINS
$oldWINS = $newWINS
}
} else {
$labelNewWINS.Text = "Invalid IP address. No changes made."
}
})
$form.Controls.Add($buttonSet)
# Create an Exit button
$buttonExit = New-Object System.Windows.Forms.Button
$buttonExit.Text = "Exit"
$buttonExit.Location = New-Object System.Drawing.Point(280, 160)
$buttonExit.Add_Click({
$form.Close()
})
$form.Controls.Add($buttonExit)
# Show the form
$form.ShowDialog()
суббота, 22 июля 2023 г.
Enable Shared PC with registry
We need to check if this script really enables Shared PC mode.
It works with registry, but there is also a way to work with Cim/WMI.
In the next few days I will check what is better.
###START###
cls
Add-Type -AssemblyName System.Windows.Forms
# Set form size and positioning variables
$mainFormWidth = 365
$mainFormHeight = 210
$margin = 20
$verticalSpacing = 30
$marksRightShift = 55
$boxSpacing = 20
$checkBoxSize = 20
$numericUpDownWidth = 70
$numericUpDownHeight = 20
$formFont = 'Microsoft Sans Serif, 10'
# Calculate positions
$label_X = $margin
$checkBox_X = $mainFormWidth / 2 + $boxSpacing
$numericUpDown_X = $mainFormWidth / 2 + $boxSpacing
$okButton_X = ($mainFormWidth - $numericUpDownWidth) / 2 - 80
$cancelButton_X = ($mainFormWidth + $numericUpDownWidth) / 2 -30
$button_Y = $mainFormHeight - $margin - $numericUpDownHeight - $verticalSpacing
# Create the main form
$mainForm = New-Object System.Windows.Forms.Form
$mainForm.Text = 'SharedPC Mode Configuration'
$mainForm.Size = New-Object System.Drawing.Size($mainFormWidth, $mainFormHeight)
$mainForm.StartPosition = 'CenterScreen'
$mainForm.Font = $formFont
# Create a label and checkbox for enabling SharedPC Mode
$enableSharedPCLabel = New-Object System.Windows.Forms.Label
$enableSharedPCLabel.Text = 'Enable SharedPC Mode:'
$enableSharedPCLabel.AutoSize = $True
$enableSharedPCLabel.Location = [System.Drawing.Point]::new($label_X, $margin)
$enableSharedPCCheckBox = New-Object System.Windows.Forms.CheckBox
$enableSharedPCCheckBox.Location = [System.Drawing.Point]::new($checkBox_X + $marksRightShift, $margin)
$enableSharedPCCheckBox.Size = New-Object System.Drawing.Size($checkBoxSize, $checkBoxSize)
$mainForm.Controls.Add($enableSharedPCLabel)
$mainForm.Controls.Add($enableSharedPCCheckBox)
# Create a label and numeric updown box for setting maintenance start time
$maintenanceLabel = New-Object System.Windows.Forms.Label
$maintenanceLabel.Text = 'Maintenance Start Time (0-23 hours):'
$maintenanceLabel.AutoSize = $True
$maintenanceLabel.Location = [System.Drawing.Point]::new($label_X, $margin + $verticalSpacing)
$maintenanceNumericUpDown = New-Object System.Windows.Forms.NumericUpDown
$maintenanceNumericUpDown.Location = [System.Drawing.Point]::new($numericUpDown_X + $marksRightShift, $margin + $verticalSpacing)
$maintenanceNumericUpDown.Size = New-Object System.Drawing.Size($numericUpDownWidth, $numericUpDownHeight)
$maintenanceNumericUpDown.Minimum = 0
$maintenanceNumericUpDown.Maximum = 23
$mainForm.Controls.Add($maintenanceLabel)
$mainForm.Controls.Add($maintenanceNumericUpDown)
# Create a label to display the result (SharedPC Mode enabled/disabled or AutoConfigURL value)
$resultLabel = New-Object System.Windows.Forms.Label
$resultLabel.Text = "Result will be displayed here..."
$resultLabel.AutoSize = $False
$resultLabel.Width = $mainFormWidth - $margin * 2
$resultLabel.Height = 60
$resultLabel.Location = [System.Drawing.Point]::new($margin, $margin + $verticalSpacing * 2)
$mainForm.Controls.Add($resultLabel)
# Create an Execute button
$executeButton = New-Object System.Windows.Forms.Button
$executeButton.Text = 'Execute'
$executeButton.Location = [System.Drawing.Point]::new($okButton_X, $button_Y)
$executeButtonWidth = $numericUpDownWidth + 20
$executeButtonHeight = $numericUpDownHeight + 5
$executeButton.Size = New-Object System.Drawing.Size($executeButtonWidth, $executeButtonHeight)
# Create a bold font and assign it to the Execute button
$boldFont = New-Object System.Drawing.Font("Microsoft Sans Serif", 10, [System.Drawing.FontStyle]::Bold)
$executeButton.Font = $boldFont
$mainForm.Controls.Add($executeButton)
# Create a Cancel button
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Text = 'Cancel'
$cancelButton.Location = [System.Drawing.Point]::new($cancelButton_X, $button_Y)
$cancelButton.Size = New-Object System.Drawing.Size($executeButtonWidth, $executeButtonHeight)
$cancelButton.Font = $boldFont
# Add an event handler to close the form when Cancel is clicked
$cancelButton.Add_Click({
$mainForm.Close()
})
$mainForm.Controls.Add($cancelButton)
# Incorporate the provided short code to check SharedPC mode status
$wmiObj = Get-WmiObject -Namespace "root\cimv2\mdm\dmmap" -Class "MDM_SharedPC"
$sharedPCStatus = $wmiObj.EnableSharedPCMode
if ($sharedPCStatus) {
$enableSharedPCCheckBox.Checked = $true
$resultLabel.Text = "SharedPC Mode is currently enabled."
} else {
$enableSharedPCCheckBox.Checked = $false
$resultLabel.Text = "SharedPC Mode is currently disabled."
}
# Add an event handler for the Execute button click
$executeButton.Add_Click({
# Check if the SharedPC status matches the checkbox state
if ($enableSharedPCCheckBox.Checked -eq $sharedPCStatus) {
$resultLabel.Text = "SharedPC Mode is already in the selected state."
return
}
# Disable buttons during execution
$executeButton.Enabled = $false
$cancelButton.Enabled = $false
$okButton.Enabled = $false
# This is where you can use the user's inputs in your script
$isSharedPCModeEnabled = $enableSharedPCCheckBox.Checked
$maintenanceStartTime = $maintenanceNumericUpDown.Value
# Enable or Disable SharedPC Mode based on the checkbox state
if ($isSharedPCModeEnabled) {
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount' -Name "DefaultStoreAccountStatus" -Value 1
$resultLabel.Text = "SharedPC Mode has been enabled."
} else {
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount' -Name "DefaultStoreAccountStatus" -Value 0
$resultLabel.Text = "SharedPC Mode has been disabled."
}
# Get the updated SharedPC status
$sharedPCStatus = $wmiObj.EnableSharedPCMode
# Enable buttons after execution is completed
$executeButton.Enabled = $true
$executeButton.Text = 'Execute'
$cancelButton.Enabled = $true
$okButton.Enabled = $true
})
# Create an OK button
$okButton = New-Object System.Windows.Forms.Button
$okButton.Text = 'OK'
$okButton.Location = [System.Drawing.Point]::new($cancelButton_X, $button_Y)
$okButton.Size = New-Object System.Drawing.Size($executeButtonWidth, $executeButtonHeight)
$okButton.Font = $boldFont
$okButton.Enabled = $false
# Add an event handler to close the form when OK is clicked
$okButton.Add_Click({
$mainForm.Close()
})
$mainForm.Add_FormClosed({
# Close the form if the user closes it using the window close button (X)
$mainForm.Close()
})
$mainForm.Controls.Add($okButton)
# Show the form
$mainForm.ShowDialog()
Delete local users if not current and not Admin
# Get the username of the currently logged in user
$current_username = [Environment]::UserName
# Get all local users
$local_users = Get-WmiObject -Class Win32_UserAccount -Filter "LocalAccount='True'" | Where-Object { $_.SID -notlike "S-1-5-21-*" }
# Iterate over the local users
foreach ($user in $local_users) {
# If the user is not the currently logged in user
if ($user.Name -ne $current_username) {
# Delete the user
net user $user. Name /delete
}
}
Delete LocalAdmin users for SharedPC
cls
# Get all local users named "LocalAdmin"
$local_users = Get-WmiObject -Class Win32_UserAccount -Filter "LocalAccount='True'" | Where-Object { $_.Name -like "LocalAdm*" }
# Iterate over the local users
foreach ($user in $local_users) {
$user.Name
# Delete the user if its name starts with "LocalAdmin"
net user $user. Name /delete
}
Create LocalAdmin for Shared PC
cls
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.Text = 'New Admin User'
$form.Size = New-Object System.Drawing.Size(400,250) # Reduced form size
$form.StartPosition = "CenterScreen"
# Status label
$statusLabel = New-Object System.Windows.Forms.Label
$statusLabel.Location = New-Object System.Drawing.Point(10,10)
$statusLabel.Size = New-Object System.Drawing.Size(360,150) # Reduced the height here
$statusLabel.Font = New-Object System.Drawing.Font("Arial",12,[System.Drawing.FontStyle]::Bold)
$statusLabel.ForeColor = [System.Drawing.Color]::DarkBlue
$statusLabel.Text = ""
$form.Controls.Add($statusLabel)
# add button
$button = New-Object System.Windows.Forms.Button
$button.Size = New-Object System.Drawing.Size(120,40)
$button.Font = New-Object System.Drawing.Font("Arial",12)
$button.Text = 'Add User'
$button.Location = New-Object System.Drawing.Point([int](($form.ClientSize.Width - $button.Width) / 2), [int]($form.ClientSize.Height - $button.Height - 10)) # Change the margin here
$button.Add_Click({
$adminName = "LocalAdmin"
$adminPass = 'Password123'
#$adminPass = 'Pa$$word123'
$suffix = ""
while (Get-WmiObject Win32_UserAccount -filter "Name='$adminName$suffix'" -ErrorAction SilentlyContinue) {
if ($suffix -eq "") {
$suffix = 1
} else {
$suffix++
}
}
$adminName += $suffix
invoke-expression "net user /add $adminName $adminPass"
$user = New-Object System.Security.Principal.NTAccount($adminName)
$sid = $user.Translate([System.Security.Principal.SecurityIdentifier])
$sid = $sid.Value;
New-Item -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\SharedPC\Exemptions\$sid" -Force
$statusLabel.Text = "User $adminName`nhas been created."
})
$form.Add_Resize({
$button.Top = $form.ClientSize.Height - $button.Height - 10 # Change the margin here
$button.Left = ($form.ClientSize.Width - $button.Width) / 2
})
$form.Controls.Add($button)
# Check user on form load
$adminName = "LocalAdmin"
if (Get-WmiObject Win32_UserAccount -filter "Name='$adminName'" -ErrorAction SilentlyContinue) {
$statusLabel.Text = "User $adminName already exists. `nRecommended not to create."
} else {
$statusLabel.Text = "User $adminName does not exist."
}
$form.ShowDialog()
