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?

0

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.