Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Get Hard disk serial Number

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CheckHD
{
        class HDSerial
        {
            const string MY_SERIAL = "F845-BB23";
            public static bool CheckSerial()
            {
                string res = ExecuteCommandSync("vol");
                const string search = "Number is";
                int startI = res.IndexOf(search, StringComparison.InvariantCultureIgnoreCase);

                if (startI > 0)
                {
                    string currentDiskID = res.Substring(startI + search.Length).Trim();
                    if (currentDiskID.Equals(MY_SERIAL))
                        return true;
                }
                return false;
            }

            public static string ExecuteCommandSync(object command)
            {
                try
                {
                    // create the ProcessStartInfo using "cmd" as the program to be run,
                    // and "/c " as the parameters.
                    // Incidentally, /c tells cmd that we want it to execute the command that follows,
                    // and then exit.
                    System.Diagnostics.ProcessStartInfo procStartInfo =
                        new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);

                    // The following commands are needed to redirect the standard output.
                    // This means that it will be redirected to the Process.StandardOutput StreamReader.
                    procStartInfo.RedirectStandardOutput = true;
                    procStartInfo.UseShellExecute = false;
                    // Do not create the black window.
                    procStartInfo.CreateNoWindow = true;
                    // Now we create a process, assign its ProcessStartInfo and start it
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.StartInfo = procStartInfo;
                    proc.Start();
                    // Get the output into a string
                    string result = proc.StandardOutput.ReadToEnd();
                    // Display the command output.
                    return result;
                }
                catch (Exception)
                {
                    // Log the exception
                    return null;
                }
            }
        }
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# push list 
Csharp :: random in unity 
Csharp :: unique items in list c# 
Csharp :: c# letters only 
Csharp :: call stored proc c# 
Csharp :: slider.onchanged in unity 
Csharp :: hashing a file in C# 
Csharp :: how to make multiplayer game in unity 
Csharp :: loop through string array c# 
Csharp :: convert string to int and read it 
Csharp :: c# string remove special characters 
Csharp :: List string to file C# 
Csharp :: destroy game object 
Csharp :: c# add picturebox to form 
Csharp :: polybius square 
Csharp :: c# type from string 
Csharp :: xamarin hide back button 
Csharp :: how to make unity build to not be full screen 
Csharp :: implement custom string to datetime convert net core 
Csharp :: mvc get base url 
Csharp :: get client ip address c# 
Csharp :: redirect to another controller page in asp.net core 
Csharp :: response redirect new tab 
Csharp :: 3d perlin noise unity 
Csharp :: unity vs unreal for beginners 
Csharp :: flip sprite in unity 
Csharp :: add variable to the beginning of a list c# 
Csharp :: update squence c# 
Csharp :: dotnet call webapi 
Csharp :: c# dictionary values to list 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =