Pernahkah
Anda ingin mendeteksi jenis sistem operasi Windows versi yang mana digunakan di
komputer tempat program Anda dijalankan nantinya? Kadang-kadang Anda
membutuhkan fungsi ini misalnya untuk memastikan penanganan khusus di program
Anda untuk masing-masing jenis sistem operasi tersebut. Berikut ini solusinya!
Code::
|
'Deskripsi: Mendeteksi jenis sistem operasi Windows di suatu komputer. 'Persiapan: 1. Buat 1 Project baru dengan 1 Form, 1 Commandbutton, ' dan satu Module (.bas)
' 2. Copy-kan coding berikut ke dalam editor form dan module ' yang bertalian.
'-------------------------------------------------------------------------- '--- Coding ini di Module --- Option Explicit
'Kode yang dimodifikasi berasal dari artikel di Visual Studio Magazine by Hank Marquis
'http://www.fawcette.com/vsm/2002_05/magazine/columns/desktopdeveloper/default_pf.asp
'Private Const VER_PLATFORM_WIN32s As Long = 0
Private Const VER_PLATFORM_WIN32_WINDOWS As Long = 1
Private Const VER_PLATFORM_WIN32_NT As Long = 2
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformID As Long
szCSDVersion As String * 128
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long
Public Function WinVer() As String
'Mengembalikan jenis Sistem Operasi
Dim tOVI As OSVERSIONINFO
'Seharusnya 148: (128 + (4 * 5)) - Tipe data Long = 4 bytes
tOVI.dwOSVersionInfoSize = Len(tOVI)
'Mulai periksa
If GetVersionEx(tOVI) = 1 Then
If tOVI.dwPlatformID = VER_PLATFORM_WIN32_NT And _
tOVI.dwMajorVersion = 5 And _
tOVI.dwMinorVersion = 1 Then
WinVer = "XP"
ElseIf tOVI.dwPlatformID = VER_PLATFORM_WIN32_NT And _
tOVI.dwMajorVersion = 5 And _
tOVI.dwMinorVersion = 0 Then
WinVer = "00"
ElseIf tOVI.dwPlatformID = VER_PLATFORM_WIN32_NT And tOVI.dwMajorVersion = 4 Then
WinVer = "NT"
ElseIf tOVI.dwPlatformID = VER_PLATFORM_WIN32_WINDOWS And _
tOVI.dwMajorVersion = 4 And _
tOVI.dwMinorVersion = 90 Then
WinVer = "ME"
ElseIf (tOVI.dwPlatformID = VER_PLATFORM_WIN32_WINDOWS) And _
(tOVI.dwMajorVersion > 4) Or _
(tOVI.dwMajorVersion = 4 And _
tOVI.dwMinorVersion > 0) Then
WinVer = "98"
ElseIf tOVI.dwPlatformID = VER_PLATFORM_WIN32_WINDOWS And _
tOVI.dwMajorVersion = 4 And tOVI.dwMinorVersion = 0 Then
WinVer = "95"
End If
End If
If Len(Trim$(WinVer)) = 0 Then
'OS tidak dikenali, kemungkinan module ini perlu diupdate jika ada OS yang baru
'atau kemungkinan fungsi API: GetVersionEX tidak dapat bekerja semestinya.
WinVer = "UN" ' Unknown
End If
End Function
'--- Batas coding di Module --- '--- Coding ini di Form --- 'Klik Command1 untuk menampilkan jenis Sistem Operasi yang digunakan
Private Sub Command1_Click()
Dim OSVersion As String
Select Case WinVer
Case "NT"
OSVersion = "Windows NT"
Case "00"
OSVersion = "Windows NT"
Case "XP"
OSVersion = "Windows XP"
Case "95"
OSVersion = "Windows 95"
Case "98"
OSVersion = "Windows 98"
Case "ME"
OSVersion = "Windows ME"
Case Else
OSVersion = "Unknown Version"
End Select
MsgBox "Sistem Operasi yang Anda gunakan: " & _
OSVersion, vbInformation, "Sistem Operasi"
End Sub
'--- Batas coding di Form --- |
0 komentar:
Posting Komentar