Public Function GetBiosSerialNumber() As String
Dim OutputString As String = String.Empty
Using Process As New Process
AddHandler Process.OutputDataReceived, Sub(sender As Object, e As DataReceivedEventArgs)
OutputString = OutputString & e.Data & vbCrLf
End Sub
With Process.StartInfo
.FileName = "cmd"
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardInput = True
.RedirectStandardOutput = True
.RedirectStandardError = True
End With
With Process
.Start()
.BeginOutputReadLine()
End With
Using InputStream As System.IO.StreamWriter = Process.StandardInput
With InputStream
.AutoFlush = True
.Write("wmic bios get serialnumber" & vbCrLf)
End With
End Using
Do
Application.DoEvents()
Loop Until Process.HasExited
End Using
Return Replace(OutputString.Split(CChar(vbCrLf)).ToList(6).Substring(1), " ", "")
End Function
Sanjeeb LenkaPosted Sep 10, 2013, 1:52 PM
you can use this site to convert vb to c#
http://www.developerfusion.com/tools/convert/vb-to-csharp/
after converting your code to C#
public string GetBiosSerialNumber()
{
string OutputString = string.Empty;
using (Process Process = new Process()) {
Process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => { OutputString = OutputString + e.Data + Constants.vbCrLf; };
var _with1 = Process.StartInfo;
_with1.FileName = "cmd";
_with1.UseShellExecute = false;
_with1.CreateNoWindow = true;
_with1.RedirectStandardInput = true;
_with1.RedirectStandardOutput = true;
_with1.RedirectStandardError = true;
var _with2 = Process;
_with2.Start();
_with2.BeginOutputReadLine();
using (System.IO.StreamWriter InputStream = Process.StandardInput) {
var _with3 = InputStream;
_with3.AutoFlush = true;
_with3.Write("wmic bios get serialnumber" + Constants.vbCrLf);
}
do {
Application.DoEvents();
} while (!(Process.HasExited));
}
return Strings.Replace(OutputString.Split(Convert.ToChar(Constants.vbCrLf)).ToList(6).Substring(1), " ", "");
}
VulpesPosted Sep 10, 2013, 11:55 AM