Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Common/Dlgcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ HWND MainDlg = NULL;
wchar_t *lpszTitle = NULL;

BOOL Silent = FALSE;
/* TRUE when the process terminates as soon as the command line request has been
carried out (/q). Shell notifications must then be delivered synchronously,
otherwise the process is gone before Explorer processes them. Note that this
is independent of Silent: /q controls whether we exit, /s only suppresses the
user interface, and either may be given without the other. */
BOOL ProcessExitsAfterCommand = FALSE;
BOOL bPreserveTimestamp = TRUE;
BOOL bShowDisconnectedNetworkDrives = FALSE;
BOOL bHideWaitingDialog = FALSE;
Expand Down Expand Up @@ -9789,13 +9795,16 @@ static BOOL UnmountVolumeBase (HWND hwndDlg, int nDosDriveNo, BOOL forceUnmount,

BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, nDosDriveNo, 0);

/* GH #337, GH #1426: When running in silent/CLI mode, the process may
/* GH #337, GH #1426: When running from the command line, the process may
exit immediately after unmount. BroadcastDeviceChange sends
SHChangeNotify asynchronously, so Explorer may not process the drive
removal before the process exits, leaving a ghost drive letter.
Re-send the notification with SHCNF_FLUSH to force synchronous
processing by Explorer before we return. */
if (Silent)
processing by Explorer before we return.
ProcessExitsAfterCommand covers /q, which is what actually makes the
process exit; testing Silent alone missed "VeraCrypt /d X: /q" because
/q does not imply /s. */
if (Silent || ProcessExitsAfterCommand)
{
wchar_t root[] = { (wchar_t) (nDosDriveNo + L'A'), L':', L'\\', 0 };
SHChangeNotify (SHCNE_DRIVEREMOVED, SHCNF_PATH | SHCNF_FLUSH, root, NULL);
Expand Down
1 change: 1 addition & 0 deletions src/Common/Dlgcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ extern int ScreenDPI;
extern double DlgAspectRatio;
extern HWND MainDlg;
extern BOOL Silent;
extern BOOL ProcessExitsAfterCommand;
extern BOOL bHistory;
extern BOOL bPreserveTimestamp;
extern BOOL bShowDisconnectedNetworkDrives;
Expand Down
12 changes: 8 additions & 4 deletions src/Mount/Mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -6316,10 +6316,12 @@ static BOOL DismountAll (HWND hwndDlg, BOOL forceUnmount, BOOL interact, int dis

BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountList.ulMountedDrives & ~mountList.ulMountedDrives);

/* GH #337, GH #1426: Flush shell notifications synchronously in
silent/CLI mode to prevent ghost drive letters when the process
exits immediately after dismount. */
if (Silent)
/* GH #337, GH #1426: Flush shell notifications synchronously when running
from the command line, to prevent ghost drive letters when the process
exits immediately after dismount. ProcessExitsAfterCommand covers /q,
which is what actually makes the process exit; testing Silent alone
missed "VeraCrypt /d /q" because /q does not imply /s. */
if (Silent || ProcessExitsAfterCommand)
{
DWORD removedDrives = prevMountList.ulMountedDrives & ~mountList.ulMountedDrives;
for (i = 0; i < 26; i++)
Expand Down Expand Up @@ -10577,6 +10579,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
else if (!_wcsicmp (szTmp, L"preferences"))
{
Quit = TRUE;
ProcessExitsAfterCommand = TRUE;
UsePreferences = TRUE;
break;
}
Expand All @@ -10589,6 +10592,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
}

Quit = TRUE;
ProcessExitsAfterCommand = TRUE;
UsePreferences = FALSE;
}
break;
Expand Down
Loading