Question: I have an installer, and it installs some native DLL along with the program. The DLL is in a separate folder that I added to the path environment variable.
This was done successfully, and the variable is displayed in the path if I check the Windows system settings.
However, if I run the command line program / service, it says that the dll was not found ...
I check the path of the environment variable with the set command, and my folder is missing there.
If i do
SET path = %path%;my/folder/here/
And run my program after that, then it works.
According to this MS KB article , this is due to the need to restart the computer.
if i don't
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) "Environment", SMTO_ABORTIFHUNG, 5000, &dwReturnValue);
Now I have done just that using the code below, but the error message is saved. My folder in% path% is spelled correctly, I checked this.
What am I doing wrong?
' http://www.pinvoke.net/default.aspx/Enums/SendMessageTimeoutFlags.html ' <Flags()> _ Public Enum SendMessageTimeoutFlags SMTO_NORMAL = 0 SMTO_BLOCK = 1 SMTO_ABORTIFHUNG = 2 SMTO_NOTIMEOUTIFNOTHUNG = 8 End Enum ' http://ghouston.blogspot.com/2005/08/how-to-create-and-change-environment.html ' Public Const HWND_BROADCAST As Integer = &HFFFF Public Const WM_SETTINGCHANGE As Integer = &H1A ' http://pinvoke.net/default.aspx/user32.SendMessageTimeout ' <System.Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True)> _ Public Shared Function SendMessageTimeout(ByVal windowHandle As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr, ByVal flags As SendMessageTimeoutFlags, ByVal timeout As Integer, ByRef result As IntPtr) As IntPtr End Function ' http://support.microsoft.com/?kbid=104011 ' ' http://blog.jtbworld.com/2005/11/set-environment-variable-using-vbnet.html ' Sub UpdatePath() Dim result As Integer ' SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,(LPARAM) "Environment", SMTO_ABORTIFHUNG,5000, &dwReturnValue); ' ' CType("Environment", System.IntPtr) ' Dim s As String = New String("Environment") Dim ptr As IntPtr = Runtime.InteropServices.Marshal.StringToHGlobalUni(s) 'SendMessageTimeout(CType(HWND_BROADCAST, System.IntPtr), WM_SETTINGCHANGE, 0, ptr, SendMessageTimeoutFlags.SMTO_BLOCK Or SendMessageTimeoutFlags.SMTO_ABORTIFHUNG Or SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG, 5000, result) ' SendMessageTimeout(CType(HWND_BROADCAST, System.IntPtr), WM_SETTINGCHANGE, 0, ptr, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 5000, result) End Sub