If I've understood it correctly, I'd rewrite it like this:
foreach (string arg in Environment.GetCommandLineArgs())
{
if (arg == "–Auto_BlueGrass")
{
for (int i = 0; i < 2; i++)
{
if (i==0)
{
mstrSwitch = "BluegrassCH";
Console.WriteLine("BlueGrass Chargeable Claims Job started in Auto mode - " + DateTime.Now + " ");
}
else // i can only be 1
{
mstrSwitch = "BluegrassRP";
Console.WriteLine("BlueGrass Reporting Claims Job started in Auto mode - " + DateTime.Now + " ");
}
// these next two lines are the same for both values of i
AllocConsole();
mblnAutomode = true;
// now embed the AutoModePoint routine
if (!IsUserAuthorized())
{
if (mblnAutomode)
{
Console.WriteLine("You do not have permissions to run this application. This application will now close." + " " + DateTime.Now);
}
else
{
MessageBox.Show("You do not have permissions to run this application. This application will now close.", "No Access", MessageBoxButton.OK, MessageBoxImage.Stop);
}
Application.Current.Shutdown();
}
else
{
this.DataContext = this;
DefinePacificareStateCodes();
ReadApplicationSettings();
}
}
break; // no point going on if required command line argument found
}
}