-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminLaunchOption.ps1
129 lines (113 loc) · 3.93 KB
/
AdminLaunchOption.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Define the path for the log file
$LOGFILE = "$env:USERPROFILE\Desktop\install-log.txt"
# Define the paths for Python and NexTool
$pythonPath = "C:\Python311\python.exe"
$NexToolPath = "C:\NexTool\NexTool.py"
# Function to write log entries to the log file and console
Function LogWrite {
Param ([string]$logEntry)
"$(Get-Date) - $logEntry" | Out-File $LOGFILE -Append
Write-Host $logEntry
}
# Function to install Chocolatey package manager
Function Install-Chocolatey {
Set-ExecutionPolicy Bypass -Scope Process -Force
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RefreshEnv
}
# Function to download a file from a URL to a destination
Function DownloadFile {
Param ([string]$url, [string]$destination)
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $destination)
}
# Start of the main script
LogWrite "Script started"
# Check for administrative rights and elevate if necessary
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
LogWrite "Requesting administrative privileges..."
Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}
LogWrite "Running with administrative privileges..."
# Create NexTool directory if it doesn't exist
if (-not (Test-Path C:\NexTool)) {
New-Item -Path C:\NexTool -ItemType Directory | Out-Null
}
# Set full permissions for the NexTool directory
icacls 'C:\NexTool' /grant 'Everyone:F' /T /C /Q | Out-Null
# Install Chocolatey if not already installed
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
try {
LogWrite "Chocolatey not detected. Attempting installation..."
Install-Chocolatey
}
catch {
LogWrite "Error installing Chocolatey!"
exit
}
}
# Check for Aria2c and install if necessary
if (-not (Get-Command aria2c -ErrorAction SilentlyContinue)) {
try {
LogWrite "Aria2c not detected. Attempting installation..."
choco install aria2 -y
}
catch {
LogWrite "Error installing Aria2c!"
exit
}
}
# Check for PowerShell Core and install/upgrade if necessary
if (-not (Get-Command pwsh -ErrorAction SilentlyContinue)) {
try {
LogWrite "PowerShell Core not detected. Attempting installation..."
choco install powershell-core -y
}
catch {
LogWrite "Error installing PowerShell Core!"
exit
}
}
else {
choco upgrade powershell-core -y
}
# Check for Python, download and install if necessary
if (-not (Test-Path $pythonPath)) {
try {
LogWrite "Python not detected. Attempting download..."
DownloadFile "https://www.python.org/ftp/python/3.11.6/python-3.11.6-amd64.exe" "C:\NexTool\python-3.11.6-amd64.exe"
LogWrite "Installing Python..."
Start-Process -FilePath "C:\NexTool\python-3.11.6-amd64.exe" -ArgumentList "/quiet InstallAllUsers=1 PrependPath=1 TargetDir=C:\Python311" -Wait
}
catch {
LogWrite "Error installing Python!"
exit
}
}
# Download NexTool.py using WebClient
try {
LogWrite "Downloading NexTool.py..."
DownloadFile "https://raw.githubusercontent.com/coff33ninja/NexTool-Windows-Suite/main/NexTool.py" $NexToolPath
}
catch {
LogWrite "Error downloading NexTool.py"
exit
}
# Launch NexTool.py if it exists
if (Test-Path $NexToolPath) {
LogWrite "Launching NexTool.py"
Start-Process -Wait -FilePath $pythonPath -ArgumentList $NexToolPath
}
# Check if the user wants to clean up
Clear-Host
$response = $null
while ($response -notmatch '^[yn]$') {
$response = Read-Host "Do you wish to clean up and remove C:\NexTool? (Y/N)"
}
if ($response -eq 'y') {
# Cleanup
Remove-Item "C:\NexTool" -Recurse
LogWrite "Cleanup completed. Removed C:\NexTool directory."
}
LogWrite "Script completed."