当前位置: 首页>>代码示例>>C#>>正文


C# EnvironmentVariableTarget.ToString方法代码示例

本文整理汇总了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);
 }
开发者ID:blastmann,项目名称:EnvManWPF,代码行数:6,代码来源:Item.cs

示例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;
              }
        }
开发者ID:Measter,项目名称:PathViewer,代码行数:35,代码来源:Form1.cs

示例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 );
              }
        }
开发者ID:Measter,项目名称:PathViewer,代码行数:31,代码来源:Form1.cs

示例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);
        }
开发者ID:umaranis,项目名称:Prig,代码行数:27,代码来源:EnvironmentRepository.cs


注:本文中的EnvironmentVariableTarget.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。