0

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?

The Furious Bear
  • 592
  • 4
  • 16
  • 31
  • Is your variable `$vbsPath` a Network Path? – Rich May 20 '14 at 20:00
  • Yes, at present the VBScript is located remotely... Would it make things easier if I stored the script locally? – The Furious Bear May 21 '14 at 09:09
  • 1
    Nah. Just wanted to ask because powershell treats network paths as remote locations and there is a direct way to fix this. http://stackoverflow.com/questions/728143/ignore-security-warning-running-script-from-command-line i see you got this fixed, but this is still worth a read. – Rich May 21 '14 at 14:22
  • Useful link Rich, thanks.. – The Furious Bear May 21 '14 at 17:02

1 Answers1

0

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.

JPBlanc
  • 70,406
  • 17
  • 130
  • 175