使用代碼來探索vm細節

來源:互聯網
上載者:User
使用代碼來探索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" %></p><p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></p><p><html xmlns="http://www.w3.org/1999/xhtml"><br /><head runat="server"><br /> <title></title><br /></head><br /><body><br /> <form id="form1" runat="server"><br /> <div><br /> <asp:Label runat="Server" ID="lblOSName"></asp:Label><br /><br /> <asp:Label runat="Server" ID="lblMachineName"></asp:Label><br /><br /> <asp:Label runat="Server" ID="lblOSVersion"></asp:Label><br /><br /> <asp:Label runat="Server" ID="lblProcessorCount"></asp:Label><br /><br /> <asp:Label runat="Server" ID="lblClrVersion"></asp:Label><br /><br /> <asp:Label runat="Server" ID="lblCurrentDirectory"></asp:Label><br /><br /> <asp:Label runat="Server" ID="lblTimeSinceLastRestart"></asp:Label><br /><br /> <asp:Label runat="Server" ID="lblUserName"></asp:Label><br /><br /> <asp:Label runat="Server" ID="lblCPUName"></asp:Label><br /><br /> </div><br /> </form><br /></body><br /></html><br />

3.修改後台代碼

using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Web;<br />using System.Web.UI;<br />using System.Web.UI.WebControls;<br />using System.Management;</p><p>namespace LookkupVMDetails<br />{<br /> public partial class _Default : System.Web.UI.Page<br /> {<br /> protected void Page_Load(object sender, EventArgs e)<br /> {<br /> var computer = new Microsoft.VisualBasic.Devices.Computer();<br /> this.lblMachineName.Text = computer.Name;</p><p> // OS information<br /> this.lblOSName.Text = computer.Info.OSFullName;<br /> this.lblOSVersion.Text = computer.Info.OSVersion;</p><p> this.lblProcessorCount.Text = System.Environment.ProcessorCount.ToString();<br /> this.lblClrVersion.Text = System.Environment.Version.ToString();<br /> this.lblCurrentDirectory.Text = this.GetCurrentDirectory();</p><p> this.lblTimeSinceLastRestart.Text = this.GetTimeSinceLastRestart();</p><p> this.lblUserName.Text = System.Environment.UserName;<br /> this.lblCPUName.Text = this.GetCPUName();</p><p> }</p><p> private string GetCurrentDirectory()<br /> {<br /> try<br /> {<br /> return System.Environment.CurrentDirectory;<br /> }<br /> catch (System.Exception ex)<br /> {<br /> return "unavailable";<br /> }<br /> }</p><p> private string GetTimeSinceLastRestart()<br /> {<br /> try<br /> {<br /> TimeSpan time = new TimeSpan(0, 0, 0, 0,<br /> System.Environment.TickCount);</p><p> return time.ToString();<br /> }<br /> catch (System.Exception ex)<br /> {<br /> return "unavailable";<br /> }<br /> }</p><p> private string GetCPUName()<br /> {<br /> try<br /> {<br /> using(ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'"))<br /> {<br /> return (string)(Mo["Name"]);<br /> }<br /> }<br /> catch (System.Exception ex)<br /> {<br /> return "unavailable";<br /> }<br /> }</p><p> }<br />}

注意需要增加引用:

4.運行

本系列的部落格均是在學習windows azure平台時個人的感悟,其中難免存在不足之處,歡迎指正,留言提出您的寶貴意見。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.