Click to See Complete Forum and Search --> : system processes for VB apps


January 25th, 2000, 08:41 AM
In Visual Basic how would one hide the application process from showing and not show up in the process list when you do a Ctrl+Alt+Del?

Chris Eastwood
January 25th, 2000, 09:21 AM
Here's some code I picked up a while back

This ones for Windows 95/98 - I can't test it here as I'm running NT4:


'
' In a form / module - change public to private as appropriate
'
' ServiceFlags: 0 means unregister as a service, 1 means to register.
'
public Declare Function RegisterServiceProcess Lib "kernel32" _
(byval ProcessID as Long, byval ServiceFlags as Long) as Long
'
public Declare Function GetCurrentProcessId Lib "kernel32" () as Long
'
'
public Sub HideApp()
'When you register the service process it becomes hidden.
ret = RegisterServiceProcess (GetCurrentProcessId, 1)
End Sub
'
public Sub ShowApp
'And the unhidden when you unregister it when you're
'finished with hiding it.
'
ret = RegisterServiceProcess (GetCurrentProcessId, 0)
End Sub




The code for NT is slightly easier (again in a module / form depending on how you want to use it ):


option Explicit
'
public Declare Function GetWindow Lib "user32" (byval hwnd as Long, byval wCmd as Long) as Long
public Declare Function ShowWindow Lib "user32" (byval hwnd as Long, byval nCmdShow as Long) as Long
public Const GW_OWNER = 4
public Const SW_HIDE = 0
public Const SW_SHOW = 5
'
'
public Sub HideApp(byval mainFrmHwnd as Long)
'Hide the app from the task manager.
'
Dim lRtn as Long
'
lRtn = GetWindow(mainFrmHwnd, GW_OWNER)
lRtn = ShowWindow(lRtn, SW_HIDE)
End Sub
'
public Sub ShowApp(byval mainFrmHwnd as Long)
'Show the app from the task manager.
'
Dim lRtn as Long
'
lRtn = GetWindow(mainFrmHwnd, GW_OWNER)
lRtn = ShowWindow(lRtn, SW_SHOW)
End Sub




Call the above with the 'hwnd' of your main form (eg. HideApp frmMain.hwnd)



Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb