-
Notifications
You must be signed in to change notification settings - Fork 127
/
ActiveSetup.ps1
109 lines (85 loc) · 3.52 KB
/
ActiveSetup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<#
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
Remove-Variable -Name RelativePath -Scope Local -Force