首页 | 博客群 | 公社 | 专栏 | 论坛 | 图片 | 资讯 | 注册 | 帮助 | 博客联播 | 随机访问
- -| 回首页 | 2005年索引 | - -渴望绿色

支持右键添加目录到Windows环境变量path变量中并立即生效的小工具

关键词Windows    环境变量    path    右键    目录                                          

使用说明:

 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的说明, 摘要如下:


SendMessageTimeout Function

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 Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systemsWindows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.


【作者: hwycheng】【访问统计:】【2005年07月20日 星期三 13:51】【注册】【打印

搜索

Google

Trackback

你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=2329577

博客手拉手

有关XP系统环境变量问题的解决
有关XP系统环境变量问题的解决
Windows 套件安?b程式
Windows 套件安?b程式
WindowsXP 键盘快捷键概述

回复

- 评论人: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 的内容都贴上来了?

验证码:   
评论内容: