Skip to content

Commit

Permalink
Merge pull request #312 from 'rseanhall-bug4857'
Browse files Browse the repository at this point in the history
Close #312
  • Loading branch information
robmen committed Jan 24, 2016
2 parents 1bf9fa0 + 67df86a commit 81ab34e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions history/4857.md
@@ -0,0 +1 @@
* SeanHall: WIXBUG:4857 - Fix DTF custom actions in Win10 Apps and Features.
50 changes: 29 additions & 21 deletions src/DTF/Tools/SfxCA/SfxCA.cpp
Expand Up @@ -107,33 +107,42 @@ int InvokeOutOfProcManagedCustomAction(MSIHANDLE hSession, const wchar_t* szEntr
wchar_t szModule[MAX_PATH] = {0};
GetModuleFileName(g_hModule, szModule, MAX_PATH);

const wchar_t* rundll32 = L"rundll32.exe";
wchar_t szSystemPath[MAX_PATH] = {0};
GetSystemDirectory(szSystemPath, MAX_PATH);

wchar_t szRunDll32Path[MAX_PATH] = {0};
GetSystemDirectory(szRunDll32Path, MAX_PATH);
wcscat_s(szRunDll32Path, MAX_PATH, L"\\");
wcscat_s(szRunDll32Path, MAX_PATH, rundll32);
wcscat_s(szRunDll32Path, MAX_PATH, szSystemPath);
wcscat_s(szRunDll32Path, MAX_PATH, L"\\rundll32.exe");

const wchar_t* entry = L"zzzzInvokeManagedCustomActionOutOfProc";
wchar_t szCommandLine[1024] = {0};
swprintf_s(szCommandLine, 1024, L"%s \"%s\",%s %s %d %s",
rundll32, szModule, entry, szSessionName, hSession, szEntryPoint);

STARTUPINFO si;
SecureZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);

PROCESS_INFORMATION pi;
SecureZeroMemory(&pi, sizeof(PROCESS_INFORMATION));

if (!CreateProcess(szRunDll32Path, szCommandLine, NULL, NULL, FALSE,
0, NULL, NULL, &si, &pi))
swprintf_s(szCommandLine, 1024, L"\"%s\",%s %s %d %s",
szModule, entry, szSessionName, hSession, szEntryPoint);

SHELLEXECUTEINFO sei;
SecureZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC;
sei.lpVerb = L"open";
sei.lpFile = szRunDll32Path;
sei.lpDirectory = szSystemPath;
sei.lpParameters = szCommandLine;
sei.nShow = SW_HIDE;

if (!ShellExecuteEx(&sei))
{
DWORD err = GetLastError();
Log(hSession, L"Failed to create new CA process via RUNDLL32. Error code: %d", err);
Log(hSession, L"Failed to shellex new CA process via RUNDLL32. Error code: %d", err);
return ERROR_INSTALL_FAILURE;
}

if (!sei.hProcess)
{
Log(hSession, L"shellex didn't return a process handle.");
return ERROR_INSTALL_FAILURE;
}

DWORD dwWait = WaitForSingleObject(pi.hProcess, INFINITE);
DWORD dwWait = WaitForSingleObject(sei.hProcess, INFINITE);
if (dwWait != WAIT_OBJECT_0)
{
DWORD err = GetLastError();
Expand All @@ -142,7 +151,7 @@ int InvokeOutOfProcManagedCustomAction(MSIHANDLE hSession, const wchar_t* szEntr
}

DWORD dwExitCode;
BOOL bRet = GetExitCodeProcess(pi.hProcess, &dwExitCode);
BOOL bRet = GetExitCodeProcess(sei.hProcess, &dwExitCode);
if (!bRet)
{
DWORD err = GetLastError();
Expand All @@ -155,8 +164,7 @@ int InvokeOutOfProcManagedCustomAction(MSIHANDLE hSession, const wchar_t* szEntr
return ERROR_INSTALL_FAILURE;
}

CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(sei.hProcess);

remote.WaitExitCode();
return remote.ExitCode;
Expand Down
Expand Up @@ -40,7 +40,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="$(WIX)sdk\VS2012\inc"
AdditionalIncludeDirectories="$(WIX)sdk\VS2015\inc"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;CUSTOMACTIONTEST_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand All @@ -62,7 +62,7 @@
Name="VCLinkerTool"
AdditionalDependencies="msi.lib dutil.lib wcautil.lib Version.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="$(WIX)sdk\VS2012\lib\x86"
AdditionalLibraryDirectories="$(WIX)sdk\VS2015\lib\x86"
ModuleDefinitionFile="CustomAction.def"
GenerateDebugInformation="true"
SubSystem="2"
Expand Down Expand Up @@ -117,7 +117,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="$(WIX)sdk\VS2012\inc"
AdditionalIncludeDirectories="$(WIX)sdk\VS2015\inc"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;CUSTOMACTIONTEST_EXPORTS"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
Expand All @@ -138,7 +138,7 @@
Name="VCLinkerTool"
AdditionalDependencies="msi.lib dutil.lib wcautil.lib Version.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="$(WIX)sdk\VS2012\lib\x86"
AdditionalLibraryDirectories="$(WIX)sdk\VS2015\lib\x86"
ModuleDefinitionFile="CustomAction.def"
GenerateDebugInformation="true"
SubSystem="2"
Expand Down

0 comments on commit 81ab34e

Please sign in to comment.