void BtnEditClick(object sender, EventArgs e) { try{ if(this.checkedListBox1.CheckedItems.Count > 0){ foreach(object o in this.checkedListBox1.CheckedItems){ string fmt = o.ToString(); string key = fmt.Substring(fmt.IndexOf('[') + 1,fmt.IndexOf(']') - fmt.IndexOf('[') - 1); string val = fmt.Substring(fmt.IndexOf(']') + 1); EnvironmentVariableEditor.EditorForm ef = new EditorForm("User", key, val); if( ef.ShowDialog() == DialogResult.OK){ if(ef.key != string.Empty && ef.val != string.Empty && ef.target != string.Empty){ if(ef.target.Equals("User")){ Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.User); ShowInformation("Set User Variable [" + ef.key + "] to " + ef.val + "."); } if(ef.target.Equals("Machine")){ Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.Machine); ShowInformation("Set Machine Variable [" + ef.key + "] to " + ef.val + "."); } } } } } if(this.checkedListBox2.CheckedItems.Count > 0){ foreach(object o in this.checkedListBox2.CheckedItems){ string fmt = o.ToString(); string key = fmt.Substring(fmt.IndexOf('[') + 1,fmt.IndexOf(']') - fmt.IndexOf('[') - 1); string val = fmt.Substring(fmt.IndexOf(']') + 1); EnvironmentVariableEditor.EditorForm ef = new EditorForm("Machine", key, val); if( ef.ShowDialog() == DialogResult.OK){ if(ef.key != string.Empty && ef.val != string.Empty && ef.target != string.Empty){ if(ef.target.Equals("User")){ Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.User); ShowInformation("Set User Variable [" + ef.key + "] to " + ef.val + "."); } if(ef.target.Equals("Machine")){ Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.Machine); ShowInformation("Set Machine Variable [" + ef.key + "] to " + ef.val + "."); } } } } } this.BtnScanClick(sender,e); }catch(Exception ex){ ShowException(ex.Message); } }
void BtnNewClick(object sender, EventArgs e) { try{ EnvironmentVariableEditor.EditorForm ef = new EditorForm("New","Key",""); if(ef.ShowDialog() == DialogResult.OK){ if(ef.target != string.Empty && ef.key != string.Empty && ef.val != string.Empty){ if(ef.target.Equals("User")){ Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.User); ShowInformation("Set User Variable [" + ef.key + "] to " + ef.val + "."); } if(ef.target.Equals("Machine")){ Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.Machine); ShowInformation("Set Machine Variable [" + ef.key + "] to " + ef.val + "."); } this.BtnScanClick(sender,e); } } }catch(Exception ex){ ShowException(ex.Message); } }