epotter
epotter

Reputation: 7799

Wix Custom Action fails to create SymbolicLink on Windows 7

I am working on a Wix installer that creates a SymbolicLink inside a custom action. The custom action is written in C#. It is creating the SymbolicLink by calling the CreateSymbolicLink Win32 API. On Windows 10, the call works perfectly. On Windows 7 it fails. If I call Marshal.GetLastWin32Error(), it returns an error code of 997, which is ERROR_IO_PENDING

Here is the line of code the calls the API:

var result = CreateSymbolicLink(pathToCreateLink, installDir, SymbolicLinkFlags.Directory | SymbolicLinkFlags.UnprivilegedCreate);
if(!result)
{
     _logger.Log($"Win32 Error Code: {Marshal.GetLastWin32Error()}");
}

Here is the Dll Import:

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool CreateSymbolicLink( string lpSymlinkFileName, string pTargetFileName, SymbolicLinkFlags dwFlags);

The custom action is invoked with Execute set to "deferred" and Impersonate set to "no".

If I put the line of C# code in a console application, it functions correctly (even on Windows 7). So there is something about how the code is being called in the installer that is causing the error.

Part of my problem is that I can find very little information on the error code, so I can't be sure what to try to fix it.

Upvotes: 0

Views: 176

Answers (2)

Gerardo Grignoli
Gerardo Grignoli

Reputation: 15177

MSI packages run as System TrustedInstaller, and on Windows 7 that user does not have access to create SymLinks with the default Local Security Policy.

I fixed it by using junctions instead (mklink /j), but that only works for folders.

Upvotes: 0

Alex
Alex

Reputation: 21

A kind of confirmation can be found in wixsharp code. They encountered this problem and could not surpass it. https://github.com/oleg-shilo/wixsharp/blob/master/Source/src/WixSharp/ResilientPackage.cs

The w/a I implemented in my installer is repeating symbolic links creation via cmd tool mklink and if it fails as well, just copy files.

Upvotes: 1

Related Questions