Skip to content

Instantly share code, notes, and snippets.

@gokulraja
Created July 21, 2014 13:36
Show Gist options
  • Save gokulraja/a216e7e50176a91dbc6a to your computer and use it in GitHub Desktop.
Save gokulraja/a216e7e50176a91dbc6a to your computer and use it in GitHub Desktop.
Process Start Helper C#
private static void ProcessHelper(string fileName, string arguments, bool showResultsinConsole)
{
// Start the child process.
using (var p = new Process{
StartInfo =
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
FileName = fileName
}
})
{
// Redirect the output stream of the child process.
if (!string.IsNullOrEmpty(arguments))
p.StartInfo.Arguments = arguments;
if(!string.IsNullOrEmpty(Path.GetDirectoryName(fileName)))
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(fileName);
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
if (showResultsinConsole)
Console.WriteLine(output);
p.WaitForExit();
}
}
@gokulraja
Copy link
Author

Setup basic authentication in C#
const bool showResultsinConsole = true;
Console.WriteLine("Setting up IIS Basic authentication");

        //http://support.microsoft.com/kb/837139

//@"%windir%\system32\inetsrv\appcmd.exe set config /section:anonymousAuthentication /enabled:false",

        string appCmdExe = Environment.GetEnvironmentVariable("windir") + @"\system32\inetsrv\appcmd.exe ";
        ProcessHelper(appCmdExe, "set config /section:basicAuthentication /enabled:true", showResultsinConsole);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment