Пример #1
0
        public static void AddPathSegments(Options options)
        {
            try
            {
                string allPaths = Environment.GetEnvironmentVariable("PATH", options.Target);

                if (allPaths != null)
                {
                    var newValue = options.PathSegment;
                    allPaths = allPaths.TrimEnd(';');
                    allPaths = allPaths + ";" + newValue;
                }
                else
                {
                    allPaths = options.PathSegment;
                }

                Environment.SetEnvironmentVariable("PATH", allPaths, options.Target);

                Console.WriteLine("Added path segment: {0}", options.PathSegment);
            }
            catch (Exception ex)
            {
                Console.WriteLine("could not add path segment: {0} -  error {1}", options.PathSegment, ex);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (!options.Parse(args))
            {
                options.Usage();
                return;
            }

            AddPathSegments(options);
        }