Reputation: 572
I'm running a VBScript from a PowerShell script in an attempt to automate component registrations.
My function looks like this:
function Register-NaviLink ($vbsPath, $vbsName) {
# Run register.vbs
$register=$vbsPath+"\"+$vbsName
Start-Process $register
}
This works OK (it runs the VBScript) but, as the purpose of the PowerShell script is to achieve automation of the process, I'd rather not be confronted with a "File Open - Security Warning" dialog when the VBScript fires.
In an attempt to work around this issue, I created a new registry key "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Associations" with value name "LowRiskFileTypes" and data ".vbs". After reboot, the PowerShell script could run the VBScript without the warning dialog.
However, thinking that leaving the new registry key in place permanently would present a security risk from malicious .vbs scripts, I tried to incorporate the creation and deletion of the registry key into my PowerShell script as follows:
function Register-NaviLink ($vbsPath, $vbsName) {
$workingDirectory=pwd
$registryKey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Associations"
$registryKeyName="LowRiskFileTypes"
$registryKeyValue=".vbs"
Set-Location HKCU:
if(-not(Test-Path ($registryKey))) {
New-Item -Path $registryKey
New-ItemProperty -Path $registryKey -Name $registryKeyName -Value $registryKeyValue
}
$register=$vbsPath+"\"+$vbsName
Start-Process $register
Remove-Item -Path $registryKey -force
Set-Location $workingDirectory
}
The PS script runs OK (no errors) but the creation and deletion of the registry key seems to have no effect on the security warning dialog without a reboot.
Is it possible to refresh the registry keys without reboot?
If so, can this be done through PowerShell scripting?
Upvotes: 0
Views: 2785
Reputation: 72610
In spite of rebooting to apply your changes, can you in a first time try to restart your windows shell (explorer.exe). If it works you just have to send an event to ask the shell to reload the associations.
Upvotes: 0