设置ComputerName环境变量

设置ComputerName环境变量

本文介绍了设置ComputerName环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用VBS脚本将环境变量%computername%设置为blah。这似乎是一个简单的任务,但由于某种原因,我今天早上发现很困难。我可以通过命令提示符(set computername = blah)来完成,我可以通过VBS获取环境变量的值,但是我似乎找不到正确的语法来覆盖环境变量。任何帮助将不胜感激。谢谢!

I need to use a VBS script to set the environment variable %computername% to "blah". This seems like a simple enough task but for some reason I'm finding it difficult this morning. I can do this via a command prompt (set computername=blah) and I can get the value of the environment variable via VBS but I cant seem to find the correct syntax to override the environment variable. Any help would be greatly appreciated. Thanks!

推荐答案

如何创建它决定了其类型和生命周期。如果您希望该变量在用户注销之前可用,则可以将其创建为 VOLATILE

How you create it determines its type and lifetime. If you want the variable to be available until the user logs off, you can create it as VOLATILE.

Set objShell = CreateObject("WScript.Shell")
objShell.Environment("VOLATILE")("MyVariable") = "This is some data to share"

并阅读...

strValue = objShell.Environment("VOLATILE")("MyVariable")

变量类型的其他选项是 SYSTEM USER PROCESS 。请参阅了解描述差异的好文章。

Other options for the variable's type are SYSTEM, USER, and PROCESS. See here for a nice article describing the differences.

这篇关于设置ComputerName环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 23:45