Skip to content

Instantly share code, notes, and snippets.

@r00t-3xp10it
Last active August 26, 2024 07:04
Show Gist options
  • Save r00t-3xp10it/09fe01440bc0b964823c81533d354c5f to your computer and use it in GitHub Desktop.
Save r00t-3xp10it/09fe01440bc0b964823c81533d354c5f to your computer and use it in GitHub Desktop.
Start|Stop service name
<#
.SYNOPSIS
STOP|START parental control service [WpcMonSvc]
Author: @r00t-3xp10it
Tested Under: Windows 10 (19044) x64 bits
Required Dependencies: Get-Service
Optional Dependencies: SCHTASKS
PS cmdlet Dev version: v1.0.8
.DESCRIPTION
This cmdlet Stops|Disables W10|11 WpcMonSvc service, process, tasks
that prevents 'Parental Controls' application\service\tasks from running.
Parental controls work by blocking inappropriate online content limmiting
the screen time, and setting the age restriction for games and applications.
This cmdlet can also be used to manage diferent windows services indevidualy.
.NOTES
Instructions how to execute Invoke-WpcMonSvc.ps1
1 - Modify powershell ExecutionPolicy to execute Invoke-WpcMonSvc.ps1
echo Y|powershell Set-ExecutionPolicy UnRestricted -Scope CurrentUser
2 - Open folder where Invoke-WpcMonSvc.ps1 is located and in that folder
press the follow keyboard keys: press ALT+F + press S + press A
3 - Check 'WpcMonSvc' service|processes|tasks without changing settings
.\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -check -tasks -process
4 - Stop 'WpcMonSvc' service|tasks|process and config service startup to 'Manual'
.\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -status 'Stopped' -StartType 'Manual' -tasks -process
Parameter -status 'Stopped' -> Stop sellected service
Parameter -status 'Running' -> Start sellected service
Parameter -StartType 'Disabled' -> prevents the service to run in the system startup
Parameter -StartType 'Manual' -> The service only runs if called by user manually
Parameter -StartType 'Automatic' -> Config the service to run in the system startup
NOTE: To config the service 'WpcMonSvc' to is default state execute:
.\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -status 'Running' -StartType 'Automatic' -tasks -process
.Parameter Name
The service name we want to stop or start (default: WpcMonSvc)
.Parameter Status
Service status settings 'Running' ou 'Stopped' (default: Stopped)
.Parameter StartType
Service startup settings 'Automatic','Manual,'Disabled' (default: Manual)
.Parameter Check
Switch to display service state or service|tasks|process state [WpcMonSvc]
.Parameter Tasks
Switch that Enable|Disable 'WpcMonSvc' related schedule tasks [FamilySafety]
.Parameter Process
Switch that STARTS|STOPS WpcMon.exe process related to WpcMonSvc service
.Parameter Filter
Search for matching strings within -check function outputs
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -check -name 'WpcMonSvc'
Check service 'WpcMonSvc' state without change anything
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -check -name '*'
Check ALL services state without change anything
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -check -name '*' -filter "Automatic"
Check ALL services with 'Automatic' string without change anything
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -check -tasks -process
Check 'WpcMonSvc' Service|Tasks|Process state without changing settings
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -status 'stopped' -StartType 'manual'
Config service 'WpcMonSvc' to status 'stopped' with startup execution set to 'manual'
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -status 'Stopped' -StartType 'disabled'
Config service 'WpcMonSvc' to status 'stopped' with startup execution set to 'disabled'
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -status 'Running' -StartType 'automatic'
Config service 'WpcMonSvc' to status 'running' with startup execution set to 'automatic'
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -status 'Running' -StartType 'manual'
Config service 'WpcMonSvc' to status 'running' with startup execution set to 'manual'
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -status 'Stopped' -StartType 'manual' -tasks
Config 'WpcMonSvc' to 'Stopped' with startup set to 'manual' and disable 'FamilySafety' tasks
.EXAMPLE
PS C:\> .\Invoke-WpcMonSvc.ps1 -name 'WpcMonSvc' -status 'Stopped' -StartType 'manual' -tasks -process
Config WpcMonSvc to 'Stopped' + startup set to 'manual' + disable 'FamilySafety' tasks + stop WpcMon.exe process
.INPUTS
None. You cannot pipe objects into Invoke-WpcMonSvc.ps1
.OUTPUTS
Name DisplayName Status StartType
---- ----------- ------ ---------
WpcMonSvc Restrições de Acesso Stopped Manual
.LINK
https://www.smartpcutilities.com/windows-service.html?name=WpcMonSvc
https://jackworthen.com/2020/09/20/start-and-stop-a-windows-service-using-powershell
#>
[CmdletBinding(PositionalBinding=$false)] param(
[string]$Filter="(Running|Stopped|Manual|Automatic|Disabled)", ## filter
[string]$StartType="Manual", ## Service startup default configuration
[string]$Status="Stopped", ## 'STOP' (Stopped) ou 'START' (Running) serviçe
[string]$Name="WpcMonSvc", ## The name of the service to 'START' or 'STOP'
[switch]$Process, ## START|STOP processes related to WpcMonSvc
[switch]$Check, ## Review service state without changing settings
[switch]$Tasks ## Disable|Enable 'WpcMonSvc' service tasks
)
$CVersion = "v1.0.8"
$ErrorActionPreference = "SilentlyContinue"
$host.UI.RawUI.WindowTitle = "Start|Stop services $CVersion"
$IsClientAdmin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -Match "S-1-5-32-544")
$Banner = @"
______ ______ ______ __ __ __ ______ ______ ______
/\ ___\ /\ ___\ /\ == \ /\ \ / / /\ \ /\ ___\ /\ __ \ /\ ___\
\ \___ \ \ \ __\ \ \ __< \ \ \'/ \ \ \ \ \ \____ \ \ \/\ \ \ \___ \
\/\_____\ \ \_____\ \ \_\ \_\ \ \__| \ \_\ \ \_____\ \ \_____\ \/\_____\
\/_____/ \/_____/ \/_/ /_/ \/_/ \/_/ \/_____/ \/_____/ \/_____/
"@;
write-host $Banner -ForegroundColor Blue
If(-not($IsClientAdmin -match '^(True)$'))
{
write-host "`n📛 Execute Invoke-WpcMonSvc.ps1 with administrator privileges`n" -ForegroundColor Red
Start-Sleep -Seconds 3
return
}
If(-not($Status -imatch '^(Running|Stopped)$'))
{
write-host "`n📛 " -ForegroundColor Red -NoNewline
write-host "wrong value input '" -NoNewline
write-host "$Status" -ForegroundColor Red -NoNewline
write-host "' values: " -NoNewline
write-host "[Running|Stopped]`n" -ForegroundColor Green
Start-Sleep -Seconds 3
return
}
If(-not($StartType -imatch '^(Automatic|Manual|Disabled)$'))
{
write-host "`n📛 " -ForegroundColor Red -NoNewline
write-host "wrong value input '" -NoNewline
write-host "$StartType" -ForegroundColor Red -NoNewline
write-host "' values: " -NoNewline
write-host "[Automatic|Manual|Disabled]`n" -ForegroundColor Green
Start-Sleep -Seconds 3
return
}
If(-not(Get-Service -Name "$Name"))
{
write-host "`n📛 " -ForegroundColor Red -NoNewline;write-host "Serviçe name '" -NoNewline
write-host "$Name" -ForegroundColor Red -NoNewline;write-host "' not found in $Env:COMPUTERNAME machine`n"
Start-Sleep -Seconds 3
return
}
function Invoke-ServiceQuery ()
{
If($Name -match '\*')
{
Get-Service -Name "$Name"|Select-Object Name,Status,StartType|Where-Object {
$_.Status -imatch "$Filter" -or $_.StartType -imatch "$Filter" }|Format-Table -AutoSize
}
Else
{
Get-Service -Name "$Name"|Select-Object Name,DisplayName,Status,StartType|Format-Table -AutoSize
}
}
function Invoke-ProcesessQuery ()
{
Get-Process -Name "WpcMon"|Select-Object Name,Path,Responding,Id|Select-Object -First 1|Format-Table -AutoSize
}
## Tasks list
$TaskList = @(
"FamilySafetyMonitor",
"FamilySafetyRefreshTask"
)
If($Check.IsPresent)
{
<#
.SYNOPSIS
Author: r00t-3xp10it
Helper - review service|Process|tasks state
.NOTES
Invoking -check together with -name '*' lists all services
Invoking -check together with -tasks lists WpcMonSvc task's
Invoking -check together with -process lists WpcMon process state
.OUTPUTS
Name DisplayName Status StartType
---- ----------- ------ ---------
WpcMonSvc Restrições de Acesso Running Automatic
Name Path Responding Id
---- ---- ---------- --
WpcMon C:\WINDOWS\system32\WpcMon.exe True 4784
Uri TaskName State
--- -------- -----
\Microsoft\Windows\Shell\FamilySafetyMonitor FamilySafetyMonitor Ready
\Microsoft\Windows\Shell\FamilySafetyRefreshTask FamilySafetyRefreshTask Ready
#>
write-host ""
Invoke-ServiceQuery
## Search for WpcMon.exe process
If(($Process.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
If((Get-Process -Name "WpcMon"|Select-Object *).Responding -match 'True')
{
Invoke-ProcesessQuery
}
}
## Check WpcMonSvc service tasks
If(($Tasks.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
## Create Data Table for output
$mytable = New-Object System.Data.DataTable
$mytable.Columns.Add("Uri")|Out-Null
$mytable.Columns.Add("TaskName")|Out-Null
$mytable.Columns.Add("State")|Out-Null
ForEach($TaskName in $TaskList)
{
## Get All task settings
$GetSettings = (Get-ScheduledTask -TaskName "$TaskName"|Select-Object *)
## Append to table
$mytable.Rows.Add(
$GetSettings.Uri,$GetSettings.TaskName,$GetSettings.State
)|Out-Null
}
## Display Data Table
$mytable | Format-Table -AutoSize
}
Start-Sleep -Seconds 3
return
}
## Local vars
$DISABLE = $null
$SELECTION = $null
If($Status -imatch '^(Stopped)$')
{
<#
.SYNOPSIS
Author: r00t-3xp10it
Helper - STOP Serviçe|Process|Tasks
.NOTES
Invoking -name 'WpcMonSvc' together with -tasks disables service task's
Invoking -name 'WpcMonSvc' together with -process stops WpcMon.exe process
.OUTPUTS
Name DisplayName Status StartType
---- ----------- ------ ---------
WpcMonSvc Restrições de Acesso Stopped Manual
#>
## Check the status of the service
If((Get-Service -Name "$Name"|Select-Object *).Status -match "Running")
{
## Display serviçe state using GUI interface (Out-GridView)
$SELECTION = Get-Service -Name "$Name"|Select-Object *|Where-Object{$_.Status -match "Running"}|
Select-Object Name,Status,StartType,CanStop,ServiceType,DisplayName,DependentServices|
Out-GridView -title "STOP service $Name ?" -PassThru
If([string]::IsNullOrEmpty($SELECTION))
{
write-host "`n`n📛 ABORT: CANCEL BUTTON PRESSED`n" -ForegroundColor Red
}
Else
{
## Stop service name
write-host "`n[*] " -ForegroundColor Blue -NoNewline
write-host "Stopping $Name service"
Stop-Service -Name "$Name" -Force
## Service configuration at system startup
write-host "[*] " -ForegroundColor Blue -NoNewline
write-host "Config $Name system startup"
Set-Service -Name "$Name" -Status "$Status" -StartupType "$StartType"
## Stop processes related to WpcMonSvc
If(($Process.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
If((Get-Process -Name "WpcMon"|Select-Object *).Responding -match '^(True)$')
{
write-host "[*] " -ForegroundColor Blue -NoNewline
write-host "Stopping WpcMon.exe process"
Stop-Process -Name "WpcMon" -Force
}
}
## Disable task if invoked -Tasks together with -name 'WpcMonSvc'
If(($Tasks.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
ForEach($TaskName in $TaskList)
{
If((Get-ScheduledTask -TaskName "$TaskName").State -match 'Ready')
{
write-host "[*] " -ForegroundColor Blue -NoNewline
write-host "Disabling $TaskName Taskname"
schtasks /Change /TN "\Microsoft\Windows\Shell\${TaskName}" /Disable|Out-Null
}
}
}
}
## Check the status of the service after the changes have been made
Start-Sleep -Milliseconds 1800
Invoke-ServiceQuery
## Check WpcMon.exe process state
If(($Process.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
Invoke-ProcesessQuery
}
## Check WpcMonSvc service tasks
If(($Tasks.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
## Create Data Table for output
$mytable = New-Object System.Data.DataTable
$mytable.Columns.Add("Uri")|Out-Null
$mytable.Columns.Add("TaskName")|Out-Null
$mytable.Columns.Add("State")|Out-Null
ForEach($TaskName in $TaskList)
{
## Get All task settings
$GetSettings = (Get-ScheduledTask -TaskName "$TaskName"|Select-Object *)
## Append to table
$mytable.Rows.Add(
$GetSettings.Uri,$GetSettings.TaskName,$GetSettings.State
)|Out-Null
}
## Display Data Table
$mytable|Format-Table -AutoSize
}
}
Else
{
## The service is already at a standstill
write-host "`n📛" -ForegroundColor Red -NoNewline;write-host " The service '" -NoNewline
write-host "$Name" -ForegroundColor Red -NoNewline;write-host "' is already at a standstill."
Invoke-ServiceQuery
}
}
If($Status -imatch '^(Running)$')
{
<#
.SYNOPSIS
Author: r00t-3xp10it
Helper - Start serviçe name
.NOTES
Warning: Pressing [cancel] in Out-GridView starts service name
Invoking -name 'WpcMonSvc' together with -tasks enables service task's
Invoking -name 'WpcMonSvc' together with -process starts WpcMon.exe process
.OUTPUTS
Name DisplayName Status StartType
---- ----------- ------ ---------
WpcMonSvc Restrições de Acesso Running Automatic
#>
## Check the status of the service
If((Get-Service -Name "$Name"|Select-Object *).Status -match "Stopped")
{
## Display serviçe state using GUI interface (Out-GridView)
$DISABLE = Get-Service -Name "$Name"|Select-Object *|Where-Object{$_.Status -match "Stopped"}|
Select-Object Name,Status,StartType,CanStop,ServiceType,DisplayName,DependentServices|
Out-GridView -title "START service $Name ?" -PassThru
If([string]::IsNullOrEmpty($DISABLE))
{
write-host "`n`n📛 ABORT: CANCEL BUTTON PRESSED`n" -ForegroundColor Red
}
Else
{
## Start service
write-host "`n[*] " -ForegroundColor Blue -NoNewline
write-host "Starting $Name service"
Start-Service -Name "$Name"
## Service configuration at system startup
write-host "[*] " -ForegroundColor Blue -NoNewline
write-host "Config $Name system startup"
Set-Service -Name "$Name" -Status "$Status" -StartupType "$StartType"
## Start processes related to WpcMonSvc
If(($Process.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
If((Get-Process -Name "WpcMon"|Select-Object *).Responding -notmatch '^(True)$')
{
write-host "[*] " -ForegroundColor Blue -NoNewline
write-host "Starting WpcMon.exe process"
Start-Process -FilePath "$Env:WINDIR\system32\WpcMon.exe"
}
}
## Enable task if invoked -Tasks together with -name 'WpcMonSvc'
If(($Tasks.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
ForEach($TaskName in $TaskList)
{
If((Get-ScheduledTask -TaskName "$TaskName").State -match 'Disabled')
{
write-host "[*] " -ForegroundColor Blue -NoNewline
write-host "Starting $TaskName Taskname"
schtasks /Change /TN "\Microsoft\Windows\Shell\${TaskName}" /Enable|Out-Null
}
}
}
}
## Check the status of the service after the changes have been made
Start-Sleep -Milliseconds 1800
Invoke-ServiceQuery
## Check WpcMon.exe process state
If(($Process.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
Invoke-ProcesessQuery
}
## Check WpcMonSvc service tasks
If(($Tasks.IsPresent) -and ($Name -imatch '^(WpcMonSvc)$'))
{
## Create Data Table for output
$mytable = New-Object System.Data.DataTable
$mytable.Columns.Add("Uri")|Out-Null
$mytable.Columns.Add("TaskName")|Out-Null
$mytable.Columns.Add("State")|Out-Null
ForEach($TaskName in $TaskList)
{
## Get All task settings
$GetSettings = (Get-ScheduledTask -TaskName "$TaskName"|Select-Object *)
## Append to table
$mytable.Rows.Add(
$GetSettings.Uri,$GetSettings.TaskName,$GetSettings.State
)|Out-Null
}
## Display Data Table
$mytable|Format-Table -AutoSize
}
}
Else
{
## The service has already started
write-host "`n📛" -ForegroundColor Red -NoNewline;write-host " The service '" -NoNewline
write-host "$Name" -ForegroundColor Red -NoNewline;write-host "' has already started."
Invoke-ServiceQuery
}
}
Start-Sleep -Seconds 3
exit
@r00t-3xp10it
Copy link
Author

oki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment