Windows 8 Store Apps Learning (30) information

Source: Internet
Author: User
Tags current time datetime tostring

Information: Get package information, System information, hardware information, PNP information, common equipment information

Introduced

Re-imagine the information for Windows 8 Store Apps

Get package information

Get System Information

Getting hardware information

Get information for devices with Plug and Play (Pnp:plug)

Get Common device information

Example

1, demo How to obtain the package information of the app

Information/packageinfo.xaml.cs

* * Demonstrates how to obtain the package information of the app * * using System;
Using Windows.applicationmodel;
Using Windows.UI.Xaml.Controls;
    
Using Windows.UI.Xaml.Navigation;
        Namespace Xamldemo.information {public sealed partial class Packageinfo:page {public PackageInfo () {this.
        InitializeComponent (); } protected override void Onnavigatedto (NavigationEventArgs e) {Package Package = Packag
            E.current; PackageID PackageID = package.
    
            Id; Lblmsg.text = "Name:" + packageid.name;
            Package name Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Version:" + packageid.version;
            Version information Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Architecture:" + packageid.architecture;
            Supported CPU types (X86, ARM, X64, Neutral (all supported), Unknown) Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Publisher:" + packageid.publisher; Published by Lblmsg.
            Text + Environment.NewLine; Lblmsg.text + = "PublisherID:" + Packageid.publisherid;
            Publisher ID Lblmsg.text + = environment.newline; Lblmsg.text + = "FullName:" + packageid.fullname;
            Package Full Name (name + Version + architecture + publisherid) Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Familyname:" + packageid.familyname;
            Package Series name (name + publisherid) Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Installed Location Path:" + package. Installedlocation.path; Installation path for package}}}

2, demonstrate how to obtain information about the system

Information/systeminfo.xaml.cs

* * Demonstrates how to obtain the relevant information about the system * * using System;
Using System.Globalization;
Using System.Threading.Tasks;
Using WINDOWS.DEVICES.ENUMERATION.PNP;
Using Windows.UI.Xaml.Controls;
Using Windows.UI.Xaml.Navigation;
    
Using System.Linq;
        Namespace Xamldemo.information {public sealed partial class Systeminfo:page {public SystemInfo () {this.
        InitializeComponent (); } protected async override void Onnavigatedto (NavigationEventArgs e) {lblmsg.text + = "CP
            U Core Quantity: "+ Environment.ProcessorCount.ToString" ();
    
            Lblmsg.text + = Environment.NewLine;
            Lblmsg.text + = "The number of milliseconds that the system has been through since its last startup:" + Environment.tickcount;
    
            Lblmsg.text + = Environment.NewLine;
            Lblmsg.text + = "Current language:" + CultureInfo.CurrentCulture.DisplayName;
    
            Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Current time:" + DateTime.Now.ToString ("yyyy mm month DD Day HH:MM:SS") + "Week" + "Day 1234567". Substring ((int)
            DateTime.Now.DayOfWeek, 1);
    
            Lblmsg.text + = Environment.NewLine;
            Lblmsg.text + = "Current time zone:" + "UTC" + DateTimeOffset.Now.ToString ("%k");
    
            Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Current system version number:" + (await Getwindowsversionasync ()).
        ToString (); #region get the current system version number, excerpted from: http://attackpattern.com/2013/03/device-information-in-windows-8-store-apps/p ublic static async task<string> Getwindowsversionasync () {var Hal = await Gethaldevice (devicedr
            Iverversionkey); if (HAL = null | |!hal.
    
            Properties.containskey (devicedriverversionkey)) return null; var versionparts = Hal. Properties[devicedriverversionkey]. ToString ().
            Split ('. '); return string. Join (".", Versionparts.take (2).
        ToArray ()); private static Async task<pnpobject> Gethaldevice (params string[] properties) {var ac Tualproperties =Properties.
            Concat (new[] {deviceclasskey});
    
            var rootdevices = await Pnpobject.findallasync (Pnpobjecttype.device, actualproperties, rootquery);
            foreach (Var rootdevice in Rootdevices.where (d => d.properties!= null && d.properties.any ()))
                {var lastproperty = RootDevice.Properties.Last (); if (lastproperty.value!= null) if (lastProperty.Value.ToString ().
            Equals (Haldeviceclass)) return rootdevice;
        return null;
        Const string Deviceclasskey = "{a45c254e-df1c-4efd-8020-67d146a850e0},10";
        Const string Devicedriverversionkey = "{a8b865dd-2e3d-4094-ad97-e593a70c75d6},3";
        Const string Rootcontainer = "{00000000-0000-0000-ffff-ffffffffffff}";
        Const string rootquery = "system.devices.containerid:=\" "+ Rootcontainer +" \ "; Const string Haldeviceclass = "4d36e966-e325-11ce-bfc1-08002be10318 "; #endregion}}

3. Demonstrate how to obtain hardware-related information

Information/hardwareinfo.xaml.cs

* * Demonstrates how to obtain hardware-related information * * using System;
Using Windows.Storage.Streams;
Using Windows.System.Profile;
Using Windows.UI.Xaml.Controls;
    
Using Windows.UI.Xaml.Navigation;
        Namespace Xamldemo.information {public sealed partial class Hardwareinfo:page {public Hardwareinfo () {this.
        InitializeComponent (); } protected override void Onnavigatedto (NavigationEventArgs e) {Hardwaretoken Hardwareto
    
            Ken = Hardwareidentification.getpackagespecifictoken (NULL); Lblmsg.text = "Id:" + buffer2base64 (hardwaretoken.id);
            Hardware ID Lblmsg.text + = Environment.NewLine;
            Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Signature:" + buffer2base64 (hardwaretoken.signature);
            Hardware signature Lblmsg.text + = Environment.NewLine;
            Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Certificate:" + buffer2base64 (hardwaretoken.certificate);
   Hardware Certificate     private string Buffer2base64 (Ibuffer buffer) {using (var DataReader = DataReader. Frombuffer (buffer) {try {var bytes = new Byte[buffer.
                    Length];
    
                    Datareader.readbytes (bytes);
                Return convert.tobase64string (bytes); catch (Exception ex) {return ex.
                ToString (); }
            }
        }
    }
}

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.