- I can't change the location of the file to be edited
- Just in case, the app.manifest has been edited so it runs as admin
Here's the code:
Code:
public void UpdateDNSNameInConfigFile(string v, ConfigFileOption cf)
{
string ConfigFilePath = Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + @"\<redacted>\<redacted>";
string ConfigFileContents = string.Empty;
string DNSName = v.Replace("/ucf:", ""); //Remove the command line arg from the value
switch (cf)
{
case ConfigFileOption.CobanSystem:
ConfigFilePath = ConfigFilePath + @"\<redacted>.<redacted>System";
break;
case ConfigFileOption.Agent_AVL:
ConfigFilePath = ConfigFilePath + @"\<redacted>.Agent.AVL";
break;
case ConfigFileOption.Agent_DB:
ConfigFilePath = ConfigFilePath + @"\<redacted>.Agent.DB";
break;
case ConfigFileOption.Agent_DVD:
ConfigFilePath = ConfigFilePath + @"\<redacted>.Agent.DVD";
break;
case ConfigFileOption.Agent_FileAgent:
ConfigFilePath = ConfigFilePath + @"\<redacted>.Agent.FileAgent";
break;
case ConfigFileOption.Agent_Log:
ConfigFilePath = ConfigFilePath + @"\<redacted>.Agent.Log";
break;
case ConfigFileOption.Agent_Streaming:
ConfigFilePath = ConfigFilePath + @"\<redacted>.Agent.Streaming";
break;
case ConfigFileOption.Agent_Listener:
throw new NotImplementedException();
case ConfigFileOption.Agent_InCar:
throw new NotImplementedException();
case ConfigFileOption.Agent_Tape:
throw new NotImplementedException();
}
ConfigFileContents = File.ReadAllText(ConfigFilePath);
ConfigFileContents = ConfigFileContents.Replace("<redacted>", v);
File.WriteAllText(ConfigFilePath, ConfigFileContents);
}