例如:服务器的名称:dbserver
              ip:192.168.0.3
      该服务器有权限控制
      访问服务器的用户名:user
                  密码:123456
      该用户可以读写服务器D:\share目录我想用vb程序里现实将本机的文件file1复制到局域网内服务器D:\share目录下。
使用程序的用户并不知道访问服务器的用户名和密码,用户名和密码写在程序中。

解决方案 »

  1.   

    楼上的大虾
    服务器上的D:\share文件夹已经是共享的
      

  2.   

    shell "cmd /c net use \\servername  password /user:username",vbhideor API的方法
    ================
    把下面代码放到module中
    Option Explicit
        Const WN_Success = &H0
        Const WN_Not_Supported = &H1
        Const WN_Net_Error = &H2
        Const WN_Bad_Pointer = &H4
        Const WN_Bad_NetName = &H32
        Const WN_Bad_Password = &H6
        Const WN_Bad_Localname = &H33
        Const WN_Access_Denied = &H7
        Const WN_Out_Of_Memory = &HB
        Const WN_Already_Connected = &H34
        Public ErrorNum As Long
        Public ErrorMsg As String
        Public rc As Long
        Private Const ERROR_NO_CONNECTION = 8
        Private Const ERROR_NO_DISCONNECT = 9
        Private Type NETRESOURCE
        dwScope As Long
        dwType As Long
        dwDisplayType As Long
        dwUsage As Long
        lpLocalName As String
        lpRemoteName As String
        lpComment As String
        lpProvider As String
        End Type
        Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
        Const NO_ERROR = 0
        Const CONNECT_UPDATE_PROFILE = &H1
        Const RESOURCETYPE_DISK = &H1
        Const RESOURCETYPE_PRINT = &H2
        Const RESOURCETYPE_ANY = &H0
        Const RESOURCE_GLOBALNET = &H2
        Const RESOURCEDISPLAYTYPE_SHARE = &H3
        Const RESOURCEUSAGE_CONNECTABLE = &H1    Public Function ConnectUserPassword(sDrive As String, sService As String, Optional sUser As String = "", Optional sPassword As String = "") As Boolean
        Dim NETR As NETRESOURCE
        Dim errInfo As Long
        With NETR
        .dwScope = RESOURCE_GLOBALNET
        .dwType = RESOURCETYPE_DISK
        .dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
        .dwUsage = RESOURCEUSAGE_CONNECTABLE
        .lpRemoteName = sDrive
        .lpLocalName = sService
        End With
        errInfo = WNetAddConnection2(NETR, sPassword, sUser, CONNECT_UPDATE_PROFILE)
        ConnectUserPassword = errInfo = NO_ERROR
        End Function
    使用时 调用ConnectUserPassword即可
    call ConnectUserPassword("\\servername", "", "password", "username")
      

  3.   

    http://community.csdn.net/Expert/topic/3385/3385727.xml?temp=.1115839
      

  4.   


    请问楼上的大虾,ConnectUserPassword的参数如何设定?