"Incorrect function" exception when running an exe not in C:\
See original GitHub issueSteps 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13
Top Results From Across the Web
utility.exe - incorrect function
Press WIndows key + I and access Applications; Select the Lenovo Utility app and click Uninstall; Go to Lenovo's website and download the...
Read more >How to fix "Incorrect function" error in Windows? - ugetfix.com
Hello. Every time I bootup my Windows PC I receive an error 'Incorrect function' and it directs to Windows apps > Win32Bridge.Server.exe.
Read more >Win32Bridge.server.exe Error on Windows 10/11
If the files required for your system to function properly are corrupted, you may run into the 'Win32Bridge.Server.exe Incorrect function' issue ...
Read more >visual studio 2010 - When compiling, "Incorrect function" error
I'm trying to build a VS 2010 web project and I'm getting this error: Could not write to output file 'C:\Users\me\myProject\obj\Debug\myProject.
Read more >Resolving 'Incorrect function' error Deploying custom software ...
The "Incorrect Function" error when deploying custom software like Adobe or Microsoft Office is returned by the operating system.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m 95% certain that exfat has no support for reparse points which explains why DeviceIoControl is returning
ERROR_INVALID_FUNCTIONfor objects on that file system. The PowerShell code would have to be modified to handle such a situation. GetVolumeInformationByHandleW can be used to detect if the volume supports reparse points but honestly it seems like just ignoringERROR_INVALID_FUNCTIONis easier.The failure here is occurring when PowerShell checks to see if
ssed.exeis a reparse point and to get the target to execute of that reparse point. The error is being raised in WinInternalGetTarget and based on the message that is returned I would bet that it’s the call to DeviceIOControl that is returning the exception.The underlying Win32 error is ERROR_INVALID_FUNCTION which has the message matching the error PowerShell reports back
The docs for FSCTL_GET_REPARSE_POINT indicate the types of filesystems that support this FSCTL code but I would also guess that
H:is an FAT32 formatted drive (or something that is not NTFS/ReFS). The fact that the path ofssedis inH:\usr\bin\makes it sound like it’s a WSL path. Knowing if you are using WSL 1 or WSL 2 would be helpful, or even what is backing the H drive and how it is formatted.It sounds like we need to have a further check on
WinInternalGetTargetto only callDeviceIoControlif the Reparse Point attribute is there or just addERROR_INVALID_FUNCTIONto the list of error codes to ignore for this call.