From: <che...@us...> - 2010-11-18 18:46:39
|
Revision: 3958 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3958&view=rev Author: chef_koch Date: 2010-11-18 18:46:30 +0000 (Thu, 18 Nov 2010) Log Message: ----------- updated shared nsis headers Modified Paths: -------------- trunk/plugins/IR Server Suite/setup/include/MediaPortalDirectories.nsh trunk/plugins/IR Server Suite/setup/include/ProcessMacros.nsh Added Paths: ----------- trunk/plugins/IR Server Suite/setup/KillProc-plugin/ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Plugin/ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Plugin/KillProcDLL.dll trunk/plugins/IR Server Suite/setup/KillProc-plugin/ReadMe.txt trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/Exam28.cpp trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.cpp trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.dsp trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.dsw trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/StdAfx.cpp trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/StdAfx.h trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/exdll.c trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/exdll.h trunk/plugins/IR Server Suite/setup/nsSCM-plugin/ trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Plugin/ trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Plugin/nsSCM.dll trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/ trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/Makefile trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/Makefile.VS2008 trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/debug.h trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/exdll.h trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/nsSCM.cpp trunk/plugins/IR Server Suite/setup/nsSCM-plugin/readme.txt Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Plugin/KillProcDLL.dll =================================================================== (Binary files differ) Property changes on: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Plugin/KillProcDLL.dll ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/ReadMe.txt =================================================================== --- trunk/plugins/IR Server Suite/setup/KillProc-plugin/ReadMe.txt (rev 0) +++ trunk/plugins/IR Server Suite/setup/KillProc-plugin/ReadMe.txt 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,82 @@ +KillProcDLL \xA92003 by DITMan, based upon the KILL_PROC_BY_NAME function programmed by Ravi, reach him at: http://www.physiology.wisc.edu/ravi/ + + +-> Introduction + + This NSIS DLL Plug-In provides one function that has the ability to close any process running, without the need to have the 'class name' or 'window handle' you used to need when using the Windows API TerminateProcess or ExitProcess, just with the name of its .exe file. + + KillProc "process_name.exe" + + the parameter "process_name.exe" is passed through the stack, and the return code is stored in the $R0 variable. + +The meaning of the return codes is this: + + 0 = Process was successfully terminated + 603 = Process was not currently running + 604 = No permission to terminate process + 605 = Unable to load PSAPI.DLL + 602 = Unable to terminate process for some other reason + 606 = Unable to identify system type + 607 = Unsupported OS + 632 = Invalid process name + 700 = Unable to get procedure address from PSAPI.DLL + 701 = Unable to get process list, EnumProcesses failed + 702 = Unable to load KERNEL32.DLL + 703 = Unable to get procedure address from KERNEL32.DLL + 704 = CreateToolhelp32Snapshot failed + + +-> Usage with NSIS + + Just copy the 'KillProcDLL.dll' in your NSIS plugins directory, and call the function with one of the two suggested syntax in the NSIS documentation: + + KillProcDLL::KillProc "process_name.exe" + +OR + + ; Pre 2.0a4 syntax + SetOutPath $TEMP + GetTempFileName $8 + File /oname=$8 KillProcDLL.dll + Push "process_name.exe" + CallInstDLL KillProc + + then check out $R0 to get the return value if you need it. + + +-> Warning: + According to MSDN (MicroSoft Developers Network): + + The TerminateProcess function is used to unconditionally cause a process to exit. Use it only in extreme circumstances. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess. + + So use this DLL as your LAST and EXTREME option :) + + +-> Copyrights and all that stuff: + + The original source file for the KILL_PROC_BY_NAME function is provided, the file is: exam28.cpp, and it MUST BE in this zip file. + + You can redistribute this archive if you do it without changing anything on it, otherwise you're NOT allowed to do so. + + You may use this source code in any of your projects, while you keep all the files intact, otherwise you CAN NOT use this code. + + +-> Contact information: + +My homepage: + http://petra.uniovi.es/~i6948857/index.php + + +-> Greetings: + + First of all, thanks to Ravi for his great function... + Then all the winamp.com forums people who helped me doing this (kichik, Joost Verburg, Afrow UK...) + Last but not least, I want to devote this source code to my Girl, Natalia... :) + + + +Compiled in La Felguera, Spain, June-7th-2003 +while listening to 'The Cure - Greatest Hits' +(in Winamp 2.91, of course :D) + +\xB7-EOF-\xB7 \ No newline at end of file Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/Exam28.cpp =================================================================== --- trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/Exam28.cpp (rev 0) +++ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/Exam28.cpp 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,335 @@ +// Exam28.cpp +// 9/21/2000 (rk) +// Last modified: 3/10/2002 (RK) +// test the routine KILL_PROC_BY_NAME to terminate a process + +#include <windows.h> +#include <tlhelp32.h> +#include <iostream.h> + +#ifdef BORLANDC + #include <string.h> + #include <ctype.h> +#endif + +int KILL_PROC_BY_NAME(const char *); + +int main(int argc,char *argv[]) +{ +// Terminate a running process + char szName[100]="notepad.exe"; // Name of process to terminate + int iRes; + + iRes=KILL_PROC_BY_NAME(szName); + + cout << "Result code=" << iRes << endl; + return 0; +} + +int KILL_PROC_BY_NAME(const char *szToTerminate) +// Created: 6/23/2000 (RK) +// Last modified: 3/10/2002 (RK) +// Please report any problems or bugs to ko...@ph... +// The latest version of this routine can be found at: +// http://www.neurophys.wisc.edu/ravi/software/killproc/ +// Terminate the process "szToTerminate" if it is currently running +// This works for Win/95/98/ME and also Win/NT/2000/XP +// The process name is case-insensitive, i.e. "notepad.exe" and "NOTEPAD.EXE" +// will both work (for szToTerminate) +// Return codes are as follows: +// 0 = Process was successfully terminated +// 603 = Process was not currently running +// 604 = No permission to terminate process +// 605 = Unable to load PSAPI.DLL +// 602 = Unable to terminate process for some other reason +// 606 = Unable to identify system type +// 607 = Unsupported OS +// 632 = Invalid process name +// 700 = Unable to get procedure address from PSAPI.DLL +// 701 = Unable to get process list, EnumProcesses failed +// 702 = Unable to load KERNEL32.DLL +// 703 = Unable to get procedure address from KERNEL32.DLL +// 704 = CreateToolhelp32Snapshot failed +// Change history: +// modified 3/8/2002 - Borland-C compatible if BORLANDC is defined as +// suggested by Bob Christensen +// modified 3/10/2002 - Removed memory leaks as suggested by +// Jonathan Richard-Brochu (handles to Proc and Snapshot +// were not getting closed properly in some cases) +{ + BOOL bResult,bResultm; + DWORD aiPID[1000],iCb=1000,iNumProc,iV2000=0; + DWORD iCbneeded,i,iFound=0; + char szName[MAX_PATH],szToTermUpper[MAX_PATH]; + HANDLE hProc,hSnapShot,hSnapShotm; + OSVERSIONINFO osvi; + HINSTANCE hInstLib; + int iLen,iLenP,indx; + HMODULE hMod; + PROCESSENTRY32 procentry; + MODULEENTRY32 modentry; + + // Transfer Process name into "szToTermUpper" and + // convert it to upper case + iLenP=strlen(szToTerminate); + if(iLenP<1 || iLenP>MAX_PATH) return 632; + for(indx=0;indx<iLenP;indx++) + szToTermUpper[indx]=toupper(szToTerminate[indx]); + szToTermUpper[iLenP]=0; + + // PSAPI Function Pointers. + BOOL (WINAPI *lpfEnumProcesses)( DWORD *, DWORD cb, DWORD * ); + BOOL (WINAPI *lpfEnumProcessModules)( HANDLE, HMODULE *, + DWORD, LPDWORD ); + DWORD (WINAPI *lpfGetModuleBaseName)( HANDLE, HMODULE, + LPTSTR, DWORD ); + + // ToolHelp Function Pointers. + HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ; + BOOL (WINAPI *lpfProcess32First)(HANDLE,LPPROCESSENTRY32) ; + BOOL (WINAPI *lpfProcess32Next)(HANDLE,LPPROCESSENTRY32) ; + BOOL (WINAPI *lpfModule32First)(HANDLE,LPMODULEENTRY32) ; + BOOL (WINAPI *lpfModule32Next)(HANDLE,LPMODULEENTRY32) ; + + // First check what version of Windows we're in + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + bResult=GetVersionEx(&osvi); + if(!bResult) // Unable to identify system version + return 606; + + // At Present we only support Win/NT/2000/XP or Win/9x/ME + if((osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) && + (osvi.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)) + return 607; + + if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT) + { + // Win/NT or 2000 or XP + + // Load library and get the procedures explicitly. We do + // this so that we don't have to worry about modules using + // this code failing to load under Windows 9x, because + // it can't resolve references to the PSAPI.DLL. + hInstLib = LoadLibraryA("PSAPI.DLL"); + if(hInstLib == NULL) + return 605; + + // Get procedure addresses. + lpfEnumProcesses = (BOOL(WINAPI *)(DWORD *,DWORD,DWORD*)) + GetProcAddress( hInstLib, "EnumProcesses" ) ; + lpfEnumProcessModules = (BOOL(WINAPI *)(HANDLE, HMODULE *, + DWORD, LPDWORD)) GetProcAddress( hInstLib, + "EnumProcessModules" ) ; + lpfGetModuleBaseName =(DWORD (WINAPI *)(HANDLE, HMODULE, + LPTSTR, DWORD )) GetProcAddress( hInstLib, + "GetModuleBaseNameA" ) ; + + if(lpfEnumProcesses == NULL || + lpfEnumProcessModules == NULL || + lpfGetModuleBaseName == NULL) + { + FreeLibrary(hInstLib); + return 700; + } + + bResult=lpfEnumProcesses(aiPID,iCb,&iCbneeded); + if(!bResult) + { + // Unable to get process list, EnumProcesses failed + FreeLibrary(hInstLib); + return 701; + } + + // How many processes are there? + iNumProc=iCbneeded/sizeof(DWORD); + + // Get and match the name of each process + for(i=0;i<iNumProc;i++) + { + // Get the (module) name for this process + + strcpy(szName,"Unknown"); + // First, get a handle to the process + hProc=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE, + aiPID[i]); + // Now, get the process name + if(hProc) + { + if(lpfEnumProcessModules(hProc,&hMod,sizeof(hMod),&iCbneeded) ) + { + iLen=lpfGetModuleBaseName(hProc,hMod,szName,MAX_PATH); + } + } + CloseHandle(hProc); + // We will match regardless of lower or upper case +#ifdef BORLANDC + if(strcmp(strupr(szName),szToTermUpper)==0) +#else + if(strcmp(_strupr(szName),szToTermUpper)==0) +#endif + { + // Process found, now terminate it + iFound=1; + // First open for termination + hProc=OpenProcess(PROCESS_TERMINATE,FALSE,aiPID[i]); + if(hProc) + { + if(TerminateProcess(hProc,0)) + { + // process terminated + CloseHandle(hProc); + FreeLibrary(hInstLib); + return 0; + } + else + { + // Unable to terminate process + CloseHandle(hProc); + FreeLibrary(hInstLib); + return 602; + } + } + else + { + // Unable to open process for termination + FreeLibrary(hInstLib); + return 604; + } + } + } + } + + if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS) + { + // Win/95 or 98 or ME + + hInstLib = LoadLibraryA("Kernel32.DLL"); + if( hInstLib == NULL ) + return 702; + + // Get procedure addresses. + // We are linking to these functions of Kernel32 + // explicitly, because otherwise a module using + // this code would fail to load under Windows NT, + // which does not have the Toolhelp32 + // functions in the Kernel 32. + lpfCreateToolhelp32Snapshot= + (HANDLE(WINAPI *)(DWORD,DWORD)) + GetProcAddress( hInstLib, + "CreateToolhelp32Snapshot" ) ; + lpfProcess32First= + (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32)) + GetProcAddress( hInstLib, "Process32First" ) ; + lpfProcess32Next= + (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32)) + GetProcAddress( hInstLib, "Process32Next" ) ; + lpfModule32First= + (BOOL(WINAPI *)(HANDLE,LPMODULEENTRY32)) + GetProcAddress( hInstLib, "Module32First" ) ; + lpfModule32Next= + (BOOL(WINAPI *)(HANDLE,LPMODULEENTRY32)) + GetProcAddress( hInstLib, "Module32Next" ) ; + if( lpfProcess32Next == NULL || + lpfProcess32First == NULL || + lpfModule32Next == NULL || + lpfModule32First == NULL || + lpfCreateToolhelp32Snapshot == NULL ) + { + FreeLibrary(hInstLib); + return 703; + } + + // The Process32.. and Module32.. routines return names in all uppercase + + // Get a handle to a Toolhelp snapshot of all the systems processes. + + hSnapShot = lpfCreateToolhelp32Snapshot( + TH32CS_SNAPPROCESS, 0 ) ; + if( hSnapShot == INVALID_HANDLE_VALUE ) + { + FreeLibrary(hInstLib); + return 704; + } + + // Get the first process' information. + procentry.dwSize = sizeof(PROCESSENTRY32); + bResult=lpfProcess32First(hSnapShot,&procentry); + + // While there are processes, keep looping and checking. + while(bResult) + { + // Get a handle to a Toolhelp snapshot of this process. + hSnapShotm = lpfCreateToolhelp32Snapshot( + TH32CS_SNAPMODULE, procentry.th32ProcessID) ; + if( hSnapShotm == INVALID_HANDLE_VALUE ) + { + CloseHandle(hSnapShot); + FreeLibrary(hInstLib); + return 704; + } + // Get the module list for this process + modentry.dwSize=sizeof(MODULEENTRY32); + bResultm=lpfModule32First(hSnapShotm,&modentry); + + // While there are modules, keep looping and checking + while(bResultm) + { + if(strcmp(modentry.szModule,szToTermUpper)==0) + { + // Process found, now terminate it + iFound=1; + // First open for termination + hProc=OpenProcess(PROCESS_TERMINATE,FALSE,procentry.th32ProcessID); + if(hProc) + { + if(TerminateProcess(hProc,0)) + { + // process terminated + CloseHandle(hSnapShotm); + CloseHandle(hSnapShot); + CloseHandle(hProc); + FreeLibrary(hInstLib); + return 0; + } + else + { + // Unable to terminate process + CloseHandle(hSnapShotm); + CloseHandle(hSnapShot); + CloseHandle(hProc); + FreeLibrary(hInstLib); + return 602; + } + } + else + { + // Unable to open process for termination + CloseHandle(hSnapShotm); + CloseHandle(hSnapShot); + FreeLibrary(hInstLib); + return 604; + } + } + else + { // Look for next modules for this process + modentry.dwSize=sizeof(MODULEENTRY32); + bResultm=lpfModule32Next(hSnapShotm,&modentry); + } + } + + //Keep looking + CloseHandle(hSnapShotm); + procentry.dwSize = sizeof(PROCESSENTRY32); + bResult = lpfProcess32Next(hSnapShot,&procentry); + } + CloseHandle(hSnapShot); + } + if(iFound==0) + { + FreeLibrary(hInstLib); + return 603; + } + FreeLibrary(hInstLib); + return 0; +} + Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.cpp =================================================================== --- trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.cpp (rev 0) +++ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.cpp 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,364 @@ +// +// KillProcDLL. \xA92003 by DITMan, based upon the KILL_PROC_BY_NAME function +// programmed by Ravi, reach him at: http://www.physiology.wisc.edu/ravi/ +// +// You may use this source code in any of your projects, while you keep this +// header intact, otherwise you CAN NOT use this code. +// +// My homepage: +// http://petra.uniovi.es/~i6948857/index.php +// + +#include "stdafx.h" + +using namespace std; + +HINSTANCE g_hInstance; +HWND g_hwndParent; + +BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + g_hInstance=(struct HINSTANCE__ *)hInst; + return TRUE; +} + +int KILL_PROC_BY_NAME(const char *szToTerminate) +// Created: 6/23/2000 (RK) +// Last modified: 3/10/2002 (RK) +// Please report any problems or bugs to ko...@ph... +// The latest version of this routine can be found at: +// http://www.neurophys.wisc.edu/ravi/software/killproc/ +// Terminate the process "szToTerminate" if it is currently running +// This works for Win/95/98/ME and also Win/NT/2000/XP +// The process name is case-insensitive, i.e. "notepad.exe" and "NOTEPAD.EXE" +// will both work (for szToTerminate) +// Return codes are as follows: +// 0 = Process was successfully terminated +// 603 = Process was not currently running +// 604 = No permission to terminate process +// 605 = Unable to load PSAPI.DLL +// 602 = Unable to terminate process for some other reason +// 606 = Unable to identify system type +// 607 = Unsupported OS +// 632 = Invalid process name +// 700 = Unable to get procedure address from PSAPI.DLL +// 701 = Unable to get process list, EnumProcesses failed +// 702 = Unable to load KERNEL32.DLL +// 703 = Unable to get procedure address from KERNEL32.DLL +// 704 = CreateToolhelp32Snapshot failed +// Change history: +// modified 3/8/2002 - Borland-C compatible if BORLANDC is defined as +// suggested by Bob Christensen +// modified 3/10/2002 - Removed memory leaks as suggested by +// Jonathan Richard-Brochu (handles to Proc and Snapshot +// were not getting closed properly in some cases) +{ + BOOL bResult,bResultm; + DWORD aiPID[1000],iCb=1000,iNumProc,iV2000=0; + DWORD iCbneeded,i,iFound=0; + char szName[MAX_PATH],szToTermUpper[MAX_PATH]; + HANDLE hProc,hSnapShot,hSnapShotm; + OSVERSIONINFO osvi; + HINSTANCE hInstLib; + int iLen,iLenP,indx; + HMODULE hMod; + PROCESSENTRY32 procentry; + MODULEENTRY32 modentry; + + // Transfer Process name into "szToTermUpper" and + // convert it to upper case + iLenP=strlen(szToTerminate); + if(iLenP<1 || iLenP>MAX_PATH) return 632; + for(indx=0;indx<iLenP;indx++) + szToTermUpper[indx]=toupper(szToTerminate[indx]); + szToTermUpper[iLenP]=0; + + // PSAPI Function Pointers. + BOOL (WINAPI *lpfEnumProcesses)( DWORD *, DWORD cb, DWORD * ); + BOOL (WINAPI *lpfEnumProcessModules)( HANDLE, HMODULE *, + DWORD, LPDWORD ); + DWORD (WINAPI *lpfGetModuleBaseName)( HANDLE, HMODULE, + LPTSTR, DWORD ); + + // ToolHelp Function Pointers. + HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ; + BOOL (WINAPI *lpfProcess32First)(HANDLE,LPPROCESSENTRY32) ; + BOOL (WINAPI *lpfProcess32Next)(HANDLE,LPPROCESSENTRY32) ; + BOOL (WINAPI *lpfModule32First)(HANDLE,LPMODULEENTRY32) ; + BOOL (WINAPI *lpfModule32Next)(HANDLE,LPMODULEENTRY32) ; + + // First check what version of Windows we're in + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + bResult=GetVersionEx(&osvi); + if(!bResult) // Unable to identify system version + return 606; + + // At Present we only support Win/NT/2000/XP or Win/9x/ME + if((osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) && + (osvi.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)) + return 607; + + if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT) + { + // Win/NT or 2000 or XP + + // Load library and get the procedures explicitly. We do + // this so that we don't have to worry about modules using + // this code failing to load under Windows 9x, because + // it can't resolve references to the PSAPI.DLL. + hInstLib = LoadLibraryA("PSAPI.DLL"); + if(hInstLib == NULL) + return 605; + + // Get procedure addresses. + lpfEnumProcesses = (BOOL(WINAPI *)(DWORD *,DWORD,DWORD*)) + GetProcAddress( hInstLib, "EnumProcesses" ) ; + lpfEnumProcessModules = (BOOL(WINAPI *)(HANDLE, HMODULE *, + DWORD, LPDWORD)) GetProcAddress( hInstLib, + "EnumProcessModules" ) ; + lpfGetModuleBaseName =(DWORD (WINAPI *)(HANDLE, HMODULE, + LPTSTR, DWORD )) GetProcAddress( hInstLib, + "GetModuleBaseNameA" ) ; + + if(lpfEnumProcesses == NULL || + lpfEnumProcessModules == NULL || + lpfGetModuleBaseName == NULL) + { + FreeLibrary(hInstLib); + return 700; + } + + bResult=lpfEnumProcesses(aiPID,iCb,&iCbneeded); + if(!bResult) + { + // Unable to get process list, EnumProcesses failed + FreeLibrary(hInstLib); + return 701; + } + + // How many processes are there? + iNumProc=iCbneeded/sizeof(DWORD); + + // Get and match the name of each process + for(i=0;i<iNumProc;i++) + { + // Get the (module) name for this process + + strcpy(szName,"Unknown"); + // First, get a handle to the process + hProc=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE, + aiPID[i]); + // Now, get the process name + if(hProc) + { + if(lpfEnumProcessModules(hProc,&hMod,sizeof(hMod),&iCbneeded) ) + { + iLen=lpfGetModuleBaseName(hProc,hMod,szName,MAX_PATH); + } + } + CloseHandle(hProc); + // We will match regardless of lower or upper case +#ifdef BORLANDC + if(strcmp(strupr(szName),szToTermUpper)==0) +#else + if(strcmp(_strupr(szName),szToTermUpper)==0) +#endif + { + // Process found, now terminate it + iFound=1; + // First open for termination + hProc=OpenProcess(PROCESS_TERMINATE,FALSE,aiPID[i]); + if(hProc) + { + if(TerminateProcess(hProc,0)) + { + // process terminated + CloseHandle(hProc); + FreeLibrary(hInstLib); + return 0; + } + else + { + // Unable to terminate process + CloseHandle(hProc); + FreeLibrary(hInstLib); + return 602; + } + } + else + { + // Unable to open process for termination + FreeLibrary(hInstLib); + return 604; + } + } + } + } + + if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS) + { + // Win/95 or 98 or ME + + hInstLib = LoadLibraryA("Kernel32.DLL"); + if( hInstLib == NULL ) + return 702; + + // Get procedure addresses. + // We are linking to these functions of Kernel32 + // explicitly, because otherwise a module using + // this code would fail to load under Windows NT, + // which does not have the Toolhelp32 + // functions in the Kernel 32. + lpfCreateToolhelp32Snapshot= + (HANDLE(WINAPI *)(DWORD,DWORD)) + GetProcAddress( hInstLib, + "CreateToolhelp32Snapshot" ) ; + lpfProcess32First= + (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32)) + GetProcAddress( hInstLib, "Process32First" ) ; + lpfProcess32Next= + (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32)) + GetProcAddress( hInstLib, "Process32Next" ) ; + lpfModule32First= + (BOOL(WINAPI *)(HANDLE,LPMODULEENTRY32)) + GetProcAddress( hInstLib, "Module32First" ) ; + lpfModule32Next= + (BOOL(WINAPI *)(HANDLE,LPMODULEENTRY32)) + GetProcAddress( hInstLib, "Module32Next" ) ; + if( lpfProcess32Next == NULL || + lpfProcess32First == NULL || + lpfModule32Next == NULL || + lpfModule32First == NULL || + lpfCreateToolhelp32Snapshot == NULL ) + { + FreeLibrary(hInstLib); + return 703; + } + + // The Process32.. and Module32.. routines return names in all uppercase + + // Get a handle to a Toolhelp snapshot of all the systems processes. + + hSnapShot = lpfCreateToolhelp32Snapshot( + TH32CS_SNAPPROCESS, 0 ) ; + if( hSnapShot == INVALID_HANDLE_VALUE ) + { + FreeLibrary(hInstLib); + return 704; + } + + // Get the first process' information. + procentry.dwSize = sizeof(PROCESSENTRY32); + bResult=lpfProcess32First(hSnapShot,&procentry); + + // While there are processes, keep looping and checking. + while(bResult) + { + // Get a handle to a Toolhelp snapshot of this process. + hSnapShotm = lpfCreateToolhelp32Snapshot( + TH32CS_SNAPMODULE, procentry.th32ProcessID) ; + if( hSnapShotm == INVALID_HANDLE_VALUE ) + { + CloseHandle(hSnapShot); + FreeLibrary(hInstLib); + return 704; + } + // Get the module list for this process + modentry.dwSize=sizeof(MODULEENTRY32); + bResultm=lpfModule32First(hSnapShotm,&modentry); + + // While there are modules, keep looping and checking + while(bResultm) + { + if(strcmp(modentry.szModule,szToTermUpper)==0) + { + // Process found, now terminate it + iFound=1; + // First open for termination + hProc=OpenProcess(PROCESS_TERMINATE,FALSE,procentry.th32ProcessID); + if(hProc) + { + if(TerminateProcess(hProc,0)) + { + // process terminated + CloseHandle(hSnapShotm); + CloseHandle(hSnapShot); + CloseHandle(hProc); + FreeLibrary(hInstLib); + return 0; + } + else + { + // Unable to terminate process + CloseHandle(hSnapShotm); + CloseHandle(hSnapShot); + CloseHandle(hProc); + FreeLibrary(hInstLib); + return 602; + } + } + else + { + // Unable to open process for termination + CloseHandle(hSnapShotm); + CloseHandle(hSnapShot); + FreeLibrary(hInstLib); + return 604; + } + } + else + { // Look for next modules for this process + modentry.dwSize=sizeof(MODULEENTRY32); + bResultm=lpfModule32Next(hSnapShotm,&modentry); + } + } + + //Keep looking + CloseHandle(hSnapShotm); + procentry.dwSize = sizeof(PROCESSENTRY32); + bResult = lpfProcess32Next(hSnapShot,&procentry); + } + CloseHandle(hSnapShot); + } + if(iFound==0) + { + FreeLibrary(hInstLib); + return 603; + } + FreeLibrary(hInstLib); + return 0; +} + + +// +// This is the only exported function, KillProc. It receives the name +// of a process through the NSIS stack. The return-value from the +// KILL_PROC_BY_NAME function is stored in the $R0 variable, so push +// it before calling KillProc function if you don't want to lose the +// data that R0 could contain. +// +// You can call this function in NSIS like this: +// +// KillProcDLL::KillProc "process_name.exe" +// +// example: +// KillProcDLL::KillProc "msnmsgr.exe" +// would close MSN Messenger if running, and return 0 in R0 +// if it's not running, it would return 603. +// +// --------------------------- ---- --- -- - + +extern "C" __declspec(dllexport) void KillProc(HWND hwndParent, int string_size, + char *variables, stack_t **stacktop) +{ + char parameter[200]; + char temp[10]; + int value; + g_hwndParent=hwndParent; + EXDLL_INIT(); + { + popstring(parameter); + value=KILL_PROC_BY_NAME(parameter); + setuservariable(INST_R0, itoa(value, temp, 10)); + } +} \ No newline at end of file Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.dsp =================================================================== --- trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.dsp (rev 0) +++ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.dsp 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,122 @@ +# Microsoft Developer Studio Project File - Name="KillProcDLL" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=KillProcDLL - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "KillProcDLL.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "KillProcDLL.mak" CFG="KillProcDLL - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "KillProcDLL - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "KillProcDLL - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "KillProcDLL - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KILLPROCDLL_EXPORTS" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KILLPROCDLL_EXPORTS" /Yu"stdafx.h" /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x40a /d "NDEBUG" +# ADD RSC /l 0x40a /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 + +!ELSEIF "$(CFG)" == "KillProcDLL - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KILLPROCDLL_EXPORTS" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KILLPROCDLL_EXPORTS" /Yu"stdafx.h" /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x40a /d "_DEBUG" +# ADD RSC /l 0x40a /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "KillProcDLL - Win32 Release" +# Name "KillProcDLL - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\KillProcDLL.cpp +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.cpp +# ADD CPP /Yc"stdafx.h" +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\exdll.h +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# Begin Source File + +SOURCE=.\ReadMe.txt +# End Source File +# End Target +# End Project Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.dsw =================================================================== --- trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.dsw (rev 0) +++ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/KillProcDLL.dsw 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "KillProcDLL"=.\KillProcDLL.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/StdAfx.cpp =================================================================== --- trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/StdAfx.cpp (rev 0) +++ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/StdAfx.cpp 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// KillProcDLL.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/StdAfx.h =================================================================== --- trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/StdAfx.h (rev 0) +++ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/StdAfx.h 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,34 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#if !defined(AFX_STDAFX_H__780690DC_E128_403D_BC07_780D1B2CC101__INCLUDED_) +#define AFX_STDAFX_H__780690DC_E128_403D_BC07_780D1B2CC101__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + +#include <windows.h> + +#include <string> // String management... + +//From exam28.cpp +#include <tlhelp32.h> +#include <iostream.h> + +#ifdef BORLANDC + #include <string.h> + #include <ctype.h> +#endif + +//To make it a NSIS Plug-In +#include "exdll.h" + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__780690DC_E128_403D_BC07_780D1B2CC101__INCLUDED_) Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/exdll.c =================================================================== --- trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/exdll.c (rev 0) +++ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/exdll.c 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,37 @@ +#include <windows.h> +#include "exdll.h" + +HINSTANCE g_hInstance; + +HWND g_hwndParent; + +void __declspec(dllexport) myFunction(HWND hwndParent, int string_size, + char *variables, stack_t **stacktop) +{ + g_hwndParent=hwndParent; + + EXDLL_INIT(); + + + // note if you want parameters from the stack, pop them off in order. + // i.e. if you are called via exdll::myFunction file.dat poop.dat + // calling popstring() the first time would give you file.dat, + // and the second time would give you poop.dat. + // you should empty the stack of your parameters, and ONLY your + // parameters. + + // do your stuff here + { + char buf[1024]; + wsprintf(buf,"$0=%s\n",getuservariable(INST_0)); + MessageBox(g_hwndParent,buf,0,MB_OK); + } +} + + + +BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + g_hInstance=hInst; + return TRUE; +} Added: trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/exdll.h =================================================================== --- trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/exdll.h (rev 0) +++ trunk/plugins/IR Server Suite/setup/KillProc-plugin/Source/exdll.h 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,97 @@ +#ifndef _EXDLL_H_ +#define _EXDLL_H_ + +// only include this file from one place in your DLL. +// (it is all static, if you use it in two places it will fail) + +#define EXDLL_INIT() { \ + g_stringsize=string_size; \ + g_stacktop=stacktop; \ + g_variables=variables; } + +// For page showing plug-ins +#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8) +#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd) +#define NOTIFY_BYE_BYE 'x' + +typedef struct _stack_t { + struct _stack_t *next; + char text[1]; // this should be the length of string_size +} stack_t; + + +static unsigned int g_stringsize; +static stack_t **g_stacktop; +static char *g_variables; + +static int popstring(char *str); // 0 on success, 1 on empty stack +static void pushstring(char *str); + +enum +{ +INST_0, // $0 +INST_1, // $1 +INST_2, // $2 +INST_3, // $3 +INST_4, // $4 +INST_5, // $5 +INST_6, // $6 +INST_7, // $7 +INST_8, // $8 +INST_9, // $9 +INST_R0, // $R0 +INST_R1, // $R1 +INST_R2, // $R2 +INST_R3, // $R3 +INST_R4, // $R4 +INST_R5, // $R5 +INST_R6, // $R6 +INST_R7, // $R7 +INST_R8, // $R8 +INST_R9, // $R9 +INST_CMDLINE, // $CMDLINE +INST_INSTDIR, // $INSTDIR +INST_OUTDIR, // $OUTDIR +INST_EXEDIR, // $EXEDIR +INST_LANG, // $LANGUAGE +__INST_LAST +}; + + +// utility functions (not required but often useful) +static int popstring(char *str) +{ + stack_t *th; + if (!g_stacktop || !*g_stacktop) return 1; + th=(*g_stacktop); + lstrcpy(str,th->text); + *g_stacktop = th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +static void pushstring(char *str) +{ + stack_t *th; + if (!g_stacktop) return; + th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize); + lstrcpyn(th->text,str,g_stringsize); + th->next=*g_stacktop; + *g_stacktop=th; +} + +static char *getuservariable(int varnum) +{ + if (varnum < 0 || varnum >= __INST_LAST) return NULL; + return g_variables+varnum*g_stringsize; +} + +static void setuservariable(int varnum, char *var) +{ + if (var != NULL && varnum >= 0 && varnum < __INST_LAST) + lstrcpy(g_variables + varnum*g_stringsize, var); +} + + + +#endif//_EXDLL_H_ \ No newline at end of file Modified: trunk/plugins/IR Server Suite/setup/include/MediaPortalDirectories.nsh =================================================================== --- trunk/plugins/IR Server Suite/setup/include/MediaPortalDirectories.nsh 2010-11-18 18:44:08 UTC (rev 3957) +++ trunk/plugins/IR Server Suite/setup/include/MediaPortalDirectories.nsh 2010-11-18 18:46:30 UTC (rev 3958) @@ -67,9 +67,7 @@ Var MPdir.Language Var MPdir.Database Var MPdir.Thumbs -Var MPdir.Weather Var MPdir.Cache -Var MPdir.BurnerSupport #*************************** #*************************** @@ -130,9 +128,7 @@ StrCpy $MPdir.Language "$MPdir.Config\language" StrCpy $MPdir.Database "$MPdir.Config\database" StrCpy $MPdir.Thumbs "$MPdir.Config\thumbs" - StrCpy $MPdir.Weather "$MPdir.Base\weather" StrCpy $MPdir.Cache "$MPdir.Config\cache" - StrCpy $MPdir.BurnerSupport "$MPdir.Base\Burner" !macroend @@ -175,9 +171,7 @@ ${ReadMPdir} Language ${ReadMPdir} Database ${ReadMPdir} Thumbs - ${ReadMPdir} Weather ${ReadMPdir} Cache - ${ReadMPdir} BurnerSupport StrCpy $0 "0" @@ -248,9 +242,7 @@ ${LOG_TEXT} "INFO" " Language: $MPdir.Language" ${LOG_TEXT} "INFO" " Database: $MPdir.Database" ${LOG_TEXT} "INFO" " Thumbs: $MPdir.Thumbs" - ${LOG_TEXT} "INFO" " Weather: $MPdir.Weather" ${LOG_TEXT} "INFO" " Cache: $MPdir.Cache" - ${LOG_TEXT} "INFO" " BurnerSupport: $MPdir.BurnerSupport" Pop $0 Modified: trunk/plugins/IR Server Suite/setup/include/ProcessMacros.nsh =================================================================== --- trunk/plugins/IR Server Suite/setup/include/ProcessMacros.nsh 2010-11-18 18:44:08 UTC (rev 3957) +++ trunk/plugins/IR Server Suite/setup/include/ProcessMacros.nsh 2010-11-18 18:46:30 UTC (rev 3958) @@ -24,6 +24,9 @@ !include LogicLib.nsh !include "${svn_InstallScripts}\include\LoggingMacros.nsh" +!AddPluginDir "${svn_InstallScripts}\nsSCM-plugin\Plugin" +!AddPluginDir "${svn_InstallScripts}\KillProc-plugin\Plugin" + #*************************** #*************************** @@ -36,34 +39,17 @@ ${LOG_TEXT} "INFO" "KillProcess: ${Process}" - StrCpy $R1 1 ; set counter to 1 - ${Do} + KillProcDLL::KillProc "${Process}" - nsExec::Exec '"taskkill" /F /IM "${Process}"' + ${If} $R0 == "0" + ${LOG_TEXT} "INFO" "KillProcess: ${Process} was killed successfully." + ${ElseIf} $R0 == "603" + ${LOG_TEXT} "INFO" "KillProcess: ${Process} is not running." + ${Else} + ${LOG_TEXT} "INFO" "KillProcess: Unable to kill ${Process} (error $R0)." + Abort "Unable to kill ${Process} (error $R0). Installation aborted." + ${EndIF} - Pop $0 - - ${Select} $0 - ${Case} "0" - ${LOG_TEXT} "INFO" "KillProcess: ${Process} was killed successfully." - ${ExitDo} - ${Case} "128" - ${LOG_TEXT} "INFO" "KillProcess: ${Process} is not running." - ${ExitDo} - ${CaseElse} - - ${LOG_TEXT} "ERROR" "KillProcess: Unknown result: $0" - IntOp $R1 $R1 + 1 ; increase retry-counter +1 - ${If} $R1 > 5 ; try max. 5 times - ${ExitDo} - ${Else} - ${LOG_TEXT} "INFO" "KillProcess: Trying again. $R1/5" - ${EndIf} - - ${EndSelect} - ${Loop} - - !verbose pop !macroend @@ -75,34 +61,42 @@ ${LOG_TEXT} "INFO" "StopService: ${Service}" - StrCpy $R1 1 ; set counter to 1 - ${Do} + nsSCM::QueryStatus /NOUNLOAD "${Service}" + Pop $0 + Pop $1 - nsExec::Exec 'net stop "${Service}"' + ${IfNot} $1 = 1 + ${LOG_TEXT} "INFO" "StopService: Trying to stop ${Service}..." + + nsSCM::Stop /NOUNLOAD "${Service}" Pop $0 - ${Select} $0 - ${Case} "0" - ${LOG_TEXT} "INFO" "StopService: ${Service} was stopped successfully." - ${ExitDo} - ${Case} "2" - ${LOG_TEXT} "INFO" "StopService: ${Service} is not started." - ${ExitDo} - ${CaseElse} + ${If} $0 == "error" + ${LOG_TEXT} "INFO" "StopService: Unable to stop ${Service} (error $1)." + Abort "Unable to stop ${Service} (error $1). Installation aborted." + ${Else} - ${LOG_TEXT} "ERROR" "StopService: Unknown result: $0" - IntOp $R1 $R1 + 1 ; increase retry-counter +1 - ${If} $R1 > 5 ; try max. 5 times - ${ExitDo} - ${Else} - ${LOG_TEXT} "INFO" "StopService: Trying again. $R1/5" - ${EndIf} + StrCpy $R0 0 + ${Do} + ${If} $R0 > 0 + ${LOG_TEXT} "INFO" "StopService: sleeping 20ms and recheking service status..." + Sleep 20 + ${EndIF} - ${EndSelect} - ${Loop} + IntOp $R0 $R0 + 1 + nsSCM::QueryStatus /NOUNLOAD "${Service}" + Pop $0 + Pop $1 + ${LoopUntil} $1 = 1 + ${LOG_TEXT} "INFO" "StopService: ${Service} was stopped successfully." + ${EndIF} + ${Else} + ${LOG_TEXT} "INFO" "StopService: ${Service} is already stopped." + ${EndIf} + !verbose pop !macroend @@ -149,7 +143,7 @@ ${Else} - ${LOG_TEXT} "INFO" "RenameDirectory: Directory does not exist. No need to rename: ${DirPath}" + ${LOG_TEXT} "INFO" "RenameDirectory: Directory does not exist. No need to rename: ${DirPath}" ${EndIf} Added: trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Plugin/nsSCM.dll =================================================================== (Binary files differ) Property changes on: trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Plugin/nsSCM.dll ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/Makefile =================================================================== --- trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/Makefile (rev 0) +++ trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/Makefile 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,67 @@ +# Makefile for use with MSVC 6.0 for build win32 executable. + +DEBUG = 0 + +CC = cl.exe +CXX = $(CC) +AR = lib.exe +RM = del +LINK = link.exe +NMS = "C:\Program Files\Compuware\DriverStudio\SoftICE\nmsym.exe" + +CFLAGS = -nologo -c -ML -W3 -WX -GX +LFLAGS = -nologo -machine:i386 -incremental:no -nodefaultlib -pdb:none +NMSOPT = /TRANSLATE:SOURCE,PACKAGE,ALWAYS /SOURCE:.; + +LFLAGS = $(LFLAGS) -subsystem:windows -dll -entry:"_DllMainCRTStartup" -opt:nowin98 + +!if "$(DEBUG)" == "1" +CFLAGS = $(CFLAGS) -D"_DEBUG" -D"DEBUG" -Z7 -Oid +LFLAGS = $(LFLAGS) -debug -debug:notmapped,FULL -debugtype:cv +!else +CFLAGS = $(CFLAGS) -D"NDEBUG" -D"RELEASE" -O1 -GD -GF -LD -Zl +LFLAGS = $(LFLAGS) -release -debug:none +!endif + +PROJECT = nsSCM + +LIBRARY_OBJS = +LIBLIST = libc.lib oldnames.lib advapi32.lib kernel32.lib user32.lib + +.SUFFIXES: .c .h .cpp .obj $(SUFFIXES) + +all: $(PROJECT).dll + +clean: + if exist *.obj $(RM) *.obj + if exist *.lib $(RM) *.lib + if exist *.dll $(RM) *.dll + if exist *.exe $(RM) *.exe + if exist *.exp $(RM) *.exp + if exist *.pdb $(RM) *.pdb + if exist *.nms $(RM) *.nms + @echo $(PROJECT) cleaned... + +$(PROJECT).dll: Makefile $(PROJECT).obj $(LIBRARY_OBJS) + $(LINK) $(LFLAGS) -out:$@ $(PROJECT).obj $(LIBRARY_OBJS) $(LIBLIST) +!if "$(DEBUG)" == "1" + $(NMS) $(NMSOPT) $@ + $(NMS) /SYM:$(PROJECT).NMS; +!endif + +lib: $(LIBRARY_OBJS) + $(AR) -out:$(PROJECT).lib $(LIBRARY_OBJS) + +src zip: + @echo ------------------------------------------------------------------ + @echo Backing up to archive $(PROJECT).zip + @echo ------------------------------------------------------------------ + @cd .. + -@zip.exe -ru9D $(PROJECT).zip $(PROJECT) -x *.bak *.err *.exe *.exp *.lib *.dll *.map *.nms *.o *.obj *.rar *.scc + @cd $(PROJECT) + +.c.obj: + $(CXX) $(CFLAGS) -Fo$* -c $< + +.cpp.obj: + $(CXX) $(CFLAGS) -Fo$* -c $< Added: trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/Makefile.VS2008 =================================================================== --- trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/Makefile.VS2008 (rev 0) +++ trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/Makefile.VS2008 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,67 @@ +# Makefile for use with MSVC 6.0 for build win32 executable. + +DEBUG = 0 + +CC = cl.exe +CXX = $(CC) +AR = lib.exe +RM = del +LINK = link.exe +NMS = "C:\Program Files\Compuware\DriverStudio\SoftICE\nmsym.exe" + +CFLAGS = -nologo -c -W3 -WX -EHsc +LFLAGS = -nologo -machine:i386 -incremental:no -nodefaultlib -pdb:none +NMSOPT = /TRANSLATE:SOURCE,PACKAGE,ALWAYS /SOURCE:.; + +LFLAGS = $(LFLAGS) -subsystem:windows -dll -entry:"_DllMainCRTStartup" + +!if "$(DEBUG)" == "1" +CFLAGS = $(CFLAGS) -D"_DEBUG" -D"DEBUG" -Z7 -Oid +LFLAGS = $(LFLAGS) -debug -debug:notmapped,FULL -debugtype:cv +!else +CFLAGS = $(CFLAGS) -D"NDEBUG" -D"RELEASE" -O1 -GF -LD -Zl +LFLAGS = $(LFLAGS) -release -debug:none +!endif + +PROJECT = nsSCM + +LIBRARY_OBJS = +LIBLIST = libcmt.lib oldnames.lib advapi32.lib kernel32.lib user32.lib + +.SUFFIXES: .c .h .cpp .obj $(SUFFIXES) + +all: $(PROJECT).dll + +clean: + if exist *.obj $(RM) *.obj + if exist *.lib $(RM) *.lib + if exist *.dll $(RM) *.dll + if exist *.exe $(RM) *.exe + if exist *.exp $(RM) *.exp + if exist *.pdb $(RM) *.pdb + if exist *.nms $(RM) *.nms + @echo $(PROJECT) cleaned... + +$(PROJECT).dll: Makefile $(PROJECT).obj $(LIBRARY_OBJS) + $(LINK) $(LFLAGS) -out:$@ $(PROJECT).obj $(LIBRARY_OBJS) $(LIBLIST) +!if "$(DEBUG)" == "1" + $(NMS) $(NMSOPT) $@ + $(NMS) /SYM:$(PROJECT).NMS; +!endif + +lib: $(LIBRARY_OBJS) + $(AR) -out:$(PROJECT).lib $(LIBRARY_OBJS) + +src zip: + @echo ------------------------------------------------------------------ + @echo Backing up to archive $(PROJECT).zip + @echo ------------------------------------------------------------------ + @cd .. + -@zip.exe -ru9D $(PROJECT).zip $(PROJECT) -x *.bak *.err *.exe *.exp *.lib *.dll *.map *.nms *.o *.obj *.rar *.scc + @cd $(PROJECT) + +.c.obj: + $(CXX) $(CFLAGS) -Fo$* -c $< + +.cpp.obj: + $(CXX) $(CFLAGS) -Fo$* -c $< Added: trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/debug.h =================================================================== --- trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/debug.h (rev 0) +++ trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/debug.h 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,40 @@ +/********************************************************************************************************* + * + * Module Name: debug.h + * + * Abstract: Debuging macroses + * + * Author: Vyacheslav I. Levtchenko (mail-to: sl...@r-..., sl...@el...) + * + * Revision History: 20.10.2003 started + * + * Classes, methods and structures: + * + * TODO: + * + *********************************************************************************************************/ + +#ifndef __DEBUG_H__ +#define __DEBUG_H__ + +#if (DEBUG) +# ifndef __GNUC__ +# define brk() {_asm int 3} +# else +# define brk() { asm ("int $3"); } +# endif +#else +# ifndef __GNUC__ +# define brk() {/* nothing */;} +# else +# define brk() {/* nothing */;} +# endif +#endif + +#if (TOTALDEBUG) +# define tbrk() brk() +#else +# define tbrk() +#endif + +#endif Added: trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/exdll.h =================================================================== --- trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/exdll.h (rev 0) +++ trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/exdll.h 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,287 @@ +/********************************************************************************************************* + * + * Module Name: exdll.h + * + * Abstract: NSIS plugin common header + * + * Author: + * + * Modified: Vyacheslav I. Levtchenko (mail-to: sl...@r-..., sl...@el...) + * + * Revision History: 20.10.2003 started + * + * Classes, methods and structures: + * + * TODO: + * + *********************************************************************************************************/ + +#ifndef _EXDLL_H_ +#define _EXDLL_H_ + +// only include this file from one place in your DLL. +// (it is all static, if you use it in two places it will fail) + +#define EXDLL_INIT() \ +{ \ + g_stringsize=string_size; \ + g_stacktop=stacktop; \ + g_variables=variables; \ + brk (); } + +// For page showing plug-ins +#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8) +#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd) +#define NOTIFY_BYE_BYE 'x' + +#define NSISFunction(funcname) extern "C" void __declspec(dllexport) funcname(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) + +#define MALLOC(len) GlobalAlloc(GPTR, len); +#define FREE(mem) { if (mem) GlobalFree (mem), mem = NULL; } + +#define STRNEW() (char*)MALLOC((sizeof(char) * g_stringsize) + 1); +#define STRDEL(mem) FREE (mem); + +#define RET_ERROR() { clear_stack (); pushstring("error"); return; } +#define RET_SUCCESS() { clear_stack (); pushstring("success"); return; } +#define RET(rc) if (!rc) { RET_ERROR(); } else { RET_SUCCESS(); } + +#define RET_DWORD(rc, dd) \ +{ clear_stack (); \ + pushdword (dd); \ + if (!rc) pushstring("error"); \ + else pushstring("success");\ + return; } + +#define strcpy(x,y) lstrcpy(x,y) +#define strncpy(x,y,z) lstrcpyn(x,y,z) +#define strdup(x) STRDUP(x); +#define stricmp(x,y) lstrcmpi(x,y) + +enum +{ + INST_0, // $0 + INST_1, // $1 + INST_2, // $2 + INST_3, // $3 + INST_4, // $4 + INST_5, // $5 + INST_6, // $6 + INST_7, // $7 + INST_8, // $8 + INST_9, // $9 + INST_R0, // $R0 + INST_R1, // $R1 + INST_R2, // $R2 + INST_R3, // $R3 + INST_R4, // $R4 + INST_R5, // $R5 + INST_R6, // $R6 + INST_R7, // $R7 + INST_R8, // $R8 + INST_R9, // $R9 + INST_CMDLINE, // $CMDLINE + INST_INSTDIR, // $INSTDIR + INST_OUTDIR, // $OUTDIR + INST_EXEDIR, // $EXEDIR + INST_LANG, // $LANGUAGE + __INST_LAST +}; + +typedef struct _stack_t +{ + struct _stack_t *next; + char text[1]; // this should be the length of string_size +} stack_t; + +static unsigned int g_stringsize = 0; + +/* Call stack (LIFO) variables _cdecl sequence (right-left) */ +static stack_t **g_stacktop = NULL; + +/* Global variables array */ +static char *g_variables = NULL; + +void *operator new (unsigned int num_bytes) { return GlobalAlloc (GPTR, num_bytes); } +void operator delete (void *p) { if (p) GlobalFree(p), p = NULL; } + +// utility functions (not required but often useful) +// 0 on success, 1 on empty stack +static int popstring (char *str) +{ + stack_t *th; + + if (!g_stacktop + || !*g_stacktop) + return 1; + + th = *g_stacktop; + + lstrcpy (str, th->text); + *g_stacktop = th->next; + GlobalFree ((HGLOBAL)th); + + return 0; +} + +static void clear_stack (void) +{ + stack_t *th; + + while (g_stacktop + && *g_stacktop) + { + th = *g_stacktop; + *g_stacktop = th->next; + GlobalFree ((HGLOBAL)th); + } +} + +static void pushstring (const char *str) +{ + stack_t *th; + + if (!g_stacktop) + return; + + th = (stack_t*) GlobalAlloc (GPTR, sizeof(stack_t) + g_stringsize); + + lstrcpyn (th->text, str, g_stringsize); + th->next = *g_stacktop; + *g_stacktop = th; +} + +static void pushdword (DWORD dd) +{ + stack_t *th; + + if (!g_stacktop) + return; + + th = (stack_t*) GlobalAlloc (GPTR, sizeof(stack_t) + g_stringsize); + + wsprintf (th->text, "%d", dd); + th->next = *g_stacktop; + *g_stacktop = th; +} + +static char *getuservariable (int varnum) +{ + if (varnum < 0 + || varnum >= __INST_LAST) + return NULL; + + return g_variables + varnum * g_stringsize; +} + +static void setuservariable(int varnum, char *var) +{ + if (var != NULL + && varnum >= 0 + && varnum < __INST_LAST) + lstrcpy (g_variables + varnum * g_stringsize, var); +} + +static char *ns_strstr (const char *string, const char *strCharSet) +{ + size_t chklen, i; + char *s1, *s2; + + if (lstrlen (string) < lstrlen (strCharSet)) + return 0; + + if (!*strCharSet) + return (char*)string; + + chklen = lstrlen(string) - lstrlen(strCharSet); + + for (i = 0; i <= chklen; i++) + { + s1 = &((char*)string)[i]; + s2 = (char*)strCharSet; + + while (*s1++ == *s2++) + if (!*s2) + return &((char*)string)[i]; + } + + return 0; +} + +static unsigned int ns_atoi (char *s) +{ + unsigned int v = 0; + + if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) + { + s+=2; + + for (;;) + { + int c=*s++; + + if (c >= '0' + && c <= '9') + c-='0'; + else + if (c >= 'a' + && c <= 'f') + c-='a'-10; + else + if (c >= 'A' + && c <= 'F') + c-='A'-10; + else + break; + + v <<= 4; + v+=c; + } + } + else + if (*s == '0' + && s[1] <= '7' + && s[1] >= '0') + { + s++; + + for (;;) + { + int c=*s++; + + if (c >= '0' + && c <= '7') + c-='0'; + else + break; + + v<<=3; + v+=c; + } + } + else + { + for (;;) + { + int c=*s++ - '0'; + + if (c < 0 + || c > 9) + break; + + v*=10; + v+=c; + } + } + + return (int)v; +} + +static char *STRDUP (const char *c) +{ + char *t = (char*) MALLOC (strlen(c) + 1); + strcpy (t,c); + return t; +} + +#endif //_EXDLL_H_ Added: trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/nsSCM.cpp =================================================================== --- trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/nsSCM.cpp (rev 0) +++ trunk/plugins/IR Server Suite/setup/nsSCM-plugin/Source/nsSCM.cpp 2010-11-18 18:46:30 UTC (rev 3958) @@ -0,0 +1,383 @@ +/********************************************************************************************************* + * + * Module Name: nsSCM.cpp + * + * Abstract: NSIS Service Control Manager + * + * Author: Vyacheslav I. Levtchenko (mail-to: sl...@r-..., sl...@el...) + * + * Revision History: 20.10.2003 started + * + * Classes, methods and structures: + * + * TODO: + * + *********************************************************************************************************/ + +#include <windows.h> + +#include "debug.h" +#include "exdll.h" + +static SC_HANDLE schSCManager = (SC_HANDLE)INVALID_HANDLE_VALUE; +#define CHECK_HANDLE(schSCManager) if (INVALID_HANDLE_VALUE == schSCManager) { RET_ERROR(); } + +#if 0 +// Service Types (Bit Mask) +#define SERVICE_KERNEL_DRIVER 0x00000001 +#define SERVICE_FILE_SYSTEM_DRIVER 0x00000002 +#define SERVICE_ADAPTER 0x00000004 +#define SERVICE_RECOGNIZER_DRIVER 0x00000008 + +#define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \ + SERVICE_FILE_SYSTEM_DRIVER | \ + SERVICE_RECOGNIZER_DRIVER) + +#define SERVICE_WIN32_OWN_PROCESS 0x00000010 +#define SERVICE_WIN32_SHARE_PROCESS 0x00000020 +#define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \ + SERVICE_WIN32_SHARE_PROCESS) + +#define SERVICE_INTERACTIVE_PROCESS 0x00000100 + +#define SERVICE_TYPE_ALL (SERVICE_WIN32 | \ + SERVICE_ADAPTER | \ + SERVICE_DRIVER | \ + SERVICE_INTERACTIVE_PROCESS) + +// Start Type +#define SERVICE_BOOT_START 0x00000000 +#define SERVICE_SYSTEM_START 0x00000001 +#define SERVICE_AUTO_START 0x00000002 +#define SERVICE_DEMAND_START 0x00000003 +#define SERVICE_DISABLED 0x00000004 + +// Error control type +#define SERVICE_ERROR_IGNORE 0x00000000 +#define SERVICE_ERROR_NORMAL 0x00000001 +#define SERVICE_ERROR_SEVERE 0x00000002 +#define SERVICE_ERROR_CRITICAL 0x00000003 + +#endif + +// 1 str 2 str 3 num 4 num 5 str 6 str 7 str 8 str 9 str +// <name of service: startstop name> <name to display: display in SCM> <service type> <start type> <service's binary:filepath> <load order group: name> <dependencies: name> <account: name> <pass... [truncated message content] |