- 精华
- 活跃值
-
- 积分
- 4448
- 违规
-
- 印币
-
- 鲜花值
-
- 在线时间
- 小时
累计签到:842 天 连续签到:14 天
|
发表于 2025-10-7 12:34:13
|
显示全部楼层
我可能搞错了,是取消了连接服务功能,只启动RMBG_Service.exe文件。
' ===== 新增函数:通过进程名检查服务是否运行 =====
Private Function IsServiceRunning() As Boolean
On Error Resume Next
Dim wmiService As Object
Dim processes As Object
Dim process As Object
Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
Set processes = wmiService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & SERVICE_EXE_NAME & "'")
IsServiceRunning = (processes.count > 0)
Set processes = Nothing
Set wmiService = Nothing
End Function
' ===== 修改后的服务检查函数 =====
Private Sub CheckAndStartService()
Dim fso As Object
Dim exePathh As String
Dim currentPathh As String
Dim workingDirh As String
currentPathh = Application.GMSManager.UserGMSPath
workingDirh = currentPathh & "orc\kt"
exePathh = workingDirh & "\RMBG_Service.exe"
Set fso = CreateObject("Scripting.FileSystemObject")
' 通过进程名检查服务是否运行
If IsServiceRunning() Then
Label7.Caption = "服务已运行,请选择图片操作。"
Else
Label7.Caption = "后台服务未运行,正在尝试启动..."
DoEvents
If fso.FileExists(exePathh) Then
Shell exePathh, vbMinimizedNoFocus
Label7.Caption = "服务启动中,请稍候..."
DoEvents
Sleep 3000
If IsServiceRunning() Then
Label7.Caption = "服务已启动,请选择图片操作。"
Else
Label7.Caption = "服务启动失败,请手动运行程序。"
MsgBox "无法启动后台服务!请检查文件是否存在:" & vbCrLf & exePathh, vbCritical, "服务错误"
End If
Else
Label7.Caption = "错误:找不到服务程序 " & exePathh
MsgBox "找不到后台服务程序!请确保文件位于:" & vbCrLf & exePathh, vbCritical, "文件丢失"
End If
End If
Set fso = Nothing
End Sub |
|