Skip to content
Snippets Groups Projects

Allow vstest to use TIA Openness

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Stefan May
    AllowVSTestUsingTiaOpenness.ps1 2.36 KiB
    if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
        write-warning "changing from 32bit to 64bit..."
        $powershell=$PSHOME.tolower().replace("syswow64", "sysnative").replace("system32", "sysnative")
        & "$powershell\powershell.exe" -NonInteractive -NoProfile -file "$($MyInvocation.InvocationName)" $args
        exit $lastexitcode
    }
    
    if (!(new-object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) {
        echo "you have to be admin!"
        exit
    }
    
    $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
    if (!(Test-Path $vswhere)) {
        Write-Error "didn't find vswhere"
        Exit 1
    }
    $vstest = & $vswhere -latest -products * -find Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe | select-object -first 1
    if (!(Test-Path $vstest)) {
        Write-Error "didn't find vstest"
        Exit 1
    }
    
    $file = Get-Item $vstest
     
    $filehash = [Convert]::ToBase64String([byte[]] -split((Get-FileHash -Path $file -Algorithm SHA256).Hash -replace '..', '0x$& '))
    $filedate = Get-Date $file.LastWriteTimeUtc -format "yyyy'/'MM'/'dd HH:mm:ss.fff"
    $filepath = $file.FullName
    $filename = $file.BaseName+$file.Extension
    
    echo "FileHash = $filehash"
    echo "DateModified = $filedate"
    echo "Path = $filepath"
    
    if (!(Test-Path HKLM:\SOFTWARE\Siemens\Automation\Openness\16.0\Whitelist)) {
        [void](New-Item -Force -Path HKLM:\SOFTWARE\Siemens\Automation\Openness\16.0\Whitelist)
    }
    
    if (!(Test-Path HKLM:\SOFTWARE\Siemens\Automation\Openness\16.0\Whitelist\$filename)) {
        [void](New-Item -Path HKLM:\SOFTWARE\Siemens\Automation\Openness\16.0\Whitelist\$filename)
    }
    
    if (!(Test-Path HKLM:\SOFTWARE\Siemens\Automation\Openness\16.0\Whitelist\$filename\Entry)) {
        [void](New-Item -Path HKLM:\SOFTWARE\Siemens\Automation\Openness\16.0\Whitelist\$filename\Entry)
    }
    
    [void](New-ItemProperty -Force -Path HKLM:\SOFTWARE\Siemens\Automation\Openness\16.0\Whitelist\$filename\Entry -Name FileHash     -PropertyType string -Value $filehash)
    [void](New-ItemProperty -Force -Path HKLM:\SOFTWARE\Siemens\Automation\Openness\16.0\Whitelist\$filename\Entry -Name DateModified -PropertyType string -Value $filedate)
    [void](New-ItemProperty -Force -Path HKLM:\SOFTWARE\Siemens\Automation\Openness\16.0\Whitelist\$filename\Entry -name Path         -PropertyType string -Value $filepath)
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment