-
Notifications
You must be signed in to change notification settings - Fork 1
/
scriptForInstallation.ps1
63 lines (48 loc) · 2.33 KB
/
scriptForInstallation.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
# --------- Function section ---------
function Set-Item-Property ([string]$path, [string]$name, [string]$value) {
Write-Host "Create or change Property:`n`tItem $name`n`tPath: $path`n`tValue: $value`n"
New-ItemProperty -Path $path -Name $name -PropertyType String -Value $value -Force | Out-Null
}
function Restart-Explorer() {
Stop-Process -ProcessName explorer
}
# ----------- Code section -----------
# Requires '-RunAsAdministrator'
# Or it elevates itself to admin rights
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "Requesting Admin Rights..."
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; stop-process -Id $PID
}
Write-Host -ForegroundColor Yellow "----------- Admin Mode Enabled -----------`n"
$registryPathRoot = "HKCR:"
IF ( !(Test-Path $registryPathRoot) ) {
Write-Host "HKEY_CLASSES_ROOT is not mounted. Mounting..."
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR
Write-Host "`n"
}
# Install neccessary registry
$registryPathDropHandler = "HKCR:\Microsoft.PowerShellScript.1\ShellEx\DropHandler"
$registryPathShellOpen = "HKCR:\Microsoft.PowerShellScript.1\Shell\Open\Command"
$nameDefault = "(Default)"
$valueDropHandler = "{60254CA5-953B-11CF-8C96-00AA00B8708C}"
$valueShellOpen = '"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoExit -File "%1" %*'
IF ( !(Test-Path $registryPathDropHandler) ) {
Write-Host "Create path..."
New-Item -Path $registryPathDropHandler -Force | Out-Null
Set-Item-Property $registryPathDropHandler $nameDefault $valueDropHandler
} ELSE {
Set-Item-Property $registryPathDropHandler $nameDefault $valueDropHandler
}
IF ( !(Test-Path $registryPathShellOpen) ) {
New-Item -Path $registryPathShellOpen -Force | Out-Null
Set-Item-Property $registryPathShellOpen $nameDefault $valueShellOpen
} ELSE {
Set-Item-Property $registryPathShellOpen $nameDefault $valueShellOpen
}
Write-Host -ForegroundColor Yellow "Enable executable scripts...`n"
Set-ExecutionPolicy Bypass
Write-Host -ForegroundColor Yellow "Restarting explorer.exe...`n"
Restart-Explorer
Write-Host -ForegroundColor Yellow "----------- Done -----------`n"
PAUSE
stop-process -Id $PID