DSAPI 网页获取本地程序登陆用户

时间:2023-03-08 22:15:38

这是一个非常简单的示例,在网页或其他平台获取程序中已经登陆的用户,当然也可以是其他信息。

DSAPI 网页获取本地程序登陆用户

源码

Imports DSAPI.网络.HTTP监听_DSWebAPI

Public Class Form1
Private WithEvents SV As New DSAPI.网络.HTTP监听_DSWebAPI With {.绑定端口 = 83, .自定义首页文件路径 = ""}
Private USERNAME As String = ""
Private PASSWORD As String = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SV.启动监听()
End Sub Private Sub SV_收到客户端请求(客户端 As DSAPI.网络.HTTP监听_DSWebAPI.WebAPI客户端, 键值列表 As DSAPI.网络.HTTP监听_DSWebAPI.键值列表, ByRef 返回信息 As String, ByRef 返回数据() As Byte) Handles SV.收到客户端请求
If 键值列表 Is Nothing OrElse 键值列表.Count = 0 Then Exit Sub
Dim 键值 As 键值 = 键值列表("user")
If 键值 Is Nothing Then 返回信息 = "No" : Exit Sub '或返回一个登陆页面
If USERNAME.Length = 0 Then
返回信息 = "当前没有用户登陆"
Else
返回信息 = String.Concat("当前已登陆用户:", USERNAME)
End If
End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
USERNAME = TextBox1.Text
PASSWORD = TextBox2.Text
End Sub
End Class