I am using VB.net to to run some code which gathers the PC's hardware specification and OS version etc. (which I found and modified from the net)
When I run the code, it displays all of the above information onto a console application. I need the information gathered to be inserted into cells on an already existing excel document. For example when the console application displays 'OS VERSION - Windows 7', I need that to be transferred into a cell on an already existing excel sheet. Is this an easy thing to do or is it even possible?
I am not really VB.net literate..
Below is the code for 'module1' and the code for 'WMI'
Module Module1
Dim bit As String
Dim VGA As String
Sub Main()
If My.Computer.Registry.LocalMachine.OpenSubKey("Hardware\Description\System\CentralProcessor\0").GetValue("Identifier").ToString.Contains("x86") Then
bit = "32-bit"
Else
bit = "64-bit"
End If
Console.Title = "System Information's"
Console.WriteLine("your system information's")
Console.WriteLine("")
Console.WriteLine(My.Computer.Info.OSFullName.ToString())
Console.WriteLine(My.Computer.Info.OSPlatform.ToString())
Console.WriteLine(My.Computer.Info.OSVersion.ToString())
Console.WriteLine("Windows bit version: " + bit)
Console.WriteLine("Computer Name: " & My.Computer.Name.ToString())
Console.WriteLine("Current Date/Time: " & Date.Now.ToLongDateString + ", " + Date.Now.ToLongTimeString)
Console.WriteLine("")
Dim objWMI As New WMI()
With objWMI
Console.WriteLine("Computer Manufacturer = " & .Manufacturer)
Console.WriteLine("Computer Model = " & .Model)
Console.WriteLine("OS Version = " & .OSVersion)
Console.WriteLine("System Type = " & .SystemType)
Console.WriteLine("Windows Directory = " & .WindowsDirectory)
End With
Console.WriteLine("")
Console.WriteLine("Number of Processes: " & Environment.ProcessorCount.ToString)
Dim moSearch As New ManagementObjectSearcher("Select * from Win32_Processor")
Dim moReturn As ManagementObjectCollection = moSearch.Get
For Each mo As ManagementObject In moReturn
Console.WriteLine("Processor: " & (mo("name")))
Next
Dim ramsize As Integer
ramsize = My.Computer.Info.TotalPhysicalMemory / 1024 / 1024
Console.WriteLine("Memory: " & ramsize.ToString & "MB RAM")
Console.WriteLine("")
Dim WmiSelect As New ManagementObjectSearcher _
("root\CIMV2", "SELECT * FROM Win32_VideoController")
For Each WmiResults As ManagementObject In WmiSelect.Get()
VGA = WmiResults.GetPropertyValue("Name").ToString
Next
Console.WriteLine("Computer Display Info: " & VGA)
Dim intX As Integer = Windows.Forms.Screen.PrimaryScreen.Bounds.Width
Dim intY As Integer = Windows.Forms.Screen.PrimaryScreen.Bounds.Height
Console.WriteLine("Screen Resolution: " & intX & " X " & intY)
Console.WriteLine("")
Console.WriteLine("Total Physical Memory: " & My.Computer.Info.TotalPhysicalMemory.ToString())
Console.WriteLine("Total Virtual Memory: " & My.Computer.Info.TotalVirtualMemory.ToString())
Console.WriteLine("Available Virtual Memory: " & My.Computer.Info.AvailableVirtualMemory.ToString())
Console.WriteLine("Available Physical Memory: " & My.Computer.Info.AvailablePhysicalMemory.ToString())
Console.WriteLine("Network Available: " & My.Computer.Network.IsAvailable.ToString())
Console.WriteLine("Additional Info:")
Console.WriteLine("Scroll Lock " & My.Computer.Keyboard.ScrollLock)
Console.WriteLine("Num Lock " & My.Computer.Keyboard.NumLock)
Console.WriteLine("Caps Lock " & My.Computer.Keyboard.CapsLock)
Console.WriteLine("")
Console.WriteLine("Current Processes: ")
Console.WriteLine("")
For Each p As Process In Process.GetProcesses
Console.WriteLine(p)
Next
Console.ReadKey()
End Sub
End Module
Public Class WMI
Private objOS As Management.ManagementObjectSearcher
Private objCS As Management.ManagementObjectSearcher
Private objMgmt As Management.ManagementObject
Private m_strComputerName As String
Private m_strManufacturer As String
Private m_StrModel As String
Private m_strOSName As String
Private m_strOSVersion As String
Private m_strSystemType As String
Private m_strTPM As String
Private m_strWindowsDir As String
Public Sub New()
objOS = New Management.ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
objCS = New Management.ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")
For Each objMgmt In objOS.Get
m_strOSName = objMgmt("name").ToString()
m_strOSVersion = objMgmt("version").ToString()
m_strComputerName = objMgmt("csname").ToString()
m_strWindowsDir = objMgmt("windowsdirectory").ToString()
Next
For Each objMgmt In objCS.Get
m_strManufacturer = objMgmt("manufacturer").ToString()
m_StrModel = objMgmt("model").ToString()
m_strSystemType = objMgmt("systemtype").ToString
m_strTPM = objMgmt("totalphysicalmemory").ToString()
Next
End Sub
Public ReadOnly Property ComputerName()
Get
ComputerName = m_strComputerName
End Get
End Property
Public ReadOnly Property Manufacturer()
Get
Manufacturer = m_strManufacturer
End Get
End Property
Public ReadOnly Property Model()
Get
Model = m_StrModel
End Get
End Property
Public ReadOnly Property OsName()
Get
OsName = m_strOSName
End Get
End Property
Public ReadOnly Property OSVersion()
Get
OSVersion = m_strOSVersion
End Get
End Property
Public ReadOnly Property SystemType()
Get
SystemType = m_strSystemType
End Get
End Property
Public ReadOnly Property TotalPhysicalMemory()
Get
TotalPhysicalMemory = m_strTPM
End Get
End Property
Public ReadOnly Property WindowsDirectory()
Get
WindowsDirectory = m_strWindowsDir
End Get
End Property
End Class
Aucun commentaire:
Enregistrer un commentaire