使用 rundll32 user32.dll 来指示用户环境已更改
我无法在 Windows 7 中修改环境变量。 但是我已被授予修改注册表设置的权限。 例如我可以修改: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment 关键:BPATH 它附加到我的系统 pathEnv 的末尾。
但是当我进行更改时,更改直到下次重新启动才会生效。
我想找到一个“始终安装”的命令行,它可以发出 BPATH 更改的信号,以便始终为后续程序和窗口更新“PATH”。
rundll user32.dll, [ BroadcastSystemMessage PATH CHANTGED... or somehting...]
条件:
- 我只能通过注册表编辑路径和 bpath,而不能从“系统”、“高级”选项卡编辑...
- 我不想安装任何不属于标准开箱即用 Windows 7 安装的软件。
- 通常,这应该通过 PowerShell 提示符的 CMD 提示符来完成。
I do not have the ability to modify environment variables in windows 7.
However I have been granted permission to modify the registry settings.
So for example I can modify:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Key: BPATH
which is appended to the end of my System's pathEnv.
but when I make the changes the change does not take affect until the next reboot.
I would like to find a command line that is "Always Installed" that can signal a change in BPATH such that "PATH" is always updated for subsequent programs and windows.
rundll user32.dll, [ BroadcastSystemMessage PATH CHANTGED... or somehting...]
Conditions:
- I can only edit the path and bpath via the registry, not from the System, Advanced tab...
- I do not want to install any software that is not part of a standard out of the box windows 7 install.
- Typically this should just be done from the CMD prompt of the PowerShell prompt.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Powershell 中,以下命令将设置系统变量“variableName”为variableValue 的值。
最后一个值可以是
Machine
、User
或Process
shell 向系统发送更新环境广播。任何打开的 shell 都不会收到新的环境变量。
In Powershell, the following command will set the System variable 'variableName' the value of variableValue.
The last value can be
Machine
,User
orProcess
The shell sends an update environment broadcast to the system. Any open shells will not receive the new environment variable.
这听起来很困难,并且不能用 rundll32 来完成 - 我知道因为我已经尝试过。这里有很多问题,rundll的文档是从哪里链接的。这基本上只调用以下形式的函数:
http://support.microsoft.com/kb/164787
这意味着 - 您可以调用专门为使用此工具调用而设计的特殊函数,以及不带参数的简单函数,或者可能只是一个 HWND。
要刷新环境,您需要广播(即
SendMessageTimeout
到HWND_BROADCAST
)WM_SETTINGCHANGE
消息,第四个参数 (wparam) 应该是
0
,LPARAM
应该是L"Environment"
(注意L
- 它有是一个宽字符串,否则变量将不会刷新!)。这是一些有效的 PS 代码,我不记得是谁写的(实际上是
从 C++ 翻译的
WM_SETTINGCHANGE
的 MSDN 示例):它不止 1 个命令,但适合一个小脚本。
我还没有尝试过使用变量(PATH)中的变量来尝试你的技巧,但可能是,
这样的配置需要两次后续刷新(第一个允许更新 BPATH,第二个 PATH 使用更新的 BPATH 值。
This sounds difficult, and cannot be done with the rundll32 - I know because I have tried. There are many questions here, where the documentation of rundll is linked from. This basically only calls functions of the form:
http://support.microsoft.com/kb/164787
Which means - you can call special functions, which were designed to be called with this tool, AND simple functions, which take no arguments, or maybe just a HWND.
To refresh the environment, you need to broadcast (i.e.
SendMessageTimeout
toHWND_BROADCAST
) theWM_SETTINGCHANGE
message, 4th argument (wparam
) should be0
, and theLPARAM
should beL"Environment"
(notice theL
- it has to be a wide string, or the variables won't refresh!).Here's some working PS code, which I don't remember who wrote (it's actually
the MSDN example for
WM_SETTINGCHANGE
translated from C++):It's more than 1 command, but fits into a small script.
I haven't tried your trick with a variable within a variable (PATH), but it may be,
that such a configuration requires two subsequent refreshes (the first one allows BPATH to be updated, and on the second one PATH uses the updated BPATH value.
Powershell:
给你,
将路径机器变量设置为其自身
(请注意,如果您更改了“路径”,并且它没有更新 Explorer.exe,Powershell 可能会再次重置当前环境!)
Powershell:
There you go,
Set the Path Machine Variable to it's self
(Be aware that if you changed 'path', and it didn't update for Explorer.exe, Powershell would probably reset the current environment again!)