Set-RegistryValue

  • 14 August 2018
  • Sean Huggans
Description: 

Function sets a registry value, creating the path if it does not exist, and modifying the value if it already exists as well.

Language: 
PowerShell
Usage Type: 
Packaging Function
Script Source: 
function Set-RegistryValue ($ValuePath, $ValueName, $ValueData) {
    ###########################################################
    # Set-RegistryValue
    # Function by: Sean Huggans
    # Function Date: 2018.08.14
    ###########################################################
    # Function will set a registry value, creating the key path if it does not already exist.
    # Usage Example: Set-RegistryValue -ValuePath "Software\Tests\Test 3" -ValueName "Test Value 4" -ValueData "Test Data REVISED 2"
    if (($ValuePath -ne "") -and ($ValueName -ne "") -and ($ValueData -ne "")) {
        $RegistryObject = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME)
        $RegistryObject.CreateSubKey("$($ValuePath)") | Out-Null
        $RegistryKey = $RegistryObject.OpenSubKey("$($ValuePath)", $true)
        try {
            $RegistryKey.SetValue("$($ValueName)", "$($ValueData)", [Microsoft.Win32.RegistryValueKind]::String) | Out-Null
            Log-Action "Registry Add: $($ValuePath)\$($ValueName) ($($ValueData)): Success!"
            return $true
        } catch {
            Log-Action "Registry Add: $($ValuePath)\$($ValueName) ($($ValueData)): Error!"
            return $false
        }
    } else {
        Log-Action "Error: Set-RegistryValue was called with missing parameters!"
        return $false
    }
}
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.
Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.