Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ release notes.

## [Unreleased]

Nothing yet.
### Fixed

- A Win32 install or uninstall command named as a bare batch file (`install.cmd`) failed with
"'install.cmd' is not recognized" from `Invoke-IntuneWin32AppTest` on a machine where
`NoDefaultCurrentDirectoryInExePath` is set in the caller's environment, a per-user shell
setting that stops `cmd.exe` looking in its working folder. The agent's `cmd.exe` runs without
the caller's profile, so the harness now starts its child processes without the variable.

## [0.29.0] - 2026-10-07

Expand Down
4 changes: 4 additions & 0 deletions Private/Invoke-IslProcess.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
if ($desktopModulePath) { $startInfo.Environment['PSModulePath'] = $desktopModulePath }
else { $null = $startInfo.Environment.Remove('PSModulePath') }
}
# With NoDefaultCurrentDirectoryInExePath set in the caller's own environment, cmd.exe does
# not look in its working folder, and a bare 'install.cmd' fails with "not recognized". The
# agent's cmd.exe runs without the caller's profile, so the child runs without the setting
$null = $startInfo.Environment.Remove('NoDefaultCurrentDirectoryInExePath')

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unconditionally rather than only when set: Remove on a missing key returns false and nothing else, and the task modes below are left alone on purpose. A scheduled task runs with the SYSTEM or the other account's environment, where a caller's per-user setting is not present, which is also the environment the agent's own cmd.exe has.


$process = [System.Diagnostics.Process]::new()
$process.StartInfo = $startInfo
Expand Down
20 changes: 20 additions & 0 deletions Tests/Unit/Private/Invoke-IslProcess.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ Describe 'Invoke-IslProcess' -Tag 'Unit', 'Private' {
$result.StdOut.Trim() | Should-Be $TestDrive
}

It 'lets cmd.exe find a batch file in the working folder whatever the caller''s own shell setting' {
# NoDefaultCurrentDirectoryInExePath in the caller's environment stops cmd.exe looking in
# the working folder; the agent's cmd.exe has no such setting, so the child must not either
Set-Content -Path (Join-Path $TestDrive 'install.cmd') -Value '@echo ran' -Encoding ascii
$saved = $env:NoDefaultCurrentDirectoryInExePath
$env:NoDefaultCurrentDirectoryInExePath = '1'

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set in the test's own process rather than mocked, because the thing under test is what the child inherits from the parent. Without the fix this exact run fails with "'install.cmd' is not recognized" (exit 1), which is how the problem showed up on a developer machine with the variable in the user environment.

try {
$result = Invoke-Process @{
FilePath = $script:Cmd; Arguments = '/C "install.cmd"'
WorkingDirectory = $TestDrive; WorkFolder = $TestDrive
}
}
finally {
$env:NoDefaultCurrentDirectoryInExePath = $saved
}
$result.ExitCode | Should-Be 0
$result.StdOut.Trim() | Should-Be 'ran'
$result.StdErr.Trim() | Should-Be ''
}

It 'closes stdin so a read returns instead of waiting' {
$result = Invoke-Process @{
FilePath = $script:Cmd; Arguments = '/C set /p answer=name? & echo [%answer%]'
Expand Down
Loading