本示例使用设备: https://item.taobao.com/item.htm?spm=a21dvs.23580594.0.0.52de2c1bWmhJZJ&ft=t&id=562957272162
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function sGetINI(strPath As String, strSection As String, strKey As String, strDefault As String) As String
Dim strV As String
Dim aa As Long
strV = " "
aa = GetPrivateProfileString(strSection, strKey, strDefault, strV, 255, strPath)
strV = Trim(strV)
strV = Left(strV, Len(strV) - 1)
sGetINI = strV
End Function
Public Sub writeINI(strPath As String, strSection As String, strKey As String, strValue As String)
WritePrivateProfileString strSection, strKey, strValue, strPath
End Sub
Private Sub Form_Initialize()
Dim i As Integer
Dim hwnd As Long
Dim TopWindow As Long
Dim hForeWnd As Long
Dim dwForeID As Long
Dim dwCurID As Long
Dim wParam As Long
Dim lParam As Long
Dim lResult As Long
Dim soundid As Integer
Me.Tag = -1
If App.PrevInstance Then
Me.Caption = ""
hwnd = FindWindow(vbNullString, "RFIDWebServer")
If hwnd > 0 Then
SendMessage hwnd, WM_SYSCOMMAND, SC_RESTORE, 0
SetForegroundWindow hwnd
TopWindow = GetLastActivePopup(hwnd)
Unload Me
Shell_NotifyIcon NIM_DELETE, tray '删除托盘图标
End
End If
End If
On Error Resume Next
txtPort.Text = Val(sGetINI(App.Path & "\SysConfig.ini", "DefaultSetup", "WebSocketPort", 39189))
Check3.value = Val(sGetINI(App.Path & "\SysConfig.ini", "DefaultSetup", "MinSystemEn", 0))
Check1.value = Val(sGetINI(App.Path & "\SysConfig.ini", "DefaultSetup", "ServerAutoRun", 0))
If sGetINI(App.Path & "\SysConfig.ini", "DefaultSetup", "DebugNetInf", "") = "https://www.icmcu.com" Then: DebugEn = True: Else: DebugEn = False:
End Sub
Private Sub Command1_Click()
Dim commstr As String
Dim delaystr As String
Dim runexefile As String
Dim Retustr
Dim delaym As Integer
runexefile = App.Path & "\RFIDWebServer.exe"
On Error Resume Next
commstr = "SCHTASKS /DELETE /TN RFIDWebServerAutoRun /F " '删除现有
Retustr = Shell(commstr, 0)
If Check1.value > 0 Then
commstr = "SCHTASKS /CREATE /SC MINUTE /MO 2 /TN RFIDWebServerAutoRun /TR " + runexefile '每2分钟运行一次
Retustr = Shell(commstr, 0)
writeINI App.Path & "\SysConfig.ini", "DefaultSetup", "ServerAutoRun", "1"
writeINI App.Path & "\SysConfig.ini", "DefaultSetup", "WebSocketPort", Trim(txtPort.Text)
writeINI App.Path & "\SysConfig.ini", "DefaultSetup", "MinSystemEn", Format(Check3.value, "0")
MsgBox "已设定开机时自动开启RFIDWebServer网页读写卡功能!", vbInformation + vbOKOnly, "提示"
Else
writeINI App.Path & "\SysConfig.ini", "DefaultSetup", "ServerAutoRun", "0"
MsgBox "已关闭开机自动开启RFIDWebServer网页读写卡功能!", vbInformation + vbOKOnly, "提示"
End If
End Sub