Skip to content

"Incorrect function" exception when running an exe not in C:\ #13605

@blancmangit

Description

@blancmangit

Steps to reproduce

C:\Users\mbj>C:\scoop\apps\powershell-preview\7.1.0-preview.7\pwsh.exe
PowerShell 7.1.0-preview.7
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

OperationStopped: C:\Users\mbj\Documents\PowerShell\Microsoft.PowerShell_profile.ps1:19
Line |
  19 |  cat $PROFILE_ORIG | H:\usr\bin\ssed.exe -n ("aliases","filters","path …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Incorrect function.

Loading personal and system profiles took 2426ms.
PS C:\Users\mbj>
1> h:\usr\bin\ssed.exe -n 19p $PROFILE
OperationStopped: Incorrect function.
PS C:\Users\mbj>
2>

Expected behavior

C:\Users\mbj>C:\scoop\apps\powershell-preview\7.1.0-preview.6\pwsh.exe
PowerShell 7.1.0-preview.6
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

   A new PowerShell preview release is available: v7.1.0-preview.7
   Upgrade now, or check out the release page at:
     https://aka.ms/PowerShell-Release?tag=v7.1.0-preview.7

Loading personal and system profiles took 1354ms.
PS C:\Users\mbj>
1> h:\usr\bin\ssed.exe -n 19p $PROFILE
cat $PROFILE_ORIG | H:\usr\bin\ssed.exe -n ("aliases","filters","path" |ForEach-Object{ "-e /^#region $_/,/^#endregion/p" }) | out-string | invoke-expression

Suggestion [4,General]: The most similar commands are: cmpcfg, tcfg, sacfg, pbcfg, rtcfg, gcfg, upcfg, copy, clc, cnsn.
PS C:\Users\mbj>
2>
C:\Users\mbj>
C:\Users\mbj>
C:\Users\mbj>C:\scoop\apps\powershell-preview\7.1.0-preview.5\pwsh.exe
PowerShell 7.1.0-preview.5
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

   A new PowerShell preview release is available: v7.1.0-preview.7
   Upgrade now, or check out the release page at:
     https://aka.ms/PowerShell-Release?tag=v7.1.0-preview.7

Loading personal and system profiles took 1360ms.
PS C:\Users\mbj>
1> h:\usr\bin\ssed.exe -n 19p $PROFILE
cat $PROFILE_ORIG | H:\usr\bin\ssed.exe -n ("aliases","filters","path" |ForEach-Object{ "-e /^#region $_/,/^#endregion/p" }) | out-string | invoke-expression

Suggestion [4,General]: The most similar commands are: cmpcfg, upcfg, sacfg, rtcfg, pbcfg, gcfg, tcfg, copy, clc, cnsn.
PS C:\Users\mbj>
2>
C:\Users\mbj>
C:\Users\mbj>
C:\Users\mbj>powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

commandline 2020-09-09T13:25:39.1303419Z C:\Users\mbj
$ h:\usr\bin\ssed.exe -n 19p $PROFILE
    Write-Host (get-location) -ForegroundColor Magenta
commandline 2020-09-09T13:25:46.5978391Z C:\Users\mbj
$

Actual behavior

Exception             : System.ComponentModel.Win32Exception (1): Incorrect function.
                           at Microsoft.PowerShell.Commands.InternalSymbolicLinkLinkCodeMethods.WinInternalGetTarget(SafeFileHandle handle)
                           at Microsoft.PowerShell.Commands.InternalSymbolicLinkLinkCodeMethods.WinInternalGetTarget(String path)
                           at System.Management.Automation.NativeCommandProcessor.CheckIfWindowsApplication(String fileName)
                           at System.Management.Automation.NativeCommandProcessor.get_IsWindowsApplication()
                           at System.Management.Automation.NativeCommandProcessor.CalculateIORedirection(Boolean& redirectOutput, Boolean& redirectError, Boolean& redirectInput)
                           at System.Management.Automation.NativeCommandProcessor.InitNativeProcess()
                           at System.Management.Automation.NativeCommandProcessor.Prepare(IDictionary psDefaultParameterValues)
                           at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
                           at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
                           at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
                           at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[]
                        pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
                           at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          :
CategoryInfo          : OperationStopped: (:) [], Win32Exception
FullyQualifiedErrorId : System.ComponentModel.Win32Exception
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, C:\Users\mbj\Documents\PowerShell\Microsoft.PowerShell_profile.ps1: line 19
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
PSMessageDetails      :

Environment data

PS C:\Users\mbj>
5> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.7
PSEdition                      Core
GitCommitId                    7.1.0-preview.7
OS                             Microsoft Windows 10.0.20206
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions