static void Main(string[] args) { // 0.删除旧版本 string tag; string tagValue; tag = "TOMCAT_HOME"; tagValue = SysEnvironment.GetSysEnvironmentByName(tag); // The local machine. delete Environment.SetEnvironmentVariable(tag, null, EnvironmentVariableTarget.Machine); SysEnvironment.SetPathDelete(@"%" + tag + @"%\bin"); SysEnvironment.SetPathDelete(tagValue + @"\bin");; tag = "CATALINA_HOME"; tagValue = SysEnvironment.GetSysEnvironmentByName(tag); // The local machine. delete Environment.SetEnvironmentVariable(tag, null, EnvironmentVariableTarget.Machine); SysEnvironment.SetPathDelete(@"%" + tag + @"%\bin"); SysEnvironment.SetPathDelete(tagValue + @"\bin");; // 刷新设定 // System.Console.WriteLine("updating..."); // RefreshEnvironment(); //----------------------------------------------------------------------------------------- string temp = ""; // 1.新建两个目录 // 无 // 2.设环境变量 temp = System.Environment.CurrentDirectory; SysEnvironment.SetSysEnvironment("TOMCAT_HOME", temp); SysEnvironment.SetSysEnvironment("CATALINA_HOME", temp); // 3.设定PATH temp = @"%TOMCAT_HOME%\bin"; temp = temp.Replace("%TOMCAT_HOME%", System.Environment.CurrentDirectory); SysEnvironment.SetPathAfter(temp); // 4.刷新设定 System.Console.WriteLine("Please wait..."); RefreshEnvironment(); // 5.执行其他设置(shell,配置文件等) // 无 // 6.成功 System.Console.WriteLine(""); System.Console.WriteLine("Mission complete!"); Console.ReadKey(); }
static void Main(string[] args) { // 0.删除 string tag; string tagValue; tag = "M2_HOME"; tagValue = SysEnvironment.GetSysEnvironmentByName(tag); // The local machine. delete Environment.SetEnvironmentVariable(tag, null, EnvironmentVariableTarget.Machine); SysEnvironment.SetPathDelete("%" + tag + "%" + @"\bin"); SysEnvironment.SetPathDelete(tagValue + @"\bin"); tag = "MAVEN_HOME"; tagValue = SysEnvironment.GetSysEnvironmentByName(tag); // The local machine. delete Environment.SetEnvironmentVariable(tag, null, EnvironmentVariableTarget.Machine); SysEnvironment.SetPathDelete("%" + tag + "%" + @"\bin"); SysEnvironment.SetPathDelete(tagValue + @"\bin"); //-------------------------------------------------------------------------------------------- // 1.新建两个目录 // 无 // 2.设环境变量 SysEnvironment.SetSysEnvironment("M2_HOME", System.Environment.CurrentDirectory); SysEnvironment.SetSysEnvironment("MAVEN_HOME", System.Environment.CurrentDirectory); // 3.设定PATH SysEnvironment.SetPathAfter(System.Environment.CurrentDirectory + @"\" + "bin"); // 4.刷新设定 System.Console.WriteLine("Please wait..."); RefreshEnvironment(); // 5.执行其他设置(shell,配置文件等) // 6.成功 System.Console.WriteLine(""); System.Console.WriteLine("Mission complete!"); Console.ReadKey(); }
static void Main(string[] args) { // 0.删除 string tag; string tagValue; tag = "NODE_PATH"; tagValue = SysEnvironment.GetSysEnvironmentByName(tag); // The local machine. delete Environment.SetEnvironmentVariable(tag, null, EnvironmentVariableTarget.Machine); SysEnvironment.SetPathDelete("%" + tag + "%"); SysEnvironment.SetPathDelete("%" + tag + "%" + @"\node_global"); SysEnvironment.SetPathDelete(tagValue); SysEnvironment.SetPathDelete(tagValue + @"\node_global"); //-------------------------------------------------------------------------------------------- // 1.新建两个目录 string path; path = System.Environment.CurrentDirectory + "/node_global"; if (Directory.Exists(path)) { System.Console.WriteLine(path + " already exists."); } else { Directory.CreateDirectory(path); } path = System.Environment.CurrentDirectory + "/node_cache"; if (Directory.Exists(path)) { System.Console.WriteLine(path + " already exists."); } else { Directory.CreateDirectory(path); } // 2.设环境变量 SysEnvironment.SetSysEnvironment("NODE_PATH", System.Environment.CurrentDirectory); // 3.设定PATH SysEnvironment.SetPathAfter(System.Environment.CurrentDirectory); SysEnvironment.SetPathAfter(System.Environment.CurrentDirectory + @"\node_global"); // 4.刷新设定 System.Console.WriteLine("Please wait..."); RefreshEnvironment(); // 5.执行其他设置(shell,配置文件等) //npm config set cache "D:\Program Files\node-v8.10.0-win-x64\node_cache" //npm install -g cnpm --registry=https://registry.npm.taobao.org writeSetting(System.Environment.CurrentDirectory + "/setting.bat"); callBat("setting.bat"); // 6.成功 System.Console.WriteLine(""); System.Console.WriteLine("Mission complete!"); Console.ReadKey(); }