本帖最后由 qqLiSi 于 2013-04-01 00:13:05 编辑

解决方案 »

  1.   

    To set the default credentials for an all-user connection, set the RASCM_DefaultCreds flag in the dwMask member of the RASCREDENTIALS structure pointed to by the lpCredentials parameter. If you attempt to set default credentials for a per-user connection, RasSetCredentials returns ERROR_ACCESS_DENIED. 好好看看上面的这段话,就是说不要设置dwMask的值中有RASCM_DefaultCreds(8)就可以了
      

  2.   

     Dim rc As New RASCREDENTIALS
            With rc
                ReDim .szPassword(256)
                ReDim .szUserName(256)
                ReDim .szDomain(15)
                .dwSize = Marshal.SizeOf(rc)
                .dwMask = 3;//修改这里
     
                Dim bSrc(100) As Byte
                bSrc = System.Text.Encoding.ASCII.GetBytes(sUsername)
                Dim cbCopy As Integer = sUsername.Length()
                CopyMemory(.szUserName, bSrc, cbCopy)
                bSrc = System.Text.Encoding.ASCII.GetBytes(sPassword)
                cbCopy = sPassword.Length()
                CopyMemory(.szPassword, bSrc, cbCopy)
            End With