Use PowerShell. Net to obtain the UUID and powershelluuid in the computer.

Source: Internet
Author: User

Use PowerShell. Net to obtain the UUID and powershelluuid in the computer.

UUID stands for the universal Unique Identifier, which is a standard for Software construction and also known as the Open Software Foundation (OSF) organizations are part of the application in the Distributed Computing Environment (Distributed Computing Environment, DCE) field.

Composition

UUID refers to the number generated on a machine, which ensures that all machines in the same time and space are unique. Generally, the platform provides the generated API. According to the standards set by the Open Software Foundation (OSF), ethernet card addresses, nanoseconds, chip ID codes, and many possible numbers are used.

UUID consists of the following parts:

(1) The current date and time. The first part of UUID is related to the time. If you generate a UUID after several seconds and then generate a UUID, the first part is different, the rest are the same.

(2) Clock sequence.

(3) Globally Unique IEEE machine identification number. If there is a nic, it is obtained from the nic mac address, and no Nic is obtained in other ways.

The unique defect of UUID is that the generated result string is long. The most common UUID standard is Microsoft's GUID (Globals Unique Identifiers ). In ColdFusion, you can use the CreateUUID () function to generate a UUID in the format of xxxxxxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16 ), each x is a hexadecimal number in the range of 0-9 or a-f. The standard UUID format is: xxxxxxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12). You can download CreateGUID () UDF from cflib for conversion.

------- The above content is taken from Baidu encyclopedia

Because software products need to be bound to the hardware code, we thought of UUID. After searching for a bunch of codes on the Internet via Baidu, we found that most of the Code is as follows:

Reference: System. Management;

String processor = "Win32_Processor"; // class name ManagementClass driveClass = new ManagementClass (processor); Console. WriteLine (driveClass. GetQualifierValue ("UUID "));

Then, let all our colleagues in the Department run on their respective computers. The results are as follows:

All running results are the same. (Why ?? I do not know yet, but I am unwilling to continue searching for Google)

---------------------------------------------- I am a separation line -----------------------------------------------

However, I found that Windows PowerShell can also obtain UUID. Although I am not familiar with PowerShell, can I solve my problem at the core?

Windows PowerShell is a command line shell program and script environment that allows command line users and script writers to take advantage of the powerful functions of. NET Framework.

It introduces many useful new concepts to further expand your knowledge and scripts created in the Windows Command Prompt and Windows Script Host environment.

First, you must ensure that PowerShell is installed on your System on the operating System, and System must be referenced in the Vs development project. management. automation. dll, which is in the path below my computer: "C: \ windows \ assembly \ GAC_MSIL \ System. management. automation \ 1.0.0.0 _ 31bf3856ad364e35 \ ", local operating system: Win7 core code:

private static string GetUUID(){try{string uuid = string.Empty;using (PowerShell PowerShellInstance = PowerShell.Create()){PowerShellInstance.AddScript("(get-wmiobject Win32_ComputerSystemProduct).UUID"); //OKCollection<PSObject> PSOutput = PowerShellInstance.Invoke();foreach (PSObject outputItem in PSOutput){if (outputItem != null){uuid += outputItem.BaseObject.ToString();}}}return uuid;}catch{return string.Empty;}}

The call is actually obtained using the PowerShell Script. Because it may be slow to call PowerShell,. net also provides an asynchronous call mechanism. The core code is as follows:

Private static string GetAsyncUUID () {try {string uuid = string. empty; using (PowerShell PowerShellInstance = PowerShell. create () {PowerShellInstance. addScript ("(get-wmiobject Win32_ComputerSystemProduct ). UUID "); // OKPSDataCollection <PSObject> outputCollection = new PSDataCollection <PSObject> (); outputCollection. dataAdded + = outputCollection_DataAdded; PowerShellInstance. streams. error. dataAdded + = Error _ DataAdded; IAsyncResult result = PowerShellInstance. beginInvoke <PSObject, PSObject> (null, outputCollection); while (result. isCompleted = false) {Console. writeLine ("Waiting for pipeline to finish... "); Thread. sleep (1000); // you can write some tasks that are waiting for execution in the While;} foreach (PSObject outputItem in outputCollection) {if (outputItem! = Null) {uuid + = outputItem. baseObject. toString () ;}} return uuid;} catch {return string. empty ;}} static void Error_DataAdded (object sender, DataAddedEventArgs e) {Console. writeLine ("An error was written to the Error stream! ");} Static void outputCollection_DataAdded (object sender, DataAddedEventArgs e) {Console. WriteLine (" Object added to output .");}

After the above Code is run and tested, no department is repeated.

The result is as follows:

 

For the time being, from the analysis of the above test results, this method is feasible. However, there are still several concerns:

1. Will the calling methods of PowerShell be different in different versions? As B/s software, do you need to consider more Windows servers? For example: (get-wmiobject Win32_ComputerSystemProduct). UUID

2. Will PowerShell be disabled by the server for security purposes?

3. Does the B/s software require IIS to run ??

The above section describes how to use PowerShell. net to get the UUID related knowledge in the computer, hope to help you, if you have any questions, please leave a message, xiaobian will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.