1

Task scheduler runs a batch file which launches a powershell script to change the registry. The task is set to run every time someone logs in. The user gets prompted to click yes or no to change registry settings. Of course I want them to press the "yes" button but cannot guarantee they will. Is there a way to suppress the registry change prompt and automatically 'Click' yes every time it asks?

Here is a copy of my .ps1 file:

$regpath = "HKCU:\Software\Laserfiche\Client8\Profile\IPDatabase"
$repositoryname = "Clay"

If ((Get-ItemProperty $regpath).PSObject.Properties.Name -eq $null) {

    C:\LF_setup.reg

}ElseIf((Get-ItemProperty $regpath).PSObject.Properties.Name -ne $null){

$RepositoryBoolean = (Get-ItemProperty $regpath).PSObject.Properties.Name -contains $repositoryname

If ($RepositoryBoolean -eq "True"){

Write-Host "Laserfische Setup Correctly"
}}
Squashman
  • 13,649
  • 5
  • 27
  • 36
Matt Brown
  • 23
  • 7
  • There is nothing in your code what writes to the registry. – Olaf Mar 16 '18 at 22:28
  • Ah .. ok ... now I see the mistake. When you simply invoke the reg file the explorer handles the execution of the program linked to the file extension. You should explicitly specify the program to launch. Something like this `regedit.exe /s C:\LF_setup.reg` – Olaf Mar 16 '18 at 22:43
  • Thanks Olaf, this did the trick! It no longer prompts me to press yes when this runs in scheduled tasks. – Matt Brown Mar 19 '18 at 16:47

1 Answers1

1

If you want to import a reg file silently you have to use either regedit.exe /s or reg import. Regardless of that has your code some room for improvement:

$regpath = 'HKCU:\Software\Laserfiche\Client8\Profile\IPDatabase'
$repositoryname = 'Clay'

$KeyContent = (Get-ItemProperty $regpath).PSObject.Properties.Name
If ($KeyContent) {
    If ($KeyContent -contains $repositoryname) {
        Write-Host 'Laserfiche Setup Correctly'
    }
}
Else{
    regedit.exe /s C:\LF_setup.reg
}

This should do the trick I think.

Olaf
  • 4,690
  • 2
  • 15
  • 23