怎樣用API:GetcomputerName
怎樣用API:GetcomputerName。
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
问题点数:0、回复次数:4Top
1 楼rainstormmaster(暴风雨 v2.0)回复于 2003-11-03 13:15:36 得分 0
Option Explicit
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
Dim strString As String
'Create a buffer
strString = String(255, Chr$(0))
'Get the computer name
GetComputerName strString, 255
'remove the unnecessary chr$(0)'s
strString = Left$(strString, InStr(1, strString, Chr$(0)))
'Show the computer name
MsgBox strString
End Sub
Top
2 楼ALIWEN(I CAN DO)回复于 2003-11-03 13:55:26 得分 0
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'取计算机名
'##ModelId=3C3C32920026
Private Function GetLogonComputerName() As String
Dim nRet As Long
Dim lpBuffer As String
Dim nSize As Long
'get computer name
nSize = 60
lpBuffer = String(nSize + 1, 0)
nRet = GetComputerName(lpBuffer, nSize)
lpBuffer = left(lpBuffer, nSize)
GetLogonComputerName = lpBuffer
End Function
'try .....Top
3 楼haikvlxiong(haikvlxiong)回复于 2003-11-22 22:14:00 得分 0
TKS!Top
4 楼online(龙卷风V4.0--决战江湖(MS MVP-VB))回复于 2003-11-23 04:12:28 得分 0
Private Sub Form_Load()
TxtValue.text = WorkstationID()
End Sub
Public Function WorkstationID() As String
Dim sBuffer As String * 255
If GetComputerNameA(sBuffer, 255&) > 0 Then
WorkstationID = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
Else
WorkstationID = "?"
End If
End FunctionTop




