当前位置: 首页 > news >正文

VB读写ini配置文件将运行文件放入任务计划程序设置为开机自启动

本示例使用设备: 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 LongPublic Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As LongPublic Function sGetINI(strPath As String, strSection As String, strKey As String, strDefault As String) As StringDim strV As StringDim aa As LongstrV = "                                                                                                                                                                                                                                 "aa = GetPrivateProfileString(strSection, strKey, strDefault, strV, 255, strPath)strV = Trim(strV)strV = Left(strV, Len(strV) - 1)sGetINI = strV
End FunctionPublic Sub writeINI(strPath As String, strSection As String, strKey As String, strValue As String)WritePrivateProfileString strSection, strKey, strValue, strPath
End SubPrivate 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 IntegerMe.Tag = -1If App.PrevInstance ThenMe.Caption = ""        hwnd = FindWindow(vbNullString, "RFIDWebServer")        If hwnd > 0 ThenSendMessage hwnd, WM_SYSCOMMAND, SC_RESTORE, 0SetForegroundWindow hwnd        TopWindow = GetLastActivePopup(hwnd)        Unload MeShell_NotifyIcon NIM_DELETE, tray   '删除托盘图标EndEnd IfEnd IfOn 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 SubPrivate Sub Command1_Click()
Dim commstr As String
Dim delaystr As String
Dim runexefile As String
Dim Retustr
Dim delaym As Integerrunexefile = App.Path & "\RFIDWebServer.exe"
On Error Resume Nextcommstr = "SCHTASKS /DELETE /TN RFIDWebServerAutoRun /F "        '删除现有
Retustr = Shell(commstr, 0)If Check1.value > 0 Thencommstr = "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, "提示"
ElsewriteINI App.Path & "\SysConfig.ini", "DefaultSetup", "ServerAutoRun", "0"MsgBox "已关闭开机自动开启RFIDWebServer网页读写卡功能!", vbInformation + vbOKOnly, "提示"
End IfEnd Sub

http://www.lryc.cn/news/525094.html

相关文章:

  • Java基础 (一)
  • 数据结构——实验六·散列表
  • springboot网上书城
  • 如何在 Pytest 中使用命令行界面和标记运行测试
  • 不建模,无代码,如何构建一个3D虚拟展厅?
  • github汉化
  • Unity Line Renderer Component入门
  • 数据库的三级模式结构与两级映像
  • TCP断开通信前的四次挥手(为啥不是三次?)
  • win32汇编环境,按字节、双字等复制字符的操作
  • .net 项目引用与 .NET Framework 项目引用之间的区别和相同
  • RabbitMQ--延迟队列
  • 使用pyboard、micropython和tja1050进行can通信
  • JS学习之JavaScript模块化规范进化论
  • 亚博microros小车-原生ubuntu支持系列:7-脸部检测
  • 第二届国赛铁三wp
  • 缓存商品、购物车(day07)
  • 4【编程语言的鄙视链原因解析】
  • 美团一面面经
  • 什么是报文的大端和小端,有没有什么记忆口诀?
  • Spring中BeanFactory和ApplicationContext的区别
  • 期货行业专题|基于超融合实现 IT 基础设施现代化与国产化转型实践合集
  • AI新玩法:Flux.1图像生成结合内网穿透远程生图的解决方案
  • Jenkins-pipeline Jenkinsfile说明
  • vue3中为什么引入setup,引入setup是为了解决什么问题,setup的执行时机是什么?返回值是什么
  • Ubuntu 安装 docker 配置环境及其常用命令
  • 自动化01
  • 音频入门(二):音频数据增强
  • MySQL管理事务处理
  • MySQL数值型函数详解