mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Windows: Support notifying WAITFOR.EXE Windows command when VeraCrypt.exe exits if /q was specified in CLI. This done using the new switch "/signalExit" who must have a string parameter that must be the same as the one that will be specified for WAITFOR.EXE command.
This commit is contained in:
@@ -181,6 +181,8 @@ static int bPrebootPasswordDlgMode = FALSE;
|
|||||||
static int NoCmdLineArgs;
|
static int NoCmdLineArgs;
|
||||||
static BOOL CmdLineVolumeSpecified;
|
static BOOL CmdLineVolumeSpecified;
|
||||||
static int LastDriveListVolumeColumnWidth;
|
static int LastDriveListVolumeColumnWidth;
|
||||||
|
static BOOL ExitMailSlotSpecified = FALSE;
|
||||||
|
static TCHAR ExitMailSlotName[MAX_PATH];
|
||||||
// WTS handling
|
// WTS handling
|
||||||
static HMODULE hWtsLib = NULL;
|
static HMODULE hWtsLib = NULL;
|
||||||
static WTSREGISTERSESSIONNOTIFICATION fnWtsRegisterSessionNotification = NULL;
|
static WTSREGISTERSESSIONNOTIFICATION fnWtsRegisterSessionNotification = NULL;
|
||||||
@@ -6780,6 +6782,41 @@ void DisplayDriveListContextMenu (HWND hwndDlg, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// broadcast signal to WAITFOR.EXE MailSlot to notify any waiting instance that we are exiting
|
||||||
|
static void SignalExitCode (int exitCode)
|
||||||
|
{
|
||||||
|
if (ExitMailSlotSpecified)
|
||||||
|
{
|
||||||
|
HANDLE hFile;
|
||||||
|
hFile = CreateFile (ExitMailSlotName,
|
||||||
|
GENERIC_WRITE,
|
||||||
|
FILE_SHARE_READ,
|
||||||
|
(LPSECURITY_ATTRIBUTES) NULL,
|
||||||
|
OPEN_EXISTING,
|
||||||
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
|
(HANDLE) NULL);
|
||||||
|
if ((hFile == INVALID_HANDLE_VALUE) && (GetLastError () == ERROR_FILE_NOT_FOUND))
|
||||||
|
{
|
||||||
|
// MailSlot not found, wait 1 second and try again in case we exited too quickly
|
||||||
|
Sleep (1000);
|
||||||
|
hFile = CreateFile (ExitMailSlotName,
|
||||||
|
GENERIC_WRITE,
|
||||||
|
FILE_SHARE_READ,
|
||||||
|
(LPSECURITY_ATTRIBUTES) NULL,
|
||||||
|
OPEN_EXISTING,
|
||||||
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
|
(HANDLE) NULL);
|
||||||
|
}
|
||||||
|
if (hFile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
char szMsg[64];
|
||||||
|
DWORD cbWritten;
|
||||||
|
StringCbPrintfA (szMsg, sizeof (szMsg), "VeraCrypt Exit %d", exitCode);
|
||||||
|
WriteFile(hFile, szMsg, (DWORD) (strlen (szMsg) +1), &cbWritten, (LPOVERLAPPED) NULL);
|
||||||
|
CloseHandle (hFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Except in response to the WM_INITDIALOG and WM_ENDSESSION messages, the dialog box procedure
|
/* Except in response to the WM_INITDIALOG and WM_ENDSESSION messages, the dialog box procedure
|
||||||
should return nonzero if it processes a message, and zero if it does not. */
|
should return nonzero if it processes a message, and zero if it does not. */
|
||||||
@@ -7126,7 +7163,10 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
if (Quit)
|
if (Quit)
|
||||||
{
|
{
|
||||||
if (TaskBarIconMutex == NULL)
|
if (TaskBarIconMutex == NULL)
|
||||||
|
{
|
||||||
|
SignalExitCode (exitCode);
|
||||||
exit (exitCode);
|
exit (exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
MainWindowHidden = TRUE;
|
MainWindowHidden = TRUE;
|
||||||
|
|
||||||
@@ -7138,6 +7178,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
{
|
{
|
||||||
if (TaskBarIconMutex)
|
if (TaskBarIconMutex)
|
||||||
TaskBarIconRemove (hwndDlg);
|
TaskBarIconRemove (hwndDlg);
|
||||||
|
SignalExitCode (exitCode);
|
||||||
exit (exitCode);
|
exit (exitCode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -8890,6 +8931,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
|
|||||||
OptionSecureDesktop,
|
OptionSecureDesktop,
|
||||||
OptionDisableDeviceUpdate,
|
OptionDisableDeviceUpdate,
|
||||||
OptionEnableMemoryProtection,
|
OptionEnableMemoryProtection,
|
||||||
|
OptionSignalExit,
|
||||||
};
|
};
|
||||||
|
|
||||||
argument args[]=
|
argument args[]=
|
||||||
@@ -8920,6 +8962,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
|
|||||||
{ OptionSecureDesktop, L"/secureDesktop", NULL, FALSE },
|
{ OptionSecureDesktop, L"/secureDesktop", NULL, FALSE },
|
||||||
{ OptionDisableDeviceUpdate, L"/disableDeviceUpdate", NULL, FALSE },
|
{ OptionDisableDeviceUpdate, L"/disableDeviceUpdate", NULL, FALSE },
|
||||||
{ OptionEnableMemoryProtection, L"/protectMemory", NULL, FALSE },
|
{ OptionEnableMemoryProtection, L"/protectMemory", NULL, FALSE },
|
||||||
|
{ OptionSignalExit, L"/signalExit", NULL, FALSE },
|
||||||
};
|
};
|
||||||
|
|
||||||
argumentspec as;
|
argumentspec as;
|
||||||
@@ -9022,6 +9065,17 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OptionSignalExit:
|
||||||
|
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i,
|
||||||
|
nNoCommandLineArgs, tmpPath, ARRAYSIZE (tmpPath)))
|
||||||
|
{
|
||||||
|
StringCbPrintfW (ExitMailSlotName, sizeof (ExitMailSlotName), L"\\\\.\\mailslot\\WAITFOR.EXE\\%s", tmpPath);
|
||||||
|
ExitMailSlotSpecified = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
AbortProcess ("COMMAND_LINE_ERROR");
|
||||||
|
break;
|
||||||
|
|
||||||
case OptionCache:
|
case OptionCache:
|
||||||
{
|
{
|
||||||
wchar_t szTmp[16] = {0};
|
wchar_t szTmp[16] = {0};
|
||||||
|
|||||||
Reference in New Issue
Block a user