本文整理汇总了C#中EnvironmentVariableTarget.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# EnvironmentVariableTarget.ToString方法的具体用法?C# EnvironmentVariableTarget.ToString怎么用?C# EnvironmentVariableTarget.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EnvironmentVariableTarget
的用法示例。
在下文中一共展示了EnvironmentVariableTarget.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Item
public Item(EnvironmentVariableTarget target)
{
varManager = new EnvVarManager();
_header = target.ToString();
_data = varManager.GetEnvVariables(target);
}
示例2: GetPaths
private void GetPaths( ListBox lb, EnvironmentVariableTarget target, ref string path )
{
if( lb == null )
throw new ArgumentNullException( "Listbox cannot be null." );
lb.Enabled = true;
try
{
string ID = "Path";
path = Environment.GetEnvironmentVariable( ID, target );
if( path == null )
path = Environment.GetEnvironmentVariable( ID.ToUpper(), target );
if( path == null )
path = Environment.GetEnvironmentVariable( ID.ToLower(), target );
ParsePaths( lb, path );
} catch( NullReferenceException )
{
lb.Items.Add( "Unable to fetch environment variable for target: " + target.ToString() );
lb.Enabled = false;
} catch( NotSupportedException )
{
lb.Items.Add( "The current platform is not supported." );
lb.Enabled = false;
} catch( ArgumentException )
{
lb.Items.Add( "The following target is invalid: " + target.ToString() );
lb.Enabled = false;
} catch( SecurityException )
{
lb.Items.Add( "This program does not have the required security privaliges to fetch the Path variable." );
lb.Enabled = false;
}
}
示例3: WritePaths
private void WritePaths( string path, EnvironmentVariableTarget target )
{
if ( path == null )
throw new ArgumentNullException( "Path cannot be null." );
try
{
Environment.SetEnvironmentVariable( "Path", path, target );
} catch( NullReferenceException )
{
MessageBox.Show( this, "A NullReferenceException was thrown while attempting to write" +
"to the Paths variable at the target: " + target.ToString(),
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} catch( ArgumentException )
{
MessageBox.Show( this, "An ArgumentExcepiton was thrown while attempting to write" +
"to the Paths variable at the target: " + target.ToString(),
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
} catch( NotSupportedException )
{
MessageBox.Show( this, "Unable to write to the Paths variable at the target: " + target.ToString() +
"The current platform is unsupported.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
} catch( SecurityException )
{
MessageBox.Show( this, "A SecurityException was thrown while attempting to write" +
"to the Paths variable at the target: " + target.ToString() +
"\n\nPlease ensure you have the appropriate permission.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
}
}
示例4: SetEnvironmentVariable
public void SetEnvironmentVariable(string variable, string value, EnvironmentVariableTarget target)
{
if (target == EnvironmentVariableTarget.Process)
{
EnvironmentSetEnvironmentVariable(variable, value, target);
return;
}
switch (target)
{
case EnvironmentVariableTarget.Machine:
SetMachineEnvironmentVariable(variable, value);
break;
case EnvironmentVariableTarget.User:
SetUserEnvironmentVariable(variable, value);
break;
default:
throw new NotSupportedException(target.ToString());
}
var explorers = Process.GetProcessesByName("explorer");
foreach (var explorer in explorers)
{
SendMessageTimeout(explorer.MainWindowHandle, WM_SETTINGCHANGE, IntPtr.Zero, "Environment", SendMessageTimeoutFlags.SMTO_NORMAL, 1, IntPtr.Zero);
}
SendMessageTimeout((IntPtr)0xFFFF, WM_SETTINGCHANGE, IntPtr.Zero, "Environment", SendMessageTimeoutFlags.SMTO_NORMAL, 1, IntPtr.Zero);
}