<#
.SYNOPSIS
    This Script will Download an AppLib with Programs
.DESCRIPTION
    This Script will Download an AppLib with Programs
    on Windows 10 amd64 Local Computer
.NOTES
    File name: NIT.Download-AppLibs.000.ps1
    VERSION: 1.0.0a
    AUTHOR: New Internet Technologies Inc.
    Created:  2025-03-13
    Licensed under the BSD license.
    Please credit me if you find this script useful and do some cool things with it.
.VERSION HISTORY:
    1.0.0 - (2025-03-13) Script created
    1.0.1 - 
#>
param([switch]$Elevated)

#### Set Variables

### Add Global Variables

# Set Script File


### Set Path
$DownloadsPath = (New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path

$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
$WGETEXEPath03 = 'C:\Util\wget.exe'
$WGETEXEPath01 = Join-Path -Path $scriptPath -ChildPath 'wget.exe'
$WGETEXEPath02 = Join-Path -Path $DownloadsPath -ChildPath 'wget.exe'
$ZlovredPath = 'c:\pub1\Distrib\Zlovred\'
$msfURL = 'http://win.netip4.ru/win10plusupdate/misc/ISO/NIT-SomePSGUI/'

if( Test-Path -Path $WGETEXEPath01 -PathType Leaf) {
    $WGETEXEPath = $WGETEXEPath01
}
else {
    if( Test-Path -Path $WGETEXEPath02 -PathType Leaf ) {
        $WGETEXEPath = $WGETEXEPath02
    }
    else {
        if ( Test-Path -Path $WGETEXEPath03 -PathType Leaf ) {
             $WGETEXEPath = $WGETEXEPath03
        }
        else {
            Write-Host "Error! WGET.exe is not found!"
            Exit 1
        }
    }
}

### Set Functions
#

function Test-Admin {
    $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
    $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}

### Run Payloads

if ((Test-Admin) -eq $false)  {
    if ($elevated) {
        # tried to elevate, did not work, aborting
    } else {
#        Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -Window Normal -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
        Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -Window Hidden -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
    }
    exit
}

# 'running with full privileges'

### Set Derivative Variables
#
if( Test-Path -Path $ZlovredPath -PathType Container ) {
    ## Write-Host "Zlovred Path is $ZlovredPath"

    if( Test-Path -Path $WGETEXEPath -PathType Leaf ) {
	    # $FilePath = 'C:\Util\wget.exe -r -nH -np -R "index.html" --cut-dirs=1 -P c:\pub1\Distrib\Zlovred\ http://documents.netip4.ru/NIT/win-msf/msf/'
	    $FilePath = ' -r -nH -np -R "index.html" --cut-dirs=2 -P ' + $ZlovredPath + ' ' + $msfURL
	    # Write-Host "$FilePath"
        Start-Process -FilePath $WGETEXEPath -ArgumentList $FilePath -Wait
    }
    else {
        Write-Host "File $WGETEXEPath is not found!"
        Exit 1
    }
}
else {
    Write-Host "Zlovred Path is not Found!"
    Exit 1
}
Write-Host "Success Script NIT.Download-AppLibs.000.ps1 at $scriptPath has executed"
Exit 0

