18-12-16, 10:12 AM
(آخر تعديل لهذه المشاركة : 18-12-16, 10:21 AM {2} بواسطة silverlight.)
هذه بعض الدوال و الأفكار لتوضيح كيفية التعامل مع الكمبيوتر من Command Prompt و هذا يتم باستخدام الأوامر القديمة للدوس
تحذير
لا ينصح بالتعامل مع الدوال بدون فهم جيد للموضوع
الدالة الأولي كيفية الحصول علي MacAddress
الإستخدام
الدالة الثانية قراءة التاريخ
الإستخدام
هذه عينة ويمكن استخدام نفس الاسلوب لقراءة المزيد من المعلومات عن الكمبيوتر
و أيضا يمكن استخدام نفس الفكرة لتغيير تاريخ النظام او إضافة فهرس او حذف ملف ...الي أخره
عموما الفكرة هنا تشبه الي حد كبير فكرة التعامل مع WMIC في System.Management
الكلاس التالي به المزيد من الأفكار
الكلاس انا كنت كتبته من فترة
وربما يحتاج للتعديل عليه قليلا
تحذير
لا ينصح بالتعامل مع الدوال بدون فهم جيد للموضوع
الدالة الأولي كيفية الحصول علي MacAddress
PHP كود :
Private Function GetMACAddress() As String
Dim result As String = ""
Using p As Process = New Process
Dim pi As ProcessStartInfo = New ProcessStartInfo
pi.Arguments = "/c wmic nicconfig get MACAddress"
pi.FileName = "cmd"
pi.RedirectStandardOutput = True
pi.UseShellExecute = False
pi.CreateNoWindow = True
p.StartInfo = pi
p.Start()
Dim reader As StreamReader = p.StandardOutput
Dim sb As New Text.StringBuilder()
Dim lines As String = reader.ReadToEnd
Dim list As New List(Of String)
For Each l As String In lines
If Not String.IsNullOrEmpty(New String(l.ToCharArray().Where(Function(c) Not Char.IsWhiteSpace(c)).ToArray())) Then
list.Add(l)
End If
Next
For Each line As String In list
If Not String.IsNullOrEmpty(New String(line.ToCharArray().Where(Function(c) Not Char.IsWhiteSpace(c)).ToArray())) Then
sb.Append(line.Replace(":", " "))
End If
Next
Dim s As String = sb.ToString.Replace("MACAddress", "")
sb.Clear()
For Each item In s.Split(" "c)
For Each input As String In Enumerable.Range(0, item.Length \ 2).Select(Function(i) item.Substring(i * 2, 2))
sb.Append(input)
sb.Append(" "c)
Next
Next
result = sb.ToString
End Using
Return result.TrimEnd(" "c)
End Function
الإستخدام
PHP كود :
Dim macAddress As String = GetMACAddress()
الدالة الثانية قراءة التاريخ
PHP كود :
Private Function GetSystemDate() As String
Dim result As String = ""
Using p As Process = New Process
Dim pi As ProcessStartInfo = New ProcessStartInfo
pi.Arguments = "/c date /t"
pi.FileName = "cmd"
pi.RedirectStandardOutput = True
pi.UseShellExecute = False
pi.CreateNoWindow = True
p.StartInfo = pi
p.Start()
Dim reader As StreamReader = p.StandardOutput
Dim sb As New Text.StringBuilder()
Dim lines As String = reader.ReadToEnd
' ممكن الإكتفاء بالسطر اعلاه من الكود و بالتالي نحصل علي التاريخ علي هيئة مصفوفة
For Each l As String In lines
result += l
Next
End Using
result.Trim()
' ************************************************************************************
' هذا الجزء من الكود من الممكن الإستغناء عنه و لاحقا نتعامل مع المخرجات كيفما أردنا
Dim dt As String = result.Split(" "c)(0)
result = result.Replace(dt, "").Trim
' ************************************************************************************
Return result
End Function
الإستخدام
PHP كود :
Dim systemDateTime As String = GetSystemDate()
هذه عينة ويمكن استخدام نفس الاسلوب لقراءة المزيد من المعلومات عن الكمبيوتر
و أيضا يمكن استخدام نفس الفكرة لتغيير تاريخ النظام او إضافة فهرس او حذف ملف ...الي أخره
عموما الفكرة هنا تشبه الي حد كبير فكرة التعامل مع WMIC في System.Management
الكلاس التالي به المزيد من الأفكار
الكلاس انا كنت كتبته من فترة
وربما يحتاج للتعديل عليه قليلا
PHP كود :
Imports System.IO
Public Class OSInfo
''' <summary>
''' Get Information About Operating System such as Caption, CSDVersion, OSArchitecture, Version
''' </summary>
Public Sub New()
End Sub
Public ReadOnly Property Is64Bit As Boolean
Get
Return OSArchitecture.Contains("64")
End Get
End Property
''' <summary>
''' Get the name of the installed operating system
''' </summary>
''' <returns></returns>
Public ReadOnly Property OSName As String
Get
Return GetCaption()
End Get
End Property
''' <summary>
''' Get The processor architecture of the installed operating system
''' </summary>
''' <returns></returns>
Public ReadOnly Property OSArchitecture As String
Get
Return GetOSArchitecture()
End Get
End Property
''' <summary>
''' Get the version of the installed operating system
''' </summary>
''' <returns></returns>
Public ReadOnly Property OSVersion As String
Get
Return GetVersion()
End Get
End Property
''' <summary>
''' Get the name of the most recent service pack installed
''' </summary>
''' <returns></returns>
Public ReadOnly Property CSDVersion As String
Get
Return GetCSDVersion()
End Get
End Property
Private Function GetSystemInfo(currentProcess As Process, func As Func(Of Process, String)) As String
Return func(currentProcess)
End Function
Private Function GetOSArchitecture() As String
Return GetSystemInfo(New Process, Function(current As Process)
Using current
Dim pi As ProcessStartInfo = New ProcessStartInfo
Dim result As String = CType(Nothing, String)
pi.Arguments = "/c wmic OS Get OSArchitecture"
pi.FileName = "cmd"
pi.RedirectStandardOutput = True
pi.UseShellExecute = False
pi.CreateNoWindow = True
current.StartInfo = pi
current.Start()
Using reader As StreamReader = current.StandardOutput
result = reader.ReadToEnd()
End Using
Return result
End Using
Return Nothing
End Function)
End Function
Private Function GetCaption() As String
Return GetSystemInfo(New Process, Function(current As Process)
Using current
Dim pi As ProcessStartInfo = New ProcessStartInfo
Dim result As String = CType(Nothing, String)
pi.Arguments = "/c wmic OS Get Caption"
pi.FileName = "cmd"
pi.RedirectStandardOutput = True
pi.UseShellExecute = False
pi.CreateNoWindow = True
current.StartInfo = pi
current.Start()
Using reader As StreamReader = current.StandardOutput
result = reader.ReadToEnd()
End Using
Return result
End Using
Return Nothing
End Function)
End Function
Private Function GetCSDVersion() As String
Return GetSystemInfo(New Process, Function(current As Process)
Using current
Dim pi As ProcessStartInfo = New ProcessStartInfo
Dim result As String = CType(Nothing, String)
pi.Arguments = "/c wmic OS Get CSDVersion"
pi.FileName = "cmd"
pi.RedirectStandardOutput = True
pi.UseShellExecute = False
pi.CreateNoWindow = True
current.StartInfo = pi
current.Start()
Using reader As StreamReader = current.StandardOutput
result = reader.ReadToEnd()
End Using
Return result
End Using
Return Nothing
End Function)
End Function
Private Function GetVersion() As String
Return GetSystemInfo(New Process, Function(current As Process)
Using current
Dim pi As ProcessStartInfo = New ProcessStartInfo
Dim result As String = CType(Nothing, String)
pi.Arguments = "/c wmic OS Get Version"
pi.FileName = "cmd"
pi.RedirectStandardOutput = True
pi.UseShellExecute = False
pi.CreateNoWindow = True
current.StartInfo = pi
current.Start()
Using reader As StreamReader = current.StandardOutput
result = reader.ReadToEnd()
End Using
Return result
End Using
Return Nothing
End Function)
End Function
End Class