# ROS2Lab - Check my PC (Windows 10 and 11). Works in a NORMAL PowerShell window (no administrator needed). # # irm https://www.ros2lab.com/install/check.ps1 | iex # # STATUS: NOT yet run on a real Windows PC (written and reviewed on Linux). Windows PowerShell 5.1 and PowerShell 7. # READ-ONLY. It installs nothing, changes nothing, needs no password and writes no file. # What it reads: Win32_OperatingSystem, Win32_Processor, Win32_ComputerSystem and Win32_VideoController (CIM), the # registry values CurrentBuildNumber and UBR under HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion, the free space of # your system drive (C:), "wsl.exe --version" and "wsl.exe --list --quiet" (these start no Linux distribution), and one # download from packages.ros.org (the ROS 2 package list, up to 8 seconds, kept in memory only, thrown away) to see # your internet speed. # Where the result goes: it is printed here. Then it is kept ready on THIS computer only (127.0.0.1, port 7776) for up to # 10 minutes, so that the ROS2Lab page open in your browser can read it when you press "Read the result from my PC". # Nothing is sent to the internet. Ctrl+C stops it at any time. $env:ROS2LAB_NO_SERVE = "1" prints only. # Everything runs inside one script block: it never calls exit (that would close the window when piped to iex) and # leaves no variables or functions behind in your PowerShell session. & { $inv = [System.Globalization.CultureInfo]::InvariantCulture $Origin = "https://www.ros2lab.com"; if ($env:ROS2LAB_ORIGIN) { $Origin = $env:ROS2LAB_ORIGIN } $Port = 7776; $pp = 0; if ([int]::TryParse([string]$env:ROS2LAB_CHECK_PORT, [ref]$pp)) { $Port = $pp } # one line, printable ASCII only, single spaces; empty -> unknown function One($v) { if ($null -eq $v) { return "unknown" } $s = (([string]$v) -replace '[^\x20-\x7E]', ' ' -replace ' +', ' ').Trim() if ($s -eq "") { return "unknown" } return $s } function YesNo($v) { if ($v -is [bool]) { if ($v) { return "yes" } else { return "no" } } return "unknown" } function Gb($bytes) { try { if ($bytes -and [double]$bytes -gt 0) { return ([double]$bytes / 1GB).ToString("0.0", $inv) } } catch {} return "unknown" } $os = "unknown"; try { $os = One (Get-CimInstance Win32_OperatingSystem -ErrorAction Stop).Caption } catch {} $osBuild = "unknown"; $osUbr = "unknown" try { $cv = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -ErrorAction Stop $osBuild = One $cv.CurrentBuildNumber; $osUbr = One $cv.UBR } catch {} # a 32-bit PowerShell on 64-bit Windows sees x86 here; the real architecture is then in PROCESSOR_ARCHITEW6432 $arch = One $env:PROCESSOR_ARCHITECTURE; if ($env:PROCESSOR_ARCHITEW6432) { $arch = One $env:PROCESSOR_ARCHITEW6432 } $cpu = "unknown"; $cores = "unknown"; $virt = "unknown"; $slat = "unknown" try { $procs = @(Get-CimInstance Win32_Processor -ErrorAction Stop) if ($procs.Count -gt 0) { $cpu = One $procs[0].Name $virt = YesNo $procs[0].VirtualizationFirmwareEnabled $slat = YesNo $procs[0].SecondLevelAddressTranslationExtensions $nc = 0; foreach ($pr in $procs) { $nc += [int]$pr.NumberOfLogicalProcessors } if ($nc -gt 0) { $cores = "$nc" } } } catch {} $ram = "unknown"; $hyp = "unknown" try { $cs = Get-CimInstance Win32_ComputerSystem -ErrorAction Stop $ram = Gb $cs.TotalPhysicalMemory; $hyp = YesNo $cs.HypervisorPresent } catch {} $diskPath = One $env:SystemDrive; $disk = "unknown" try { $disk = Gb (New-Object System.IO.DriveInfo -ArgumentList $env:SystemDrive).AvailableFreeSpace } catch {} $gpu = "unknown"; $gpuDrv = "unknown" try { $vcs = @(Get-CimInstance Win32_VideoController -ErrorAction Stop) if ($vcs.Count -gt 0) { $gpu = One (($vcs | ForEach-Object { One $_.Name }) -join " + ") $gpuDrv = One (($vcs | ForEach-Object { $vc = $_; $dd = "unknown" try { if ($vc.DriverDate -is [datetime]) { $dd = $vc.DriverDate.ToString("yyyy-MM-dd", $inv) } } catch {} (One $vc.DriverVersion) + " " + $dd }) -join " + ") } } catch {} # wsl.exe prints UTF-16; read it as Unicode, drop NULs, wait at most 15 s. Only --version and --list: no distribution starts. $wslExe = Join-Path $env:SystemRoot "Sysnative\wsl.exe" if (-not (Test-Path $wslExe)) { $wslExe = Join-Path $env:SystemRoot "System32\wsl.exe" } function RunWsl($argLine) { try { $psi = New-Object System.Diagnostics.ProcessStartInfo $psi.FileName = $wslExe; $psi.Arguments = $argLine $psi.UseShellExecute = $false; $psi.CreateNoWindow = $true $psi.RedirectStandardOutput = $true; $psi.RedirectStandardError = $true $psi.StandardOutputEncoding = [System.Text.Encoding]::Unicode $proc = [System.Diagnostics.Process]::Start($psi) $outTask = $proc.StandardOutput.ReadToEndAsync(); $null = $proc.StandardError.ReadToEndAsync() if (-not $proc.WaitForExit(15000)) { try { $proc.Kill() } catch {}; return $null } if ($proc.ExitCode -ne 0) { return $null } return ($outTask.Result -replace "`0", "") } catch { return $null } } $wsl = "not installed"; $distros = "none"; $u2404 = "no" if (Test-Path $wslExe) { $t = RunWsl "--version" if ($t) { $l1 = @($t -split "`r?`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne "" }) | Select-Object -First 1 if ($l1) { $wsl = One $l1 } } $t = RunWsl "--list --quiet" if ($t) { $names = @($t -split "`r?`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne "" }) if ($names.Count -gt 0) { $distros = One ($names -join ", ") if ($names -contains "Ubuntu-24.04") { $u2404 = "yes" } # an old inbox wsl.exe has no --version but can still list distributions: do not call that "not installed" if ($wsl -eq "not installed") { $wsl = "installed (wsl --version not supported)" } } } } $netRos = "no"; $mbps = "0" $resp = $null try { $sw = [System.Diagnostics.Stopwatch]::StartNew() $req = [System.Net.HttpWebRequest]::Create("http://packages.ros.org/ros2/ubuntu/dists/noble/main/binary-amd64/Packages") $req.Timeout = 8000; $req.ReadWriteTimeout = 8000 $resp = $req.GetResponse() if ([int]$resp.StatusCode -eq 200) { # like curl --max-time 8: a 200 answer counts even when the 8 seconds end before the list is complete $netRos = "yes"; $total = 0 try { $st = $resp.GetResponseStream(); $buf = New-Object byte[] 65536 while ($sw.ElapsedMilliseconds -lt 8000) { $n = $st.Read($buf, 0, $buf.Length); if ($n -le 0) { break }; $total += $n } } catch {} $secs = $sw.Elapsed.TotalSeconds if ($secs -gt 0) { $mbps = ($total * 8 / $secs / 1000000).ToString("0.0", $inv) } } } catch { } finally { if ($resp) { try { $resp.Close() } catch {} } } $R = @( "===== ROS2LAB PC CHECK 1 =====", "system: windows", "os: $os", "os_build: $osBuild", "os_ubr: $osUbr", "arch: $arch", "cpu: $cpu", "cores: $cores", "ram_gb: $ram", "disk_free_gb: $disk", "disk_path: $diskPath", "gpu: $gpu", "gpu_driver: $gpuDrv", "virt_firmware: $virt", "hypervisor: $hyp", "slat: $slat", "wsl: $wsl", "wsl_distros: $distros", "ubuntu_2404: $u2404", "net_ros: $netRos", "net_mbps: $mbps", "===== END =====" ) -join "`n" Write-Host ""; Write-Host $R; Write-Host "" if ($env:ROS2LAB_NO_SERVE -eq "1") { return } Write-Host 'Now go back to the ROS2Lab page and press "Read the result from my PC".' Write-Host "(The result waits on this computer only, for up to 10 minutes. Ctrl+C stops. Or copy the lines above and paste them into the page.)" $body = [System.Text.Encoding]::ASCII.GetBytes($R) $common = "Access-Control-Allow-Origin: $Origin`r`nAccess-Control-Allow-Private-Network: true`r`nContent-Type: text/plain; charset=utf-8`r`nCache-Control: no-store`r`nConnection: close`r`n" $h200 = [System.Text.Encoding]::ASCII.GetBytes("HTTP/1.1 200 OK`r`n" + $common + "Content-Length: $($body.Length)`r`n`r`n") $h204 = [System.Text.Encoding]::ASCII.GetBytes("HTTP/1.1 204 No Content`r`n" + $common + "`r`n") $h404 = [System.Text.Encoding]::ASCII.GetBytes("HTTP/1.1 404 Not Found`r`n" + $common + "Content-Length: 0`r`n`r`n") $listener = $null try { $listener = [System.Net.Sockets.TcpListener]::new([System.Net.IPAddress]::Loopback, $Port) $listener.Start() } catch { Write-Host ("Could not keep the result ready (" + $_.Exception.Message + "). Copy the lines above and paste them into the page.") if ($listener) { try { $listener.Stop() } catch {} } return } $got = $false try { $deadline = (Get-Date).AddMinutes(10) while (-not $got -and (Get-Date) -lt $deadline) { if (-not $listener.Pending()) { Start-Sleep -Milliseconds 200; continue } $client = $listener.AcceptTcpClient() try { $client.ReceiveTimeout = 3000; $client.SendTimeout = 3000 $ns = $client.GetStream() $rb = New-Object byte[] 8192; $head = "" while ($head.IndexOf("`r`n`r`n") -lt 0 -and $head.Length -lt 16384) { $n = $ns.Read($rb, 0, $rb.Length); if ($n -le 0) { break } $head += [System.Text.Encoding]::ASCII.GetString($rb, 0, $n) } $first = ($head -split "`r?`n")[0] if ($first -like "OPTIONS *") { $ns.Write($h204, 0, $h204.Length) } elseif ($head -notmatch "(?im)^Host:\s*(127\.0\.0\.1|localhost)(:\d+)?\s*$") { $ns.Write($h404, 0, $h404.Length) } elseif ($first -like "GET /check HTTP/*") { $ns.Write($h200, 0, $h200.Length); $ns.Write($body, 0, $body.Length); $ns.Flush(); $got = $true } else { $ns.Write($h404, 0, $h404.Length) } } catch { } finally { $client.Close() } } } finally { $listener.Stop() if ($got) { Write-Host "The page has read the result. Done." } else { Write-Host "Stopped. Nothing was sent." } } }