在 Windows %username% 中设置永久变量

发布于 2024-11-15 12:07:06 字数 208 浏览 4 评论 0原文

我需要在 Windows 上永久设置 %username% 变量,这可能吗?

我的意思是,如果我在命令提示符下设置用户名=大写,我可以看到该变量已更改,但是正如预期的那样,这确实在该命令提示符下起作用,如果我打开另一个命令提示符,则用户名变量是原始变量。

我试图找到对应的注册表值,但没有找到。

我需要一些自动的方法来做到这一点。

谢谢!

i need to set permanently the %username% variable on windows is that possible?

I mean if I do on command prompt set username=UPPERCASE I can see that the variable is changed, however as expected this does work just in that command prompt, If I open another one the username variable is the original.

I tried to find the correspondent registry value but I did not find it.

I need some automatic way to do it.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏舞 2024-11-22 12:07:06

当每个进程启动时,该进程都会获取父进程环境变量的副本。因此,如果您使用 Windows 资源管理器启动命令提示符。您将获得 Explorer.exe 环境变量的副本,但是当您在 cmd.exe 中编辑它时,您不会编辑系统其余部分的值。

也就是说,Windows 提供了一个进程可以订阅的事件,以便它们可以得知环境变量有新值。如果你有兴趣,我可以尝试挖掘它。我之前曾将它用于 Path 环境变量,并认为它可能适用于您的问题。

听起来你应该创建一个bat文件。这将提示用户输入用户名并将其放入 %USERNAME% 环境变量中。

SET /p USERNAME=What is your UserName?
putty /user:%username%

When each process starts, the process gets a copy of the parent process' environment variables. So, if you used Windows Explorer to start your command prompt. You get a copy of Explorer.exe's environment variables, but when you edit it in cmd.exe, you don't edit the value for the rest of the system.

That said, Windows provides an event that processes can subscribe to so they can be told that there is a new value for environment variables. If you are interested, I can try to dig it up. I've used it before for the Path environment variable and think it may apply to your problem.

Sounds like you should create a bat file. This will prompt the user for their username and put it in the %USERNAME% environment variable.

SET /p USERNAME=What is your UserName?
putty /user:%username%
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文