如何電腦名? ------------------------------------------------------------ Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongFunction getname() As String Dim l1 As String Dim l2 As Long Dim l3 As Long
l2 = 255 l1 = String$(l2, " ") l3 = GetComputerName(l1, l2) getname = "" If l3 <> 0 Then getname = Left(l1, l2) End If Me.Label2 = getname
End FunctionPrivate Sub Command1_Click() End End Sub Private Sub Form_Load() Dim i i = getname End Sub-----------------------------------------------------
判断有无软盘:Dim fso As New FileSystemObject Dim dr As Drive Set dr = fso.GetDrive("a:") If dr.IsReady Then else msgbox Drive A: has no floppy in it!" end if引用scripting runtime
如何知道軟驅(A:)是否有磁盤? Dim fsl As New FileSystemObject Private Sub Form_Load() If fsl.Drives.Item("A").IsReady Then MsgBox "软驱内有磁盘" Else MsgBox "软驱内无磁盘" End If End Sub
gump2000(阿甘) 的答案很标准!
取得Computer Name, OS的版本
Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 ' Maintenance string for PSS usage End TypePrivate Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _ (lpVersionInformation As OSVERSIONINFO) As Long Private Declare Function GetComputerName Lib "kernel32" Alias _ "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongPrivate Sub Command1_Click() Dim len5 As Long, aa As Long Dim cmprName As String Dim osver As OSVERSIONINFO'取得Computer Name cmprName = String(255, 0) len5 = 256 aa = GetComputerName(cmprName, len5) cmprName = Left(cmprName, InStr(1, cmprName, Chr(0)) - 1) Debug.Print "Computer Name = "; cmprName'取得OS的版本 osver.dwOSVersionInfoSize = Len(osver) aa = GetVersionEx(osver) Debug.Print "MajorVersion "; osver.dwMajorVersion Debug.Print "MinorVersion "; osver.dwMinorVersion Select Case osver.dwPlatformId Case 0 Debug.Print "Window 3.1" Case 1 Debug.Print "Win95" Case 2 Debug.Print "WinNT" End Select End Sub
------------------------------------------------------------
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongFunction getname() As String
Dim l1 As String
Dim l2 As Long
Dim l3 As Long
l2 = 255
l1 = String$(l2, " ")
l3 = GetComputerName(l1, l2)
getname = ""
If l3 <> 0 Then
getname = Left(l1, l2)
End If
Me.Label2 = getname
End FunctionPrivate Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
Dim i
i = getname
End Sub-----------------------------------------------------
Dim dr As Drive Set dr = fso.GetDrive("a:")
If dr.IsReady Then
else
msgbox Drive A: has no floppy in it!"
end if引用scripting runtime
Dim fsl As New FileSystemObject
Private Sub Form_Load()
If fsl.Drives.Item("A").IsReady Then
MsgBox "软驱内有磁盘"
Else
MsgBox "软驱内无磁盘"
End If
End Sub
取得Computer Name, OS的版本
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End TypePrivate Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongPrivate Sub Command1_Click()
Dim len5 As Long, aa As Long
Dim cmprName As String
Dim osver As OSVERSIONINFO'取得Computer Name
cmprName = String(255, 0)
len5 = 256
aa = GetComputerName(cmprName, len5)
cmprName = Left(cmprName, InStr(1, cmprName, Chr(0)) - 1)
Debug.Print "Computer Name = "; cmprName'取得OS的版本
osver.dwOSVersionInfoSize = Len(osver)
aa = GetVersionEx(osver)
Debug.Print "MajorVersion "; osver.dwMajorVersion
Debug.Print "MinorVersion "; osver.dwMinorVersion
Select Case osver.dwPlatformId
Case 0
Debug.Print "Window 3.1"
Case 1
Debug.Print "Win95"
Case 2
Debug.Print "WinNT"
End Select
End Sub