|
-
December 2nd, 1999, 10:52 AM
#1
Shell
Can anyone help me in getting the computer name??
I have placed the code below. Please go thru it and tell me the mistake. THank you
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Private Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Public Enum ShFolder
fldrPrograms = &H2
fldrControls = &H3
fldrPrinters = &H4
fldrPersonal = &H5
fldrFavorites = &H6
fldrStartup = &H7
fldrRecent = &H8
fldrSendTo = &H9
fldrBitBucket = &HA
fldrStartMenu = &HB
fldrDeskTopDir = &H10
fldrDrives = &H11
fldrNetWork = &H12
fldrNetHood = &H13
fldrFonts = &H14
fldrTemplates = &H15
fldrCommonStartMenu = &H16
fldrCommonPrograms = &H17
fldrCommonStartup = &H18
fldrCommonDeskTopDir = &H19
fldrCommonAppData = &H1A
End Enum
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const BIF_BROWSEFORCOMPUTER = 4096
Private Const MAX_PATH = 260
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Sub Command1_Click()
Dim IDL As ITEMIDLIST
Dim lpIDList As Long
Dim sBuffer As String * 255
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo
Dim Path As String * 255
lret = SHGetSpecialFolderLocation(0, fldrNetWork, IDL)
szTitle = "Select new server"
With tBrowseInfo
.hwndOwner = Me.hWnd
.pIDLRoot = IDL.mkid.cb
.lpszTitle = lstrcat(szTitle, "")
.ulFlags = BIF_BROWSEFORCOMPUTER
.pszDisplayName = StrPtr(Path)
End With
lpIDList = SHBrowseForFolder(tBrowseInfo)
If (lpIDList) Then
sBuffer = Space(MAX_PATH)
lret = SHGetPathFromIDList(lpIDList, sBuffer)
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
MsgBox sBuffer & Path
End If
End Sub
-
December 2nd, 1999, 01:52 PM
#2
Re: Shell
Try this:
private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (byval lpBuffer as string, nSize as Long) as Long
'--------Put this on any event
Dim lRet as Long
Dim strComputerName as string
strComputerName = Space(125)
lRet = GetComputerName(strComputerName, len(strComputerName))
If lRet then strComputerName = Left(strComputerName, InStr(strComputerName, vbNullChar) - 1)
strComputerName now holds the name of the computer
Serge
Software Developer
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|