RasSetCredentials(vbNullString, sEntryName, rc, 0)返回为5求解决
--------------------编程问答-------------------- 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)就可以了 --------------------编程问答-------------------- 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
补充:VB , API