Solved

Ctrl-Alt-Delete: The Close Program Box

Posted on 1998-12-16
9
146 Views
Last Modified: 2013-11-20
I'm attempting to prevent my application's name from being seen in the close program box

I've added the following code in the proper sections that contains the InitInstance function.

  #define REGISTER 0
  #define UNREGISTER 1

to the top of your main source code file (the one with the InitInstance function in it).  Then add:

  typedef DWORD (WINAPI *fp_RegServProc) (DWORD, DWORD);
  fp_RegServProc pRegisterServiceProcess = NULL;

  pRegisterServiceProcess = (fp_RegServProc) GetProcAddress (GetModuleHandle ("KERNEL32.dll"), "RegisterServiceProcess");

  (pRegisterServiceProcess)(0, UNREGISTER);

to your InitInstance member function.  

Yet it doesn't work.
What have I done wrong????
0
Comment
Question by:lynn402
  • 4
  • 4
9 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
The problem is simply the way to obtain the DLL module handle. Change the code to read
HANDLE hDll = LoadLibrary ( "kernel32.dll");

  pRegisterServiceProcess = (fp_RegServProc) GetProcAddress (hDll, "RegisterServiceProcess");

  (pRegisterServiceProcess)(GetCurrentProcessId(), UNREGISTER);

BTW: the correct operation codes for this function:

// from http://support.microsoft.com/support/kb/articles/q125/7/14.asp,
// How to Start an Application at Boot Time Under Windows 95
// Last reviewed: September 25, 1995
// Article ID: Q125714

// Define                    Value       Meaning
#define RSP_SIMPLE_SERVICE        0x00000001      // Registers the process as a
                                                                        // simple service process.
#define RSP_UNREGISTER_SERVICE    0x00000000      // Unregisters the process as a
                                                                        // service process.

0
 

Author Comment

by:lynn402
Comment Utility
Now when I compile my program I get a spawning error --"error spawning c1.exe"
0
 

Author Comment

by:lynn402
Comment Utility
CORRECTION: the error I'm getting is c2664: cannot convert param 1 from 'void *' to 'struct HINSTANCE__*'
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Check your include path!!! This error usually occurs when outdated (Win16!) header files are involved (formerly, 'LoadLibrary()' indeed returned a 'struct HINSTANCE', whereas it returns 'void*' nowadays...). Here some code that compiles AND works:

typedef DWORD ( *RSPPROC)   (   DWORD,  DWORD);

RSPPROC RegisterServiceProcess;


            g_hSvcDll   =   LoadLibrary (   "kernel32.dll");

            if  (   !g_hSvcDll)
                {
                    // error
                }

            RegisterServiceProcess  =   ( RSPPROC)  GetProcAddress  (   g_hSvcDll,
                                                                        "RegisterServiceProcess"
                                                                    );

            if  (   !RegisterServiceProcess)
                {
                    FreeLibrary (   g_hSvcDll);
                }
             else
                {
                    if  (   !RegisterServiceProcess (   GetCurrentProcessId (),
                                                        RSP_SIMPLE_SERVICE
                                                    )
                        )
                        {
                            // error
                        }
                }

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 23

Expert Comment

by:chensu
Comment Utility
GetModuleHandle is OK.

The following code should work.

// Registers the process as a simple service process.
#define RSP_SIMPLE_SERVICE        0x00000001
// Unregisters the process as a service process.
#define RSP_UNREGISTER_SERVICE    0x00000000
// ...
 typedef DWORD (WINAPI *fp_RegServProc)(DWORD dwProcessId,DWORD dwType);
 fp_RegServProc fncptr=NULL;
// ...
HMODULE hModule = ::GetModuleHandle(TEXT("kernel32.dll"));
fncptr=(fp_RegServProc)::GetProcAddress(hModule, "RegisterServiceProcess");
if (fncptr!=NULL)
    (*fncptr)(0, RSP_SIMPLE_SERVICE);

0
 

Author Comment

by:lynn402
Comment Utility
It's working now.Thanks, JKR
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Fine! Do you think i may lock the Q?
0
 

Author Comment

by:lynn402
Comment Utility
Yes. Lock the question. It seems that expert exchange isn't presenting me with the options of whether to accept or refuse a person's solution.


0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
Comment Utility
Thanks! ;-)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 99
withoutTen challenge 14 87
Detect file exist or not 3 74
Problem to event 3 47
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now