It is requested a basic perspective for scripts on a functional aspect therewith

Claus Debanker 41 Reputation points
2024-08-29T08:26:20.7066667+00:00

In the event of having to employ a script to stabilize a safety setting in the registry which conflicts occasionally from the existence with an alternate user account;

the script is based on checking every one minute the specific value and repairing it when it is detected with error, a round of starting and sleeping indicates that the script will be active continually after once be executed?

What if at a point need be to do away with the specific script? Is it enough to simply delete the ps1 file from the 'scripts' folder?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,710 questions
Office
Office
A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.
1,706 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 34,421 Reputation points
    2024-08-30T13:13:04.2266667+00:00

    One option would be to define scheduled task that runs at system startup and executes a Powershell script.

    Here's a sample script that will save the registry value when it starts and will reset it if it ever changes. You will need to modify it to refer to the registry value that you need to monitor.

    Function LogIt($msg) {
        "{0} - {1}" -f (Get-Date), $msg | Write-Host 
        "{0} - {1}" -f (Get-Date), $msg | Out-File -FilePath $log -Append
    }
    
    # Define the log file name and the registry to monitor
    $log = "c:\scripts\Monitor.log"
    $KeyName = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\"
    $ValueName = "UpdateDesiredVisibility"
    
    LogIt "Monitor starting."
    $wur = Get-ItemProperty $KeyName
    $DesiredValue = $wur.($ValueName)
    LogIt "Initial value is $DesiredValue"
    while ($true) {                             # infinite loop to monitor value 
        Start-Sleep -Seconds 60
        $wur = Get-ItemProperty $KeyName 
        if ($wur.($ValueName) -ne $DesiredValue) {
            Logit "Value changed to $($wur.UpdateDesiredVisibility). Reset to $DesiredValue."
            Set-ItemProperty $KeyName  -Name $ValueName -Value  $DesiredValue
        }
    }
    

    Run the task as the system account identity so that it executes "in the background". If you need to stop it, use the task manager to kill the Powershell process.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.