怎么让vb程序在进程中隐藏

怎么让vb程序在进程中隐藏

在进程中隐藏的
Public Declare Function GetCurrentProcessId 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

下面代码为隐藏

Public Sub MakeMeService()
Dim pid As Long
Dim reserv As Long
pid = GetCurrentProcessId() '取的当前运行的程序Id

regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
对当前的程序传入 RSP_SIMPLE_SERVICE 消息,使此程序
从任务列表中隐藏
End Sub

'恢复隐藏
Public Sub UnMakeMeService()
Dim pid As Long
Dim reserv As Long
pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
原理同上
End Sub

Private Sub Command1_Click()
Call MakeMeService
End Sub

Private Sub Command2_Click()
Call UnMakeMeService
End Sub

Private Sub Form_Load()
Form1.Left = Screen.Width / 2 - Form1.Width / 2
Form1.Top = Screen.Height / 2 - Form1.Height / 2
End Sub

开机自动启动
'使用下面这三个API与两个常数(标记部份为快捷键方式增加到开始下的启动)
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
Private Sub Command1_Click()
Dim Ret2 As Long
'打开 HKEY_LOCAL_MACHINE 下的 software\microsoft\windows\currentVersion\run
RegCreateKey HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentVersion\run", Ret2
'将此主键下的 "默认" 值改为你的 exe 全路径"
RegSetValue Ret2, vbNullString, REG_SZ, "c:\windows\abc.exe", 4
'关闭对主键的操作
RegCloseKey Ret2
End Sub
窗口总是在最前面
Option Explicit

'【VB声明】
' Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long _
) As Long
Const HWND_TOPMOST = -1
Const SWP_SHOWWINDOW = &H40
Private Sub Form_load()
Dim retValue As Long
'将窗体设置为处于所有窗口的顶层,注意在 VB 中运行时,
’可能不行,但编译成EXE后就可以了
retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX,
Me.CurrentY, 300, 300, SWP_SHOWWINDOW)
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-11-29
vb程序隐藏??指的是整个图形用户界面、整个窗体吗??如果是的话 可以通过hide方法来实现
给窗体加上该方法 即 form1.hide 即可隐藏该窗体