同志们有福了,这个安装器可以实现自动装载卸载服务,可以直接通过服务找到进程进行终止服务,其中包含一段稀有代码,找遍百度和google都难寻到的通过服务分析可执行文件路径
完整源码传送门
稀有代码
Private Function 获取服务的可执行文件路径(serviceName As String) As String
Dim hSCManager = OpenSCManager(Nothing, Nothing, SC_MANAGER_ALL_ACCESS)
If (hSCManager <> 0) Then
Dim hService = OpenService(hSCManager, serviceName, SERVICE_QUERY_CONFIG)
If (hService <> 0) Then
Dim dwBytesNeeded = 0
QueryServiceConfig(hService, Nothing, 0, dwBytesNeeded)
Dim errint = GetLastError()
If errint = 122 Then
Dim ptr = Marshal.AllocHGlobal(dwBytesNeeded)
Dim isok = QueryServiceConfig_1(hService, ptr, dwBytesNeeded, dwBytesNeeded)
Dim ServiceConfig As QUERY_SERVICE_CONFIG = Marshal.PtrToStructure(ptr, GetType(QUERY_SERVICE_CONFIG))
CloseServiceHandle(hSCManager)
CloseServiceHandle(hService)
Marshal.FreeHGlobal(ptr)
Return ServiceConfig.lpBinaryPathName
Else
Return "未知1"
End If
End If
Else
Return "未知2"
End If
End Function