cdk refresh 2

Created: 2025-12-01 17:22:48 | Last updated: 2025-12-02 19:28:51 | Status: Public

$desktopPath = [Environment]::GetFolderPath("Desktop")
$filePath = Join-Path $desktopPath "CDK_Opener.txt"
"https://c185978-dms.drive.connectcdk.com/of/" | Out-File -FilePath $filePath -Encoding UTF8

CDK String

https://c185978-dms.drive.connectcdk.com/of/

# CDK Cleaner. Kills CDK, Clears Temp folders, Clears CDK folders, Sets 'Do not save encrypted'
# 2022-04-06 : Last Edit


function Set-RegistryValueForAllUsers {
    <#
    .SYNOPSIS
        This function uses Active Setup to create a "seeder" key which creates or modifies a user-based registry value
        for all users on a computer. If the key path doesn't exist to the value, it will automatically create the key and add the value.
    .EXAMPLE
        PS> Set-RegistryValueForAllUsers -RegistryInstance @{'Name' = 'Setting'; 'Type' = 'String'; 'Value' = 'someval'; 'Path' = 'SOFTWARE\Microsoft\Windows\Something'}
        This example would modify the string registry value 'Type' in the path 'SOFTWARE\Microsoft\Windows\Something' to 'someval'
        for every user registry hive.
    .PARAMETER RegistryInstance
         A hash table containing key names of 'Name' designating the registry value name, 'Type' to designate the type
        of registry value which can be 'String,Binary,Dword,ExpandString or MultiString', 'Value' which is the value itself of the
        registry value and 'Path' designating the parent registry key the registry value is in.
    #>
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [hashtable[]]$RegistryInstance
    )
    try {
        New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS | Out-Null

        ## Change the registry values for the currently logged on user. Each logged on user SID is under HKEY_USERS
        $LoggedOnSids = $(Get-ChildItem HKU: | Where-Object { $_.Name -match 'S-\d-\d+-(\d+-){1,14}\d+$' } | foreach-object { $_.Name })
        Write-Verbose "Found $($LoggedOnSids.Count) logged on user SIDs"
        foreach ($sid in $LoggedOnSids) {
            Write-Verbose -Message "Loading the user registry hive for the logged on SID $sid"
            foreach ($instance in $RegistryInstance) {
                ## Create the key path if it doesn't exist
                if (!(Test-Path "HKU:\$sid\$($instance.Path)")) {
                    New-Item -Path "HKU:\$sid\$($instance.Path | Split-Path -Parent)" -Name ($instance.Path | Split-Path -Leaf) -Force | Out-Null
                }
                ## Create (or modify) the value specified in the param
                Set-ItemProperty -Path "HKU:\$sid\$($instance.Path)" -Name $instance.Name -Value $instance.Value -Type $instance.Type -Force
            }
        }

        ## Create the Active Setup registry key so that the reg add cmd will get ran for each user
        ## logging into the machine.
        ## http://www.itninja.com/blog/view/an-active-setup-primer
        Write-Verbose "Setting Active Setup registry value to apply to all other users"
        foreach ($instance in $RegistryInstance) {
            ## Generate a unique value (usually a GUID) to use for Active Setup
            $Guid = [guid]::NewGuid().Guid
            $ActiveSetupRegParentPath = 'HKLM:\Software\Microsoft\Active Setup\Installed Components'
            ## Create the GUID registry key under the Active Setup key
            New-Item -Path $ActiveSetupRegParentPath -Name $Guid -Force | Out-Null
            $ActiveSetupRegPath = "HKLM:\Software\Microsoft\Active Setup\Installed Components\$Guid"
            Write-Verbose "Using registry path '$ActiveSetupRegPath'"

            ## Convert the registry value type to one that reg.exe can understand.  This will be the
            ## type of value that's created for the value we want to set for all users
            switch ($instance.Type) {
                'String' {
                    $RegValueType = 'REG_SZ'
                }
                'Dword' {
                    $RegValueType = 'REG_DWORD'
                }
                'Binary' {
                    $RegValueType = 'REG_BINARY'
                }
                'ExpandString' {
                    $RegValueType = 'REG_EXPAND_SZ'
                }
                'MultiString' {
                    $RegValueType = 'REG_MULTI_SZ'
                }
                default {
                    throw "Registry type '$($instance.Type)' not recognized"
                }
            }

            ## Build the registry value to use for Active Setup which is the command to create the registry value in all user hives
            $ActiveSetupValue = "reg add `"{0}`" /v {1} /t {2} /d {3} /f" -f "HKCU\$($instance.Path)", $instance.Name, $RegValueType, $instance.Value
            Write-Verbose -Message "Active setup value is '$ActiveSetupValue'"
            ## Create the necessary Active Setup registry values
            Set-ItemProperty -Path $ActiveSetupRegPath -Name '(Default)' -Value 'Active Setup Test' -Force
            Set-ItemProperty -Path $ActiveSetupRegPath -Name 'Version' -Value '1' -Force
            Set-ItemProperty -Path $ActiveSetupRegPath -Name 'StubPath' -Value $ActiveSetupValue -Force
        }
    }
    catch {
        Write-Warning -Message $_.Exception.Message
    }
}

# End the CDK process
taskkill /im wsStart_4.exe /f  
taskkill /im msedge.exe /f  
taskkill /im iexplore.exe /f  

Write-Host "`nDelaying for 5 seconds for CDK to exit..."
Start-Sleep -s 5
Write-Host "`nContinuing..."

#Clear all Temp folders

$temp_folders = @( "$Env:WinDir\Temp\*", "C:\Windows\Prefetch\", "$Env:Temp","C:\Users\*\AppData\Local\Temp" ) 
Get-Childitem $temp_folders -Recurse | ForEach-Object { 
    $full_name = $_.FullName
    Remove-Item  $full_name -Recurse -Force -Confirm:$false  -EA SilentlyContinue #-Verbose
    Write-Host "$full_name is in use, not deleting..." 
}
Write-Host "`n`nTemp File Removal - COMPLETE"

# Clear CDK Folders

#$cdk_folders= @("C:\Users\$env:USERNAME\Appdata\Local\Apps\2.0\","C:\Users\$env:USERNAME\Appdata\Local\assembly\")
$cdk_folders= @("C:\Users\*\Appdata\Local\Apps\2.0\","C:\Users\*\Appdata\Local\assembly\")

Get-Childitem $cdk_folders -Recurse | ForEach-Object { 
    $full_name = $_.FullName
    Remove-Item  $full_name -Recurse -Force -Confirm:$false  -EA SilentlyContinue #-Verbose
    Write-Host "$full_name is in use, not deleting..." 
}
Write-Host "`nCDK File Removal - COMPLETE`n"


#Delete Internet Explorer Cache
Remove-Item -path "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -Recurse -Force -EA SilentlyContinue #-Verbose
Remove-Item -path "C:\Users\*\AppData\Local\Microsoft\Windows\INetCache\*" -Recurse -Force -EA SilentlyContinue #-Verbose
Write-Host "`nInternet Explorer Cache Removal - COMPLETE`n" # -ForegroundColor yellow 


# DisableCachingOfSSLPages HKLM
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "DisableCachingOfSSLPages" -Value 0
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "DisableCachingOfSSLPages" -Value 0

# DisableCachingOfSSLPages HKLU
Set-RegistryValueForAllUsers -RegistryInstance @{'Name' = 'DisableCachingOfSSLPages'; 'Type' = 'DWord'; 'Value' = '0'; 'Path' = "\Software\Microsoft\Windows\CurrentVersion\Internet Settings"}


Write-Host "`nInternet Explorer Registry Settings Update - COMPLETE`n" 
Write-Host "`n`nWe suggest that you save any open user documents and restart!`n`n" 


#$pause_time=5
#Write-Host "`nAll processes have successfully completed!`n" 
#Write-Host "Pausing for $pause_time seconds before autoclosing"
#Start-Sleep -s $pause_time