FIX: Bug [0001073] Start exe from command line should not inherit cashed PATH variable

This commit is contained in:
Alexander Koblov 2016-11-14 18:53:03 +00:00
commit 261dd30175
2 changed files with 45 additions and 1 deletions

View file

@ -79,7 +79,7 @@ uses
//DC
uFileProcs, uOSUtils, fOptionsMisc, uKASToolItemsExtended,
DCClassesUtf8, DCOSUtils, uDebug, DCStrUtils, uPixMapManager, uShowMsg,
uDCUtils, uLng, uGlobs, uGlobsPaths, DCConvertEncoding;
uDCUtils, uLng, uGlobs, uGlobsPaths, DCConvertEncoding, uMyWindows;
type
{ TTCommandEquivalence }
TTCommandEquivalence = record
@ -608,6 +608,28 @@ var
TCNumberOfInstance: integer;
TCListOfCreatedTCIconFilename: TStringList;
procedure UpdateEnvironment;
var
ASysPath: UnicodeString;
AUserPath: UnicodeString;
APath: UnicodeString = '';
begin
// System environment
if RegReadKey(HKEY_LOCAL_MACHINE, 'System\CurrentControlSet\Control\Session Manager\Environment', 'Path', ASysPath) then
begin
APath:= ASysPath;
if APath[Length(APath)] <> PathSeparator then APath += PathSeparator;
end;
// User environment
if RegReadKey(HKEY_CURRENT_USER, 'Environment', 'Path', AUserPath) then
begin
APath:= APath + AUserPath;
if APath[Length(APath)] <> PathSeparator then APath += PathSeparator;
end;
// Update path environment variable
if Length(APath) > 0 then SetEnvironmentVariableW('Path', PWideChar(APath));
end;
{ WindowProc }
function WindowProc(hWnd: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
@ -624,6 +646,12 @@ begin
}
//SendMessage(hMainWindow, uiMsg, wParam, lParam);
if (uiMsg = WM_SETTINGCHANGE) and (lParam <> 0) and (StrComp('Environment', PAnsiChar(lParam)) = 0) then
begin
UpdateEnvironment;
DCDebug('WM_SETTINGCHANGE:Environment');
end;
{$IF (lcl_fullversion >= 1020000)}
if (uiMsg = WM_DEVICECHANGE) and (wParam = DBT_DEVNODES_CHANGED) and (lParam = 0) then
begin

View file

@ -57,6 +57,7 @@ function InsertMenuItemW(hMenu: HMENU; uItem: UINT; fByPosition: BOOL;
function GetMenuItemText(hMenu: HMENU; uItem: UINT; fByPosition: LongBool): WideString;
function GetMenuItemType(hMenu: HMENU; uItem: UINT; fByPosition: LongBool): UINT;
function InsertMenuItemEx(hMenu, SubMenu: HMENU; Caption: PWideChar; Position, ItemID, ItemType : UINT; Bitmap:Graphics.TBitmap = nil): boolean;
function RegReadKey(ARoot: HKEY; const APath, AName: UnicodeString; out AValue: UnicodeString): Boolean;
{en
Extracts volume GUID from a volume GUID path
}
@ -227,6 +228,21 @@ begin
Result := InsertMenuItemW(hMenu, Position, True, mi);
end;
function RegReadKey(ARoot: HKEY; const APath, AName: UnicodeString; out AValue: UnicodeString): Boolean;
var
AKey: HKEY = 0;
dwSize: DWORD = MaxSmallint;
begin
Result:= RegOpenKeyExW(ARoot, PWideChar(APath), 0, KEY_READ, AKey) = ERROR_SUCCESS;
if Result then
begin
SetLength(AValue, MaxSmallint);
Result:= RegQueryValueExW(AKey, PWideChar(AName), nil, nil, PByte(AValue), @dwSize) = ERROR_SUCCESS;
if Result then SetLength(AValue, dwSize div SizeOf(WideChar));
RegCloseKey(AKey);
end;
end;
function DisplayName(const wsDrv: WideString): WideString;
var
SFI: TSHFileInfoW;