Code Monkey home page Code Monkey logo

Comments (3)

mosra avatar mosra commented on September 24, 2024

Interesting, apparently I overlooked this error case.

I have a fix locally, but would like to have an explicit test for it -- do you still have access to the home-less VM runner to explore a bit? In particular I'd like to know what environment variables are present there, especially %HOMEPATH% and %USERPROFILE%, or whether they're set to empty, to independently detect such case in a test. Thank you!

from corrade.

Squareys avatar Squareys commented on September 24, 2024

I seem to be unable to find documentation on what environment is present for local system/service accounts on Windows, hence I tried running a powershell script as a local service account to grep the environment. (Using this for the system account execution and this for retrieving the environment. The script is attached for reference.

That returned nothing at all, so I am suspecting that system/service accounts don't have access to the environment at all. This post hints and individual variables needing explicit access to environment variables, controlled by Windows registry values.

Powershell script for grepping the environment as system user
$ErrorActionPreference = 'Stop'

Clear-Host

$taskName = "it3xl_dummy_PowerShell_job"
# Unregister-ScheduledJob it3xl_dummy_PowerShell_job -Confirm:$false

$task = Get-ScheduledJob -Name $taskName  -ErrorAction SilentlyContinue
if ($task -ne $null)
{
    Unregister-ScheduledJob $task  -Confirm:$false
    Write-Host "Old $taskName job has been unregistered"; Write-Host;
}


$trigger = New-JobTrigger -AtStartup;

$options = New-ScheduledJobOption -StartIfOnBattery  -RunElevated;

Write-Host "Registering new $taskName job";
Register-ScheduledJob -Name $taskName  -Trigger $trigger  -ScheduledJobOption $options `
    -ScriptBlock {
    $somthing = Get-ChildItem env:
    Write-Host $something
}


#$accountId = "NT AUTHORITY\SYSTEM";
$accountId = "NT AUTHORITY\LOCAL SERVICE";
$principal = New-ScheduledTaskPrincipal -UserID $accountId `
    -LogonType ServiceAccount  -RunLevel Highest;

$psSobsSchedulerPath = "\Microsoft\Windows\PowerShell\ScheduledJobs";
$someResult = Set-ScheduledTask -TaskPath $psSobsSchedulerPath `
    -TaskName $taskName  -Principal $principal


Write-Host;
Write-Host "Let's show proofs that our PowerShell job will be running under the LocalSytem account"
$task = Get-ScheduledTask -TaskName $taskName
$task.Principal

Write-Host "Let's start $taskName"
Start-Job -DefinitionName $taskName | Format-Table

Write-Host "Let's proof that our PowerShell job was ran"
Start-Sleep -Seconds 3
Receive-Job -Name $taskName

from corrade.

mosra avatar mosra commented on September 24, 2024

Awesome, so for testing it might be enough to just check that %APPDATA% or %HOMEPATH% doesn't exist. I made an attempt on a fix and a test in 94f841e (on the next directory-home-graceful-fail branch, #141), could you try to run UtilityPathTest under the system account? The test should fail because I don't know what error message to accept, if you could then paste the whole output here that'd be great.

Thanks in advance! :)

from corrade.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.