06 March 2014

Creating Active Setup Registry Key

Here is a script I just wrote that will create an active setup registry key. It prompts you for the title, description, command line execution string, and version. It generates a unique GUID to name the registry key. It then generates the registry key file and places it in the same directory as the script was executed from.

You can download the script from here.

<#
     Author: Mick Pletcher
       Date: 06 March 2014
   Synopsis: This will generate the active setup registry key to
             deploy to machines so it iterates through every user that
             logs onto a machine.
Description: This will prompt for the title, brief description, version, and
             command line execution string. It then generates the .reg file
             and places it in the same directory as the script was executed from.
#>

Function GetRelativePath{  

    #Declare Local Memory
    Set-Variable -Name RelativePath -Scope Local -Force
    
    $RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"
    Return $RelativePath
    
    #Cleanup Local Memory
    Remove-Variable -Name RelativePath -Scope Local -Force
    
}
 
Function GenerateGUID {

    #Declare Local Memory
    Set-Variable -Name GetGUID -Scope Local -Force
    
    $GetGUID = [guid]::NewGuid()
    $GetGUID = $GetGUID.ToString().ToUpper()
    
    return $GetGUID

    #Cleanup Local Memory
    Remove-Variable -Name GetGUID -Scope Local -Force
    
}

Function GetKeyInfo {

    #Declare Local Memory
    Set-Variable -Name ComponentID -Scope Local -Force
    Set-Variable -Name Description -Scope Local -Force
    Set-Variable -Name StubPath -Scope Local -Force
    Set-Variable -Name Version -Scope Local -Force
    
    $ComponentID = Read-Host "Enter the title"
    $Description = Read-Host "Enter brief description"
    $Version = Read-Host "Enter the version number"
    $StubPath = Read-Host "Enter the command line execution string"
    $StubPath = $StubPath -replace '\\','\\'
    Return $ComponentID, $Description, $Version, $StubPath
    
    #Cleanup Local Memory
    Remove-Variable -Name ComponentID -Scope Local -Force
    Remove-Variable -Name Description -Scope Local -Force
    Remove-Variable -Name StubPath -Scope Local -Force
    Remove-Variable -Name Version -Scope Local -Force
    
}

Function GenerateRegKey ($RelativePath, $GUID, $KeyInfo) {

    #Declare Local Memory
    Set-Variable -Name File -Scope Local -Force
    Set-Variable -Name Text -Scope Local -Force
    
    $File = $RelativePath+"ActiveSetup.reg"
    If (Test-Path $File) {
        Remove-Item -Path $File -Force
    }
    New-Item -Name ActiveSetup.reg -Path $RelativePath -ItemType file -Force
    $Text = "Windows Registry Editor Version 5.00"
    Add-Content -Path $File -Value $Text -Force
    $Text = [char]13
    Add-Content -Path $File -Value $Text -Force
    $Text = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{"+$GUID+"}]"
    Add-Content -Path $File -Value $Text -Force
    $Text = "@="+[char]34+$KeyInfo[1]+[char]34
    Add-Content -Path $File -Value $Text -Force
    $Text = [char]34+"ComponentID"+[char]34+"="+[char]34+$KeyInfo[0]+[char]34
    Add-Content -Path $File -Value $Text -Force
    $Text = [char]34+"StubPath"+[char]34+"="+[char]34+$KeyInfo[3]+[char]34
    Add-Content -Path $File -Value $Text -Force
    $Text = [char]34+"Version"+[char]34+"="+[char]34+$KeyInfo[2]+[char]34
    Add-Content -Path $File -Value $Text -Force

    #Cleanup Local Memory
    Remove-Variable -Name File -Scope Local -Force
    Remove-Variable -Name Text -Scope Local -Force

}

#Declare Global Memory
Set-Variable -Name GUID -Scope Local -Force
Set-Variable -Name KeyInfo -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force

cls
$RelativePath = GetRelativePath
$GUID = GenerateGUID
$KeyInfo = GetKeyInfo
GenerateRegKey $RelativePath $GUID $KeyInfo

#Cleanup Global Memory
Remove-Variable -Name GUID -Scope Local -Force
Remove-Variable -Name KeyInfo -Scope Local -Force

Related Posts:

  • Get Default Printer The new and updated Default Printer report is located here. This script will find the default printer of a logged on user and write it to a text file named DefaultPrinter.txt in the %APPDATA% folder. I have this script run… Read More
  • Application Uninstall Script This script will uninstall an application with just the partial description that is listed in Add/Remove programs. It searches the product list and then grabs the GUID to use in the MSI uninstallation. At current, it will o… Read More
  • PowerShell One-Liners to ensure Dell system is configured for UEFI when imaging While planning and configuring the Windows 10 upgrades, we had to also include the transition to UEFI from BIOS. I wanted to make sure that when the build team builds new models that they are configured for UEFI when applica… Read More
  • Robocopy User Profile Contents to UNC Path The Windows 10 upgrades required us to move profile contents off of the machines to a file share and then move them back. This was because USMT could not be used due to the architecture changing from 32-bit to 64-bit. This … Read More
  • Find out who is logged on and logged off Being an SCCM administrator, I often have to log into machines to see if a deployment went ok. Trying to login to machines and getting the message that someone is already logged in gets tiring. Ed Wilson originally wrote a … Read More

2 comments:

  1. Nice blog. this blog is very important and helpful.I a very thankful to the Author of this blog.seo services in amritsar

    ReplyDelete
  2. Hello to every , for the reason that I am actually keen of reading this blog's
    post to be updated daily. It includes fastidious information.

    Feel free to visit my webpage - internet providers hanover wv

    ReplyDelete