0

i am working on a small project in c# and i am trying to run a command using the windows command prompt in the background (without showing the command prompt). Ive done this in vb.net before using : Shell("netsh wlan stop hostednetwork", 0) , but can't find how to do it in c#. Anyone know how?

1 Answers1

2
   public static string ProcessStarter(string processName, string argString, string workingDirectory = null)
    {
        var prs = new Process();
        if (!string.IsNullOrWhiteSpace(workingDirectory))
        {
            prs.StartInfo.WorkingDirectory = workingDirectory;
        }
        prs.StartInfo.UseShellExecute = false;
        prs.StartInfo.RedirectStandardOutput = true;
        prs.StartInfo.RedirectStandardError = true;
        prs.StartInfo.FileName = processName;
        prs.StartInfo.Arguments = argString;
        // LOOK HERE
        prs.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
        prs.Start();
        string result = prs.StandardOutput.ReadToEnd();
        string resultErr = prs.StandardError.ReadToEnd();
        return string.IsNullOrEmpty(result) ? resultErr : result;
}
eugenekgn
  • 1,652
  • 2
  • 17
  • 38