home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 21
/
macformat_21.iso
/
Shareware
/
Programación
/
VideoToolbox
/
VideoToolboxSources
/
KillEveryoneButMe.c
< prev
next >
Wrap
Text File
|
1995-06-22
|
4KB
|
122 lines
/*
KillEveryoneButMe.c
Quits every other application on your machine, including the Finder (and FileSharing).
Requires at least System 7, otherwise returns 1 and does nothing.
This may be appropriate for an application that will hog the entire machine anyway,
in order to maximize the available memory and minimize the time lost to other
processes.
"Some folks want to kill all the other applications running on a machine for
demos, school situations, kiosks, etc. With System 7 it's easy. Just use the
Process Manager and AppleEvents. This thing shows you how.
"PLEASE don't abuse this. System 7 gives the user full-time multiFinder, and they
like it, our System Software team worked very hard to make this happen. ONLY do
this in very special circumstances, or you're taking power away from the user and
tweaking the strength of the Mac.
"Written by C.K. Haun <TR>, Apple Developer Tech Support
"BUG FIX, if only this app and the Finder were running, it didn't do anything. Oops
"Of course, Copyright 1991-1992, Apple Computer Inc."
C.K.HAUN@applelink.apple.com
NOTE:
It is essential that the isHighLevelEventAware bit be set in your application's
SIZE resource, otherwise all your attempts to emit AppleEvents will be ignored.
In CodeWarrior, use the Edit:Preferences menu item to set the Project:SIZE Flags.
In THINK C, use the menu item Project:SetProjectType:SIZE Flags.
CAUTION:
This routine has not been tested.
SEE ALSO:
VideoToolbox:Demos:Quitter.c
ACKNOWLEDGEMENT:
Peter Lennie gave me a similar routine, for inclusion in the VideoToolbox.
HISTORY:
6/6/95 dgp extracted from Apple develop Bookmark CD snippets folder, and edited
to make it more readable and shorter. Corrected minor bugs in the disposing
of resources in the event of error.
*/
#include "VideoToolbox.h"
#include <AppleEvents.h>
OSErr KillEveryoneButMe(void)
{
ProcessSerialNumber psn={kNoProcess,kNoProcess},ourPSN,finderPSN={kNoProcess,kNoProcess};
ProcessInfoRec infoRec;
Str31 processName;
FSSpec procSpec;
OSErr error;
AppleEvent event;
AEDesc address;
Boolean isOk,isUs,isFinder,foundFinder=0;
long value;
error=Gestalt(gestaltAppleEventsAttr,&value);
if(error || !(value&(1<<gestaltAppleEventsPresent)))return 1;
GetCurrentProcess(&ourPSN);
do{
error=GetNextProcess(&psn);
switch(error){
case noErr:
isOk=1;
/* Is it us? */
SameProcess(&ourPSN,&psn,&isUs);
/* Is it the Finder? */
infoRec.processInfoLength=sizeof(ProcessInfoRec);
infoRec.processName=processName;
infoRec.processAppSpec=&procSpec;
GetProcessInformation(&psn,&infoRec);
isFinder=infoRec.processSignature=='MACS' && infoRec.processType=='FNDR';
if(isFinder){
finderPSN=psn;
foundFinder=1;
}
break;
case procNotFound:
isOk=0;
psn=finderPSN;
break;
default:
return error;
}
/*
Kill the Finder last of all.
Otherwise non-AppleEvent-aware apps won't get killed because the Finder
won't be there to convert the AppleEvent to puppet strings.
And FileShare must be killed before the Finder.
*/
if(isOk && !isUs && !isFinder || !isOk && foundFinder){
error=AECreateDesc(typeProcessSerialNumber,(Ptr)&psn,sizeof(psn),&address);
if(!error){
error=AECreateAppleEvent(kCoreEventClass,kAEQuitApplication,&address
,kAutoGenerateReturnID,kAnyTransactionID,&event);
AEDisposeDesc(&address);
/*
The Finder will convert the AppleEvent to puppetstrings if
the application is not AppleEvent-aware. But this only
happens for the 4 required (oapp,odoc,pdoc,and quit) AppleEvents
and only if you use the PSN for the address.
*/
if(!error){
AESend(&event,NULL,kAENoReply+kAEAlwaysInteract+kAECanSwitchLayer
,kAENormalPriority,kAEDefaultTimeout,NULL,NULL);
AEDisposeDesc(&event);
}
}
if(error)return error;
}
}while(isOk);
return 0;
}