使用说明:
1.不需要安装, 将下载后解压缩,将解压缩后的目录拷贝到你喜欢的路径下即可。
2.第一次使用请双击执行"AddEnvPath.exe", 将会在右键菜单自动生成"Add to Environment Path"菜单项.
3.以后只要在目录上面点击右键, 就会看到"Add to Environment Path"菜单项, 点击执行, 则选择的目录会自动加入到path环境变量中。
4.为了使path环境变量立即生效,程序向系统发送了广播消息,因此要延时几十秒钟,请耐心等待一下。
@使用备注:
环境变量分为用户环境变量和系统环境变量,用户环境变量只对当前用户有效,系统环境变量对于系统中的所有用户有效。 本程序修改的是用户环境变量中的path变量。同一个目录不会重复加入,程序会自动处理。
立即下载 下载空间由 FlashBT(变态快车) 强大/免费/无广告的BitTorrent下载程序 提供
@关于程序修改Windows环境变量后使环境变量立即生效的问题:
本程序是使用SendMessageTimeout函数向系统发送设置改变的消息来实现的。具体代码如下:
DWORD dwMsgResult = 0L;
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,LPARAM("Environment"), SMTO_ABORTIFHUNG, 5000, &dwMsgResult);
5000是延时等待的时间长度,单位为毫秒。整个等待的长度为:
Therefore, the total wait time can be up to the value of uTimeout multiplied by the number of top-level windows.
在本示例中整个程序等待的长度 = 5000 * 顶层窗口的个数;
如果还有不明白的请参考MSDN中关于SendMessageTimeOut的说明, 摘要如下:
Sends the specified message to one of more windows.
Syntax
LRESULT SendMessageTimeout( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, UINT fuFlags, UINT uTimeout, PDWORD_PTR lpdwResult );
Parameters
- hWnd
- [in] Handle to the window whose window procedure will receive the message.
If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows. The function does not return until each window has timed out. Therefore, the total wait time can be up to the value of uTimeout multiplied by the number of top-level windows.
- Msg
- [in] Specifies the message to be sent.
- wParam
- [in] Specifies additional message-specific information.
- lParam
- [in] Specifies additional message-specific information.
- fuFlags
- [in] Specifies how to send the message. This parameter can be one or more of the following values.
- SMTO_ABORTIFHUNG
- Returns without waiting for the time-out period to elapse if the receiving thread appears to not respond or "hangs."
- SMTO_BLOCK
- Prevents the calling thread from processing any other requests until the function returns.
- SMTO_NORMAL
- The calling thread is not prevented from processing other requests while waiting for the function to return.
- SMTO_NOTIMEOUTIFNOTHUNG
- Microsoft Windows 2000/Windows XP: Does not return when the time-out period elapses if the receiving thread stops responding.
- uTimeout
- [in] Specifies the duration, in milliseconds, of the time-out period. If the message is a broadcast message, each window can use the full time-out period. For example, if you specify a five second time-out period and there are three top-level windows that fail to process the message, you could have up to a 15 second delay.
- lpdwResult
- [in] Receives the result of the message processing. This value depends on the message sent.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails or times out, the return value is zero. To get extended error information, call GetLastError . If GetLastError returns zero, then the function timed out. SendMessageTimeout does not provide information about individual windows timing out if HWND_BROADCAST is used.
Remarks
The function calls the widow procedure for the specified window and, if the specified window belongs to a different thread, does not return until the window procedure has processed the message or the specified time-out period has elapsed. If the window receiving the message belongs to the same queue as the current thread, the window procedure is called directly—the time-out value is ignored.
This function considers a thread is not responding or is "hung" if it has not called GetMessage or a similar function within five seconds.
The system only does marshalling for system messages (those in the range 0 to WM_USER ). To send other messages (those above WM_USER) to another process, you must do custom marshalling.
Windows 95/98/Me: SendMessageTimeoutW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems .
Function Information
Minimum DLL Version user32.dll Header Declared in Winuser.h, include Windows.h Import library User32.lib Minimum operating systems Windows 95, Windows NT 3.1 Unicode Implemented as ANSI and Unicode versions.
你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=2329577
|
- 评论人:aker
2007-07-05 10:55:43
|
|||
不错,这个功能不错,最好用console的写出来,功能添加为可以对path等环境变量删除,添加,更新等
|
||||
|
- 评论人:anonymous
2006-10-24 16:25:13
|
|||
|
||||
|
- 评论人:anonymous
2006-10-24 16:23:55
|
|||
|
||||
|
- 评论人:anonymous
2006-10-24 16:23:21
|
|||
|
||||
|
- 评论人:anonymous
2006-10-24 16:22:42
|
|||
?? |
||||
|
- 评论人:你老豆
2006-10-24 16:20:48
|
|||
你只垃圾直接贴上来,还不如不写? |
||||
|
- 评论人:temp77
2005-10-01 16:59:04
|
|||
没有源码吗? 怎么把 MSDN 的内容都贴上来了? |
||||