Sanjay  Darekar

Sanjay Darekar

  • NA
  • 61
  • 1.3k

How To ExcecuteCommandSyncronisation in ASPNET

Oct 3 2015 2:33 AM
In CheckSerial() function there is one key in res result how to work that code 
 
public static string CheckSerial()
{
string res = ExecuteCommandSync("vol");
const string search = "Number is";
int startI = res.IndexOf(search, StringComparison.InvariantCultureIgnoreCase);
string currentDiskID = "";
if (startI > 0)
{
currentDiskID = res.Substring(startI + search.Length).Trim();
}
return currentDiskID;
}
public static string ExecuteCommandSync(object command)
{
try
{
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
return result;
}
catch (Exception)
{
return null;
}
}