Yazdigimiz programlarin sadece bir bilgisayarda kullanilmasini, emegimizin korunmasini isteriz. Bunun için her program kopyasina farkli bir lisans islemi gerekmektedir. Lisans islemini programin kuruldugu bilgisayar islemcisinin, hard diskinin veya ana kartinin seri numarasini, markasini yada modeli ögrenerek gelistiririz. Bu tip oem bilgilerini almak için System.Management sinifini kullanacagiz ancak varsayilan olarak referanslarimiza ekli degildir. Solution Explorer sekmesinden referanslara sag tiklayip, referans ekle diyelim.
Referansimizi ekledikten sonra sayfimiza import ederek kullancagiz.
Asagidaki örnek kodlarda anakarti, islemci, harddisk serial numaralarini ve bilgisayar host ismini yani makine ismini cekecegiz.
' System.Management kütüphanemizi projemize import etmeyi unutmuyoruz.
Imports System.Management
Public Class Form1
Private Sub AnaKartSerial()
Dim motherboardserial = String.Empty
Dim mos As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard")
Dim moc As ManagementObjectCollection = mos.[Get]()
For Each mo As ManagementObject In moc
motherboardserial = CStr(mo("SerialNumber"))
Exit For
Next
Label2.Text = motherboardserial
End Sub
Private Sub islemciSerial()
Dim cpuid = String.Empty
Dim sQuery As String = "SELECT ProcessorId FROM Win32_Processor"
Dim oManagementObjectSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(sQuery)
Dim oCollection As ManagementObjectCollection = oManagementObjectSearcher.[Get]()
For Each oManagementObject As ManagementObject In oCollection
cpuid = CStr(oManagementObject("ProcessorId"))
Exit For
Next
Label3.Text = cpuid
End Sub
Private Sub BiosBilgileri()
Dim BIOSSürüm As String = Nothing
Dim Version As String = Nothing
Dim TargetOperatingSystem As String = Nothing
Dim Status As String = Nothing
Dim SoftwareElementState As String = Nothing
Dim SoftwareElementID As String = Nothing
Dim SMBIOSPresent As String = Nothing
Dim SMBIOSMinorVersion As String = Nothing
Dim SMBIOSMajorVersion As String = Nothing
Dim SerialNumber As String = Nothing
Dim ReleaseDate As String = Nothing
Dim PrimaryBIOS As String = Nothing
Dim Name As String = Nothing
Dim Manufacturer As String = Nothing
Dim ListOfLanguages As String = Nothing
Dim InstallableLanguages As String = Nothing
Dim Description As String = Nothing
Dim CurrentLanguage As String = Nothing
Dim Caption As String = Nothing
Dim BiosCharacteristics As String = Nothing
Dim sQuery As String = "Select * FROM WIN32_BIOS"
Dim oManagementObjectSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(sQuery)
Dim oCollection As ManagementObjectCollection = oManagementObjectSearcher.[Get]()
For Each oManagementObject As ManagementObject In oCollection
BIOSSürüm = oManagementObject("SoftwareElementID")
Version = oManagementObject("Version")
TargetOperatingSystem = oManagementObject("TargetOperatingSystem")
Status = oManagementObject("Status")
SoftwareElementID = oManagementObject("SoftwareElementID")
SoftwareElementState = oManagementObject("SoftwareElementState")
SMBIOSPresent = oManagementObject("SMBIOSPresent")
SMBIOSMinorVersion = oManagementObject("SMBIOSMinorVersion")
SMBIOSMajorVersion = oManagementObject("SMBIOSMajorVersion")
SerialNumber = oManagementObject("SerialNumber")
ReleaseDate = oManagementObject("ReleaseDate")
PrimaryBIOS = oManagementObject("PrimaryBIOS")
Name = oManagementObject("Name")
Manufacturer = oManagementObject("Manufacturer")
'ListOfLanguages = oManagementObject("ListOfLanguages")
InstallableLanguages = oManagementObject("InstallableLanguages")
Description = oManagementObject("Description")
CurrentLanguage = oManagementObject("CurrentLanguage")
Caption = oManagementObject("Caption")
'BiosCharacteristics = oManagementObject("BiosCharacteristics")
Exit For
Next
lblBIOSSürüm.Text = BIOSSürüm
lblVersion.Text = Version
lblTargetOperating.Text = TargetOperatingSystem
lblStatus.Text = Status
lblSoftwareElementID.Text = SoftwareElementID
lblSoftwareElementState.Text = SoftwareElementState
lblSMBIOSPresent.Text = SMBIOSPresent
lblSMBIOSMajorVersion.Text = SMBIOSMajorVersion
lblSMBIOSMinorVersion.Text = SMBIOSMinorVersion
lblSerialNumber.Text = SerialNumber
lblReleaseDate.Text = ReleaseDate
lblPrimaryBIOS.Text = PrimaryBIOS
lblName.Text = Name
lblManufacturer.Text = Manufacturer
lblInstallableLanguages.Text = InstallableLanguages
lblDescription.Text = Description
lblCurrentLanguage.Text = CurrentLanguage
lblCaption.Text = Caption
End Sub
Public Shared Function GetSerialsFromHardDrives() As List(Of String)
Dim serials As New List(Of String)()
Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
Dim disks As ManagementObjectCollection = searcher.[Get]()
For Each disk As ManagementObject In disks
If disk("SerialNumber") Is Nothing Then
serials.Add("")
Exit For
Else
serials.Add(disk("SerialNumber").ToString())
Exit For
End If
Next
Return serials
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AnaKartSerial()
islemciSerial()
BiosBilgileri()
Dim HDDSerial As String = String.Empty
Dim serialsList As List(Of String) = GetSerialsFromHardDrives()
For Each s As String In serialsList
HDDSerial = s
Exit For
Next
Label6.Text = HDDSerial
Label8.Text = SystemInformation.UserDomainName
End Sub
End Class
Yukaridaki islemler gibi asagidaki Win32 islemleride yapilabilir.
Select * FROM WIN32_ComputerSystem
Select * FROM WIN32_OperatingSystem
Select * FROM WIN32_Environment
Select * FROM WIN32_SystemDriver
Select * FROM WIN32_Service
Select * FROM WIN32_Process
Select * FROM WIN32_StartupCommand
Select * FROM WIN32_Registry
Select * FROM WIN32_NTEventLogFile
Select * FROM WIN32_TimeBone
Select * FROM WIN32_QuickFixEngineering
Select * FROM WIN32_BootConfiguration
Select * FROM WIN32_WMISetting
Select * FROM WIN32_DiskDrive
Select * FROM WIN32_LogicalDisk
Select * FROM WIN32_DiskPartition
Select * FROM WIN32_Share
Select * FROM WIN32_IDEController
Select * FROM WIN32_CDROMDrive
Select * FROM WIN32_SystemSlot
Select * FROM WIN32_PhysicalMemory
Select * FROM WIN32_PhysicalMemoryArray
Select * FROM WIN32_BIOS
Select * FROM WIN32_DesktopMonitor
Select * FROM WIN32_NetworkAdaptor
Select * FROM WIN32_Configuration
Select * FROM WIN32_Printer
Select * FROM WIN32_UserAccount
Select * FROM WIN32_SystemAccount
Select * FROM WIN32_NTDomain
Select * FROM WIN32_Group
Select * FROM WIN32_ComputerSystemProduct
Uygulama dosyasini buradan indirebilirsiniz.