using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Win32;
namespace SetPathEnv
{
class Program
{
static void Main(string[] args)
{
string regKey = Registry.LocalMachine + @"\SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
if (args.Length == 0)
{
Console.WriteLine("\nSetPathEnv - Setzt die Windows Path Umgebungsvariable dauerhaft.\n");
Console.WriteLine("Benutzung: setpathenv <Verzeichnis>\n");
Console.WriteLine("(c) 2010 Andi Kanzler");
Environment.Exit(0);
}
string newPath = args[0];
if (!Regex.IsMatch(newPath, "^(([a-zA-Z]\\:)|(\\\\))(\\\\{1}|((\\\\{1})[^\\\\]([^/:*?<>\"|]*))+)$", RegexOptions.IgnoreCase))
{
Console.WriteLine("\nFehler: Ungültiger Pfad");
Environment.Exit(0);
}
try
{
string oldPathvar = (string)Registry.GetValue(regKey, "Path", string.Empty);
Registry.SetValue(regKey, "Path", string.IsNullOrEmpty(oldPathVar) ? newPath : oldPathVar + ';' + newPath, RegistryValueKind.ExpandString);
}
catch (Exception ex)
{
Console.WriteLine("\nFehler: " + ex.Message);
}
}
}
}