请问,如何用nas的名字登录?而不是IP,谢谢!
我有个 nas , 以前我是通过 IP 连接并读取内容,代码如下:Shell Environ("comspec") & " /c net use " & IPadssAndDir & "ipc$ ""xxx"" /user:""xxx""", vbHide
但后来,根据需要,会时常改变 nas 的 IP 位置,就不得不经常修改代码,
请问,能否用该 nas 的名字连接?而不是IP,或者有什么其它方法解决这个问题?谢谢!
Option Explicit Private Type WSADATA wversion As Integer wHighVersion As Integer szDescription(0 To 256) As Byte szSystemStatus(0 To 128) As Byte iMaxSockets As Integer iMaxUdpDg As Integer lpszVendorInfo As Long End Type Private Type HOSTENT hName As Long hAliases As Long hAddrType As Integer hLen As Integer hAddrList As Long End Type Private Const WS_VERSION_REQD = &H101 Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long) Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal szHostname As String) As Long Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Integer, lpWSAData As WSADATA) As Long Private Sub Command1_Click() Dim i As Integer Dim sIPAddr As String Dim HOST As HOSTENT Dim lpHost As Long Dim dwIPAddr As Long Dim tmpIPAddr() As Byte Dim udtWSAD As WSADATA Call WSAStartup(WS_VERSION_REQD, udtWSAD) lpHost = gethostbyname("www.baidu.com") CopyMemory HOST, lpHost, Len(HOST) CopyMemory dwIPAddr, HOST.hAddrList, 4 ReDim tmpIPAddr(1 To HOST.hLen) CopyMemory tmpIPAddr(1), dwIPAddr, HOST.hLen For i = 1 To HOST.hLen sIPAddr = sIPAddr & tmpIPAddr(i) & "." Next Form1.Caption = Mid$(sIPAddr, 1, Len(sIPAddr) - 1) End Sub你可以用上述代码测试.