www.pudn.com > Ó²ÅÌµÄ¼à¿Ø.rar > UNINST.C


/*++ 
 
Copyright (c) 1999  Microsoft Corporation 
 
Module Name: 
 
   uninstall.c 
 
Abstract: 
 
   This is the main module to uninstall the filespy. 
 
Environment: 
 
   User Mode Only 
 
Revision History: 
 
--*/ 
 
#include  
#include  
#include  
#include "fspyServ.h" 
 
VOID 
DisplayError( 
   DWORD Code 
   ) ; 
 
 
void __cdecl main (argc, argv) 
   int argc; 
   char *argv[]; 
 
/*++ 
 
Routine Description: 
 
   This is the program entry point and main processing routine for the 
   installation console mode application. It will be responsible for 
   installing the file system filter driver into the registry and preparing 
   the system for a reboot. 
 
Arguments: 
 
   argc - The count of arguments passed into the command line. 
 
   argv - Array of arguments passed into the command line. 
 
Return Value: 
 
   None. 
 
--*/ 
 
{ 
    SC_HANDLE serviceControlManager = NULL ; 
    SC_HANDLE filespyService = NULL ; 
    DWORD errorCode ; 
     
    // 
    // Begin by displaying an introduction message to the user to let them 
    // know that the application has started. 
    // 
     
    printf("\nFileSpy.sys Simple Uninstallation Aid\n") ; 
    printf("Copyright (c) 1999  Microsoft Corporation\n") ; 
    printf("\n\n") ; 
     
    // 
    // Obtain a handle to the service control manager requesting all access 
    // 
     
    serviceControlManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 
     
    // 
    // Verify that a handle could be obtained. 
    // 
     
    if (!serviceControlManager) { 
         
        // 
        // A handle could not be obtained. Get the error code and display a 
        // useful message to the user. 
        // 
         
        errorCode = GetLastError() ; 
        printf("The Service Control Manager could not be opened.\n") ; 
        DisplayError (errorCode) ; 
        goto Main_Exit; 
    } 
     
    // 
    // Open the FileSpy service so that we can delete it 
    // 
    filespyService = OpenService(serviceControlManager, 
               FILESPY_SERVICE_NAME, 
               FILESPY_SERVICE_ACCESS); 
    if (!filespyService) { 
        errorCode = GetLastError(); 
        printf("The FileSpy Service could not be opened.\n"); 
        DisplayError (errorCode); 
        goto Main_Exit; 
    } 
     
    // 
    // Try to delete the service 
    // 
    if (!DeleteService(filespyService)) { 
        errorCode = GetLastError(); 
        printf("The FileSpy Service could not be deleted.\n"); 
        DisplayError (errorCode); 
        goto Main_Exit; 
    } 
     
    // 
    // Display a message indicating that the driver has successfully been 
    // uninstalled and the system should be shut down. 
    // 
     
    printf("Driver successfully uninstalled.\n\n") ; 
    printf("For the driver removal to take effect, " 
           "the system must now be restarted.\n") ; 
    printf("Please restart the system after closing " 
           "all applications and saving all data\n") ; 
 
Main_Exit: 
    if (filespyService) { 
        CloseServiceHandle (filespyService) ; 
    } 
    if (serviceControlManager) { 
        CloseServiceHandle (serviceControlManager) ; 
    } 
} 
 
 
VOID 
DisplayError ( 
   DWORD Code 
   ) 
 
/*++ 
 
Routine Description: 
 
   This routine will display an error message based off of the Win32 error 
   code that is passed in. This allows the user to see an understandable 
   error message instead of just the code. 
 
Arguments: 
 
   Code - The error code to be translated. 
 
Return Value: 
 
   None. 
 
--*/ 
 
{ 
   WCHAR                                    buffer[80] ; 
   DWORD                                    count ; 
 
   // 
   // Translate the Win32 error code into a useful message. 
   // 
 
   count = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 
                          NULL, 
                          Code, 
                          0, 
                          buffer, 
                          sizeof (buffer), 
                          NULL) ; 
 
   // 
   // Make sure that the message could be translated. 
   // 
 
   if (count == 0) { 
 
      printf("\nError could not be translated.\n Code: %d\n", Code) ; 
      return; 
   } 
   else { 
 
      // 
      // Display the translated error. 
      // 
 
      printf("%S\n", buffer) ; 
      return; 
   } 
}