From 8f48490b3c2b10ec8d941e0744d154c3930b4d6e Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 10 Jun 2015 21:51:24 +0300 Subject: notify about environment updates --- RegUtils.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/RegUtils.hs b/RegUtils.hs index 677e4f8..429abec 100644 --- a/RegUtils.hs +++ b/RegUtils.hs @@ -62,6 +62,21 @@ setString key subKeyPath valueName valueValue = withTStringLen valueValue $ \(ptr, len) -> do type' <- getType key subKeyPath valueName regSetValueEx subKey valueName (fromMaybe rEG_SZ type') ptr $ len * sizeOf (undefined :: TCHAR) + notifyEnvironmentUpdate + +foreign import ccall "BroadcastSystemMessageW" + c_BroadcastSystemMessage :: DWORD -> LPDWORD -> UINT -> WPARAM -> LPARAM -> IO LONG + +notifyEnvironmentUpdate :: IO () +notifyEnvironmentUpdate = + withCWString "Environment" $ \lparamPtr -> do + let wparam = fromIntegral $ castPtrToUINTPtr nullPtr + let lparam = fromIntegral $ castPtrToUINTPtr lparamPtr + c_BroadcastSystemMessage bSF_POSTMESSAGE nullPtr wM_SETTINGCHANGE wparam lparam + return () + where + bSF_POSTMESSAGE = 0x10 + wM_SETTINGCHANGE = 0x1A delValue :: HKEY -> String -> String -> IO () delValue key subKeyPath valueName = @@ -69,6 +84,7 @@ delValue key subKeyPath valueName = withForeignPtr subKey $ \subKeyPtr -> withCWString valueName $ \valueNamePtr -> do ret <- c_RegDeleteValue subKeyPtr valueNamePtr + notifyEnvironmentUpdate case ret of 0x0 -> return () 0x2 -> ioError $ mkIOError doesNotExistErrorType "RegQueryValueEx" Nothing $ Just (subKeyPath ++ "\\" ++ valueName) -- cgit v1.2.3