Search code examples
vbscriptregistryskypewsh

Getting VBS-Script to change registry


I have been trying a lot of different solutions to making a script that with 1 click can change some registry settins in Skype. I have attempted straight scripting even using delay and sending enter but nothing seems to work.

The closest I have gotten is the following:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Skype\Phone]
"ProxySetting"=-
"ProxyAddress"=-
"DisableUDP"=-

However this still results in a confirmation box from "RegistryEditor". I have tried getting the script to send enter and I have tried making a separate VBS script to run this file and sending enter twice to handle the confirmation box but with no "smooth" success.

What'd a proper solution be?


Solution

  • Using regedit /s is possible, but a little awkward, since you'd have to create a file with the settings and then import that file. And even if we ignored that, the solution still had the problem that regedit doesn't return a status code indicating whether the import was successful or not. The latter could be addressed by replacing regedit.exe with reg.exe:

    rc = objShell.Run("reg import \\host\share\registry.reg", 0, True)
    

    However, it's unnecessary to import an external file. VBScript can directly create, manipulate and delete registry keys and values, either via a WshShell object:

    Set sh = CreateObject("WScript.Shell")
    
    sh.RegDelete "HKLM\SOFTWARE\Policies\Skype\Phone\ProxySetting"
    sh.RegDelete "HKLM\SOFTWARE\Policies\Skype\Phone\ProxyAddress"
    sh.RegDelete "HKLM\SOFTWARE\Policies\Skype\Phone\DisableUDP"
    

    or via WMI:

    Const HKLM = &h80000001
    Const key  = "SOFTWARE\Policies\Skype\Phone"
    
    Set reg = GetObject("winmgmts://./root/default:StdRegProv")
    
    rc1 = reg.DeleteValue(HKLM, key, "ProxySetting")
    rc2 = reg.DeleteValue(HKLM, key, "ProxyAddress")
    rc3 = reg.DeleteValue(HKLM, key, "DisableUDP")