Environment.ExpandEnvironmentVariables(String) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した文字列に埋め込まれた各環境変数の名前を、変数の値に相当する文字列に置き換え、結果の文字列を返します。
public:
static System::String ^ ExpandEnvironmentVariables(System::String ^ name);
public static string ExpandEnvironmentVariables(string name);
static member ExpandEnvironmentVariables : string -> string
Public Shared Function ExpandEnvironmentVariables (name As String) As String
パラメーター
- name
- String
0 個以上の環境変数の名前を含む文字列。 各環境変数はパーセント記号 (%) で囲まれます。
返品
各環境変数がその値に置き換えられた文字列。
例外
name は nullです。
例
次の例は、システム ドライブとシステム ルート変数を取得する方法を示しています。
// Sample for the Environment.ExpandEnvironmentVariables method
using System;
class Sample
{
public static void Main()
{
// Keep this information secure!
string query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
string str = Environment.ExpandEnvironmentVariables(query);
Console.WriteLine(str);
}
}
/*
This example prints:
My system drive is C: and my system root is C:\WINDOWS
*/
// Sample for the Environment.ExpandEnvironmentVariables method
open System
let nl = Environment.NewLine
// <-- Keep this information secure! -->
let query = "My system drive is %SystemDrive% and my system root is %SystemRoot%"
let str = Environment.ExpandEnvironmentVariables query
printfn $"\nExpandEnvironmentVariables: {nl} {str}"
// This example produces the following results:
// ExpandEnvironmentVariables:
// My system drive is C: and my system root is C:\WINNT
' Sample for the Environment.ExpandEnvironmentVariables method
Class Sample
Public Shared Sub Main()
Dim str As [String]
Dim nl As [String] = Environment.NewLine
Console.WriteLine()
' <-- Keep this information secure! -->
Dim query As [String] = "My system drive is %SystemDrive% and" & _
"my system root is %SystemRoot%"
str = Environment.ExpandEnvironmentVariables(query)
Console.WriteLine("ExpandEnvironmentVariables: {0} {1}", nl, str)
End Sub
End Class
'
'This example produces the following results:
'
'ExpandEnvironmentVariables:
' My system drive is C: and my system root is C:\WINNT
'
注釈
COM 相互運用機能は、オペレーティング システムから環境変数を取得するために使用されます。 COM エラーが原因で環境変数を取得できない場合、エラーの原因を説明する HRESULT を使用して、いくつかの例外が発生する可能性があります。つまり、例外は HRESULT に依存します。 HRESULT の処理方法の詳細については、 Marshal.ThrowExceptionForHR メソッドの「解説」セクションを参照してください。
置換は、設定されている環境変数に対してのみ行われます。 たとえば、 name が "MyENV = %MyENV%" であるとします。 環境変数 MyENV が 42 に設定されている場合、このメソッドは "MyENV = 42" を返します。 MyENV が設定されていない場合、変更は行われません。このメソッドは "MyENV = %MyENV%" を返します。
戻り値のサイズは 32K に制限されています。