Skip to content

Commit

Permalink
Check if running in system context
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrodksmith authored Mar 14, 2024
1 parent 3a0123e commit 9ef920a
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Private/Helpers/Test-BrowserSupport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function Test-BrowserSupport {
.EXAMPLE
Test-BrowserSupport -Browser "Chrome"
Test-BrowserSupport -Browser "Edge"
.PARAMETER Browser
What browser to check if we can run
Expand All @@ -18,18 +19,42 @@ function Test-BrowserSupport {
[Parameter(Mandatory = $false)]
[String]$Browser= $Seleniumdrivermode
)
# Check if running in system context
function Test-SystemContext {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$currentUserSid = $currentUser.User.Value

# The SID for the SYSTEM account
$systemSid = "S-1-5-18"

if ($currentUserSid -eq $systemSid) {
Write-Verbose "Running in SYSTEM context."
return $true
} else {
Write-Verbose "Not running in SYSTEM context."
return $false
}
}

# Check if Edge and Chrome Installed
$chrome = Test-SoftwareInstalled -SoftwareName "Google Chrome"
$edge = Test-SoftwareInstalled -SoftwareName "Microsoft Edge"
$loggedInUsers = Get-LoggedInUser
$systemcontext = Test-SystemContext

# Check if Edge can be used
if($edge.installed -eq $true) {
if (($loggedInUsers = Get-LoggedInUser) -eq $false) {
Write-Host "No user logged in cannot run Edge without user logged in"
$edgesupport = $false
} else{
$edgesupport = $true
if($systemcontext -eq $true) {
$edgesupport = $true
} else {
Write-Host "Script not running system context cannot run Edge without system context"
$edgesupport = $false
}

}
}

Expand Down

0 comments on commit 9ef920a

Please sign in to comment.