使用代码来探索vm细节
1.新建windows azure工程
2.修改Default.aspx页面
3.修改后台代码
4.运行
1.新建windows azure工程
2.修改Default.aspx页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="LookkupVMDetails._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label runat="Server" ID="lblOSName"></asp:Label><br /> <asp:Label runat="Server" ID="lblMachineName"></asp:Label><br /> <asp:Label runat="Server" ID="lblOSVersion"></asp:Label><br /> <asp:Label runat="Server" ID="lblProcessorCount"></asp:Label><br /> <asp:Label runat="Server" ID="lblClrVersion"></asp:Label><br /> <asp:Label runat="Server" ID="lblCurrentDirectory"></asp:Label><br /> <asp:Label runat="Server" ID="lblTimeSinceLastRestart"></asp:Label><br /> <asp:Label runat="Server" ID="lblUserName"></asp:Label><br /> <asp:Label runat="Server" ID="lblCPUName"></asp:Label><br /> </div> </form> </body> </html>
3.修改后台代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Management; namespace LookkupVMDetails { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { var computer = new Microsoft.VisualBasic.Devices.Computer(); this.lblMachineName.Text = computer.Name; // OS information this.lblOSName.Text = computer.Info.OSFullName; this.lblOSVersion.Text = computer.Info.OSVersion; this.lblProcessorCount.Text = System.Environment.ProcessorCount.ToString(); this.lblClrVersion.Text = System.Environment.Version.ToString(); this.lblCurrentDirectory.Text = this.GetCurrentDirectory(); this.lblTimeSinceLastRestart.Text = this.GetTimeSinceLastRestart(); this.lblUserName.Text = System.Environment.UserName; this.lblCPUName.Text = this.GetCPUName(); } private string GetCurrentDirectory() { try { return System.Environment.CurrentDirectory; } catch (System.Exception ex) { return "unavailable"; } } private string GetTimeSinceLastRestart() { try { TimeSpan time = new TimeSpan(0, 0, 0, 0, System.Environment.TickCount); return time.ToString(); } catch (System.Exception ex) { return "unavailable"; } } private string GetCPUName() { try { using(ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'")) { return (string)(Mo["Name"]); } } catch (System.Exception ex) { return "unavailable"; } } } }
注意需要增加引用:
4.运行
本系列的博客均是在学习windows azure平台时个人的感悟,其中难免存在不足之处,欢迎指正,留言提出您的宝贵意见。