软件注册站
热情软件屋

 
如何使程序不出现在任务列表中
编号: QA000325    
建立日期: 1999年1月11日 最后修改日期: 2000年5月7日
所属类别: C/C++ - 其他方面

Visual Basic - 其他方面
   
    工具:VB5.0
    操作系统: win98
    怎样使 VB 编写的程序不被Ctrl+Alt+Del 拦截? 我的意思是 Ctrl+Alt+Del依然起作用,但不能发现该程序。(赵日成)
   
    我想你的意思是如何使程序不出现在任务列表中。如果你的程序是ActiveX Automation Server且没有窗体,可以将App.TaskVisible设为False。
    另外一个办法是将你的注册为服务(service),这可以利用RegisterService API函数(只能用于Windows 9x,无法用于Windows 2000/XP)将程序的进程ID进行注册来实现。但程序退出时不要忘记需要使用此API函数将服务器注册取消。下面举例说明。
    1)在窗体中加入两个按钮,Command1、Command2,在窗体的总体声明部分声明API函
    数、需要的常数并编写注册和释放注册的过程:
    Private Declare Function GetCurrentProcessId _
    Lib "kernel32" () As Long
    Private Declare Function GetCurrentProcess _
    Lib "kernel32" () As Long
    Private Declare Function RegisterServiceProcess _
    Lib "kernel32" (ByVal dwProcessID As Long, _
    ByVal dwType As Long) As Long
    Private Const RSP_SIMPLE_SERVICE = 1
    Private Const RSP_UNREGISTER_SERVICE = 0
    
    Private Sub MakeMeService()
     Dim pid As Long
     Dim reserv As Long
     pid = GetCurrentProcessId()
     regserv = RegisterServiceProcess (pid, RSP_SIMPLE_SERVICE)
    End Sub
    
    Private Sub UnMakeMeService()
     Dim pid As Long
     Dim reserv As Long
     pid = GetCurrentProcessId()
     regserv = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
    End Sub
    
    2)写如下代码:
    Private Sub Command1_Click()
     Call MakeMeService
    End Sub
    
    Private Sub Command2_Click()
     Call UnMakeMeService
    End Sub
    3)下面就可以运行了,运行此程序,单击按钮1,按下Ctrl-Alt-Del键,在列表中看不到你的程序了。再单击按钮2,就可以看到你的程序在列表中。
    
    jlmay问:
    上面的答案是用VB写的,希望提示一下用VC6.0如何使用!
    回答:
    下面是一个示例片段:
    #define RSP_SIMPLE_SERVICE 0x00000001 // 注册进程为简单服务
    #define RSP_UNREGISTER_SERVICE 0x00000000 // 反注册
    
     typedef DWORD (*RSPPROC)(DWORD, DWORD);
     RSPPROC RegisterServiceProcess;
    
     HANDLE g_hSvcDll = NULL;
     g_hSvcDll = LoadLibrary("kernel32.dll");
    
     if(!g_hSvcDll)
     {
     AfxMessageBox("加载DLL失败!");
     }
    
     RegisterServiceProcess =(RSPPROC)GetProcAddress(
     (HINSTANCE) g_hSvcDll, "RegisterServiceProcess");
    
     if(!RegisterServiceProcess)
     {
     FreeLibrary((HINSTANCE)g_hSvcDll);
     }
     else
     {
     if(!RegisterServiceProcess(GetCurrentProcessId(),
     RSP_SIMPLE_SERVICE))
     {
     AfxMessageBox("调用函数出错!");
     }
     }
    he_jm的意见:
    还有,以下这断代码也可以实现程序名的任务栏中隐藏。
    在你所编的程序前加上以下的代码:
    (VC++为例)
     在App类中有如下定义:
     DWORD m_nAppType
     DWORD m_nOffset
    
    在APP类的构造函数中加入
    DWORD nOffset;
    DWORD nAppType = 0x10800000;
    __asm{
    mov ebx,30h
    push es
    push fs
    pop es
    mov ebx,es:[ebx]
    mov nOffset,ebx
    pop es
    mov eax,nAppType
    xchg [ebx+20h],eax
    mov nAppType,eax
    }
    m_nOffset = nOffset;
    m_nAppType =nAppType;
    
    在程序结尾(ExitInstance)加上:
    DWORD nOffset;
    DWORD nAppType;
    
    nOffset = m_nOffset;
    nAppType = m_nAppType;
    
    __asm{
    push eax
    push ebx
    mov ebx,nOffset
    mov eax,nAppType
    xchg [ebx+20h],eax
    pop ebx
    pop eax
    }
    程序编译好后运行看一看CTRL+ALT+DEL中的窗口里面“有什么”。
    
    相关问题:
    QA002235 "在NT下运行RegisterServiceProcess失败"
    QA001581 "在Delphi中,怎么使程序不出现在任务列表中"

    

此问题由李海回答。

附加关键字:编程, 源程序, programming, source code, C/C++, MFC, C++ Builder, Borland C++, Turbo C, C, BCB, Visual Basic, VB, 其他方面,

   
 
把这个问题推荐给朋友
   
 
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio