Renamed file and added check for admin rights

This commit is contained in:
2024-03-02 10:41:14 -05:00
parent 8692860087
commit 87ea1a96c2
2 changed files with 67 additions and 26 deletions

View File

@@ -1,26 +0,0 @@
$releaseURL = "https://api.github.com/repos/bailey27/cppcryptfs/releases/latest"
$installPath = "C:\Program Files\CCPCryptFS"
$release = Invoke-RestMethod $releaseURL
$latestVersion = $release.tag_name
write-host "Latest Version: $latestVersion"
new-item -type Directory $installPath -force | out-null
foreach ($asset in $release.assets) {
$fileName = $asset.name
$downloadURL = $asset.browser_download_url
if ($fileName -like '*32.exe') {
continue
}
Invoke-WebRequest -URI $downloadURL -OutFile "$installPath\$fileName"
if ($fileName -like 'cppcryptfs.exe') {
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\$((Get-Item "$installPath\$fileName").Basename).lnk")
$Shortcut.TargetPath = "$installPath\$fileName"
$Shortcut.Save()
}
}

67
Install CCPCryptFS.ps1 Normal file
View File

@@ -0,0 +1,67 @@
[cmdletbinding()]
Param ()
#####################
# Get Admin Rights ##
#####################
# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
# Check to see if we are currently running "as Administrator" and not 64 bit
if ($myWindowsPrincipal.IsInRole($adminRole)) {
# We are running "as Administrator" - so change the title and background color to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
#$Host.UI.RawUI.BackgroundColor = "DarkBlue"
clear-host
} else {
# We are not running "as Administrator" - so relaunch as administrator
# Create a new process object that starts PowerShell x86
# Check to see if we are currently running x86 arch
# the LHO script can only run with 32 bit powershell
if (([environment]::Is64BitProcess)) {
# run the 32 bit powershell exe when on a 64 bit computer
$newProcess = new-object System.Diagnostics.ProcessStartInfo "C:\Windows\SysWoW64\WindowsPowerShell\v1.0\powershell.exe";
} else {
# run the normal 32 bit powershell exe when on 32 bit computer
$newProcess = new-object System.Diagnostics.ProcessStartInfo "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe";
}
# Specify the current script path and name as a parameter with added scope and support for scripts with spaces in it's path
$newProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'"
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($newProcess);
# Exit from the current, unelevated, process
exit
}
$releaseURL = "https://api.github.com/repos/bailey27/cppcryptfs/releases/latest"
$installPath = "C:\Program Files\CCPCryptFS"
$release = Invoke-RestMethod $releaseURL
$latestVersion = $release.tag_name
write-host "Latest Version: $latestVersion"
new-item -type Directory $installPath -force | out-null
foreach ($asset in $release.assets) {
$fileName = $asset.name
$downloadURL = $asset.browser_download_url
if ($fileName -like '*32.exe') {
continue
}
Invoke-WebRequest -URI $downloadURL -OutFile "$installPath\$fileName"
if ($fileName -like 'cppcryptfs.exe') {
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\$((Get-Item "$installPath\$fileName").Basename).lnk")
$Shortcut.TargetPath = "$installPath\$fileName"
$Shortcut.Save()
}
}