home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2007 April / PCpro_2007_04.ISO / files / dsl / NVinst.exe / Scripts / NetWatcher / FreeResourcesForThis.nvs next >
Encoding:
Text File  |  2007-02-10  |  2.3 KB  |  88 lines

  1. {
  2. WORK ONLY ON WIN2000 OR BETTER!
  3. This script automatically disables sharing when any specified .exe
  4. program is active. Usefull for lazy gamers ;).
  5. }
  6. program FreeResourcesForThis;
  7.  
  8. const RefreshInterval=20;//Refresh interval, seconds
  9.  
  10. function IsGameExe(exe:string):boolean;
  11. begin
  12. {
  13. Specify here any .exe on start of wich script should disable sharing
  14. Note that exe must be specified in lower case!
  15. }
  16. Result:=((exe='quake.exe') or (exe='quake2.exe') or (exe='quake3.exe') or
  17.          (exe='rangers.exe') or (exe='hl.exe') or (exe='calc.exe'));
  18. end;
  19.  
  20.  
  21. type PROCESSENTRY32=record
  22. size:Longint;
  23. cntUsage:Longint;
  24. th32ProcessID:Longint;
  25. th32DefaultHeapID:Longint;
  26. th32ModuleID:Longint;
  27. cntThreads:Longint;
  28. th32ParentProcessID:Longint;
  29. pcPriClassBase:Longint;
  30. dwFlags:Longint;
  31. szExeFile:array [0..259] of char;
  32. end;
  33.  
  34. function CreateToolhelp32Snapshot(flg,pid:longint): Longint; external 'CreateToolhelp32Snapshot@kernel32.dll stdcall';
  35. function Process32First(snp:Longint;var lppe:PROCESSENTRY32): Longint; external 'Process32First@kernel32.dll stdcall';
  36. function Process32Next(snp:Longint;var lppe:PROCESSENTRY32): Longint; external 'Process32Next@kernel32.dll stdcall';
  37. function CloseHandle(hObject :Longint): Longint; external 'CloseHandle@kernel32.dll stdcall';
  38.  
  39. var snp:Longint;
  40.     e,v1,v2,i,j:integer;
  41.     pe:PROCESSENTRY32;
  42.     s:string;
  43.     gamecon,con:boolean;
  44.  
  45. Begin
  46. SetTimer(RefreshInterval*1000);
  47. con:=false;
  48. repeat
  49.  e:=WaitEvent(v1,v2);
  50.  if e=8 then
  51.   begin
  52.   snp:=CreateToolhelp32Snapshot(2,0);
  53.   if snp<>-1 then
  54.    begin
  55.    gamecon:=false;
  56.    pe.size:=sizeof(pe);
  57.    if Process32First(snp,pe)<>0 then
  58.     begin
  59.     repeat
  60.      i:=0;
  61.      while(i<260) and (pe.szExeFile[i]<>chr(0)) do i:=i+1;
  62.      setlength(s,i);
  63.      for j:=1 to i do s[j]:=pe.szExeFile[j-1];
  64.      s:=LowerCase(ExtractFileName(s));
  65.      if IsGameExe(s)then gamecon:=true;
  66.     until Process32Next(snp,pe)=0;
  67.     end;
  68.    CloseHandle(snp);
  69.    if gamecon then
  70.     begin
  71.     if NVWatcher.GetSharingEnabled then
  72.      begin
  73.      NVWatcher.SetSharingEnabled(false);
  74.      con:=true;
  75.      end;
  76.     end else
  77.     begin
  78.     if con and (not NVWatcher.GetSharingEnabled) then
  79.      begin
  80.      NVWatcher.SetSharingEnabled(true);
  81.      con:=false;
  82.      end;
  83.     end;
  84.    end;
  85.   end;
  86. until e=0;
  87. End.
  88.