Rendere un'applicazione
un servizio:
non far vedere l'applicazione nel task manager
Dichiarazioni: in un modulo:
Option Explicit
Public Declare Function
GetCurrentProcessId _
Lib "kernel32" () As Long
Public Declare Function GetCurrentProcess _
Lib "kernel32" () As Long
Public Declare Function RegisterServiceProcess _
Lib "kernel32" (ByVal dwProcessID As Long, _
ByVal dwType As Long) As Long
Public Const RSP_SIMPLE_SERVICE = 1
Public Const RSP_UNREGISTER_SERVICE = 0
Procedure:
Public Sub MakeMeService()
'Nasconde l'app nel Task Manager (la rende un servizio)
Dim pid As Long
Dim regserv As Long
pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
End Sub
Public Sub UnMakeMeService()
'Rimette l'app nel Task Manager
Dim pid As Long
Dim regserv As Long
pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, _
RSP_UNREGISTER_SERVICE)
End Sub
-------------------------------------------------
In un Form inserire 2 CommandButton:
Command1.Caption="&Scompare dal
Task"
Command2.Caption="&Riappare nel Task"
Inserire infine il seguente codice:
Option Explicit
Private Sub Command1_Click()
MakeMeService
End Sub
Private Sub Command2_Click()
UnMakeMeService
End Sub
Private Sub Form_Load()
MakeMeService
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnMakeMeService
End Sub
Non dimenticare di chiamare UnMakeMeService prima di chiudere l'applicazione
per liberare risorse di sistema!
Testato su: Windows 98, Windows Me