C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-29-2002, 04:50 AM   #1
joh
Registered User
 
Join Date: Oct 2002
Posts: 1
EXE Closing all instances of Internet explorer - How can it run in Win 95/98

Shown below is coding for a simple C++ application that closes Internet Explorer. This application works perfectly in Windows 2000, although when run in a Windows 95/98 environment, two error messages show and the EXE does not run at all.

These error messages are:

- 'The PSAPI.DLL file is linked to missing export NTDLL.DLL:NtAllocateVirtualMemory.'

- '{Directory path where this file is located}\closeexplorer.exe
A device attached to the system is not functioning.'


How can this coding be altered so that this Application can run in Windows 95/98 as well as Windows 2000?
Please can someone help!

================================================== ===========

Code:
// - Coding for the close IE/Netscape instances solution - ///////////////////////////////////////

#include "stdafx.h"
#include "psapi.h"
#pragma comment(lib,"psapi.lib")


char *g_sAppName;
boolean g_bVerbose;


boolean KillProcess( DWORD processID )
{
   char szProcessName[MAX_PATH] = "unknown";

   // Get a handle to the process.

   HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
   PROCESS_VM_READ | PROCESS_TERMINATE,
                                  FALSE, processID );
    boolean retval = false;

   // Get the process name.

   if ( hProcess )   {
       HMODULE hMod;
       DWORD cbNeeded;

       if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), 
            &cbNeeded) ) {
           GetModuleBaseName( hProcess, hMod, szProcessName, 
                              sizeof(szProcessName) );
       }
         // Print the process name and identifier.
//Need to 
// 

         _strlwr(szProcessName);
         if (!strcmp(szProcessName,"explorer.exe") ||
// Copy and paste the following line with anything else that needs killing
//			!strcmp(szProcessName,"netscape.exe") || // change whatever is in the quotes
         !strcmp(szProcessName,"iexplore.exe")) {

              TerminateProcess(hProcess,0);
         }

        CloseHandle( hProcess );
    }
    return retval;
}

int main()
{
   DWORD aProcesses[1024], cbNeeded, cProcesses;
   unsigned int i;

    int killCount=0;

   if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ))
       return 0;    // Get the list of process identifiers.

   // Calculate how many process identifiers were returned.
   cProcesses = cbNeeded / sizeof(DWORD);
   // Print the name and process identifier for each process.
   for ( i = 0; i < cProcesses; i++ )
       if (KillProcess( aProcesses[i] )) 
         {
              killCount++;
         }
    return killCount;
}

//Just add the Netscape module name and you have it!
joh is offline   Reply With Quote
Old 10-29-2002, 06:06 AM   #2
&TH of undefined behavior
 
Fordy's Avatar
 
Join Date: Aug 2001
Posts: 5,183
PSAPI.DLL is an extention to the API that allows you to manipulate processes....

Unfortunately, it doesnt work on Win98/95/ME...Only NT/2K/XP...

You can still call TermianteProcess to actually kill IE, but the methods you have for identifying Internet Explorer processes will not work....
__________________
"If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut."
Albert Einstein (1879 - 1955)


Board Rules
Fordy is offline   Reply With Quote
Old 10-29-2002, 04:56 PM   #3
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 4,923
Quote:
TermianteProcess
...your latin roots are really showing through!
Sebastiani is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run an exe command in c++ and get back the results? mitilkhatoon C++ Programming 5 09-21-2006 06:00 PM
How I can Run exe file in C++ palang C++ Programming 2 05-10-2006 11:55 AM
help with this tyrantil C Programming 18 01-30-2005 04:53 PM
FlashWindowEx not declared? Aidman Windows Programming 3 05-17-2003 02:58 AM
Error when I run an EXE file dirkduck C++ Programming 12 03-26-2002 03:05 PM


All times are GMT -6. The time now is 02:50 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22