I am having some issues, and I am not sure if it's caused by Visual Studio, or something within the application.
I wrote a simple console application to stop and start services. When I go to debug/release the application, it's compiling the application into a .dll.
I followed some instructions I found while googling to get the .exe, but when I do that, my output folder with the dependence is massive compared to the script (60MB).
I have made console applications many times, and normally the .exe is stored in the debug/release folder and works without issue. I am not sure what is different this time.
All I want is a simple .exe
Output from the build:
1>------ Build started: Project: FixAnyConnect, Configuration: Debug Any CPU ------ 1>FixAnyConnect -> C:\Users\jeh\Desktop\Projects\FixAnyConnect\FixAnyConnect\bin\Debug\netcoreapp2.1\FixAnyConnect.dll ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Full Code:
using System;
using System.Diagnostics;
using System.ServiceProcess;
namespace FixAnyConnect
{
class Program
{
static void Main(string[] args)
{
string[] serviceList = { "Cisco AnyConnect Network Access Manager", "Cisco AnyConnect Network Access Manager Logon Module", "Cisco AnyConnect Secure Mobility Agent" };
//string[] serviceList = { "Print Spooler", "Realtek Audio Service", "Themes" };
Console.WriteLine("Restarting AnyConnect...");
foreach (string serviceName in serviceList)
{
ServiceController service = new ServiceController(serviceName, ".");
Console.WriteLine("Stopping " + serviceName);
try
{
service.Stop();
Console.WriteLine(serviceName + " Stopped");
}
catch
{
}
Console.WriteLine("Sleeping for 5 seconds");
System.Threading.Thread.Sleep(5000);
Console.WriteLine("Starting " + serviceName);
try
{
service.Start();
Console.WriteLine(serviceName + " Started");
}
catch (Exception ex)
{
Console.WriteLine("Failed to start service");
Console.WriteLine(ex.Message);
Console.WriteLine("Rerun script - if same error occurs, please reboot system");
Console.WriteLine("Press any key to close");
Console.ReadKey();
Environment.Exit(0);
}
Console.WriteLine("================");
}
Console.WriteLine("Starting AnyConnect Software");
try
{
Process.Start("C:\\Program Files (x86)\\Cisco\\Cisco AnyConnect Secure Mobility Client\vpnui.exe");
}
catch (Exception ex)
{
Console.WriteLine("Failed to start Any Connect");
Console.WriteLine(ex.Message);
Console.WriteLine("Rerun script - if same error occurs, please reboot system");
Console.WriteLine("Press any key to close");
Console.ReadKey();
Environment.Exit(0);
}
Console.WriteLine("AnyConnect has been sucessfuly restarted");
Console.WriteLine("Press any key to close");
Console.ReadKey();
}
}
}