次の方法で共有


Remove メソッド

指定された既存の環境変数を削除します。

object
.Remove(strName) 

引数

  • object
    WshEnvironment オブジェクトです。
  • strName
    削除する環境変数の名前です。

解説

Remove メソッドは、環境変数を PROCESS、USER, SYSTEM、VOLATILE の各環境から削除します。Remove メソッドを使って削除される環境変数は、永久的に削除されるわけではありません。現在のセッションから削除されるだけです。

使用例

次のコードは、Process 環境変数 TestVar を削除する例です。

VBScript

Dim WshShell, WshEnv
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("PROCESS")
WshEnv("TestVar") = "Windows Script Host"
WScript.Echo WshShell.ExpandEnvironmentStrings("The value of the test variable is: '%TestVar%'")
WshEnv.Remove "TestVar"
WScript.Echo WshShell.ExpandEnvironmentStrings("The value of the test variable is: '%TestVar%'")

JScript

var WshShell = WScript.CreateObject("WScript.Shell");
var WshEnv = WshShell.Environment("PROCESS");
WshEnv("TestVar") = "Windows Script Host";
WScript.Echo(WshShell.ExpandEnvironmentStrings("The value of the test variable is: '%TestVar%'"));
WshEnv.Remove("TestVar");
WScript.Echo(WshShell.ExpandEnvironmentStrings("The value of the test variable is: '%TestVar%'"));

参照

WshEnvironment オブジェクト | Environment プロパティ