Tu as bien raison mon bon OLIVIER.
Ce qui leur manque à nos jeunes, c'est le bon coup de pied ou le dos change de nom de temps en temps.
Tout est maché, protégé, dévalorisé, à tel point qu'il ne savent meme plus ce que c'est de galérer.
Bref, avec lui, j'ai du pain sur la planche.
Mais il faut absolument qu'il arrette de se faire virer au moins cette année, car apres je compte l'orienter sur un CAP.
Mais pour que le LEP l'accepte, il faudrait qu'il n'y ai pas d'ommicide pendant cette année
Avant de créer ce programme, j'ai éssayé de le responsabiliser,mais autant apprendre à un cheval à danser la gigue
Alors grace au code d'un peu tout le monde, j'ai suivi les combines de DOBRO et je vous est concocté une petite sauce au champignons.
J'ai malaxé 4 codes et ça donne un résultat assez bon.(Enfin pour moi evidement)
Il me reste à ajouter un fichier LOG, pour pouvoir vérifier si il arrive à couper quand meme le prg, car hier il m'a dit qu'il allait chercher.
Et aussi pour que si il change la date systeme, il l'est dans le "baigneur".
Je l'ai encouragé à le faire, car je me dit que pendant qu'il cherche à ni...le systeme, il fait fonctionner ses neurones, et c'est toujours mieux que son dofus ou MSN.
Il me reste aussi l'inscription dans la BDR, pour le lancement au démarrage de windows.
Puis je vais rajouter des codes secrets qui permettrons à sa mere de lui donner à distance 1/2h, 1h ou 2h suplementaires, si il a fait et fini ses devoirs.
Code : Tout sélectionner
; VigiDevoir codé par Kwai chang caine en pureBasic v4.10
; Avec l'aide des codes de : - End7 (Module hide process)
; - Julien et soldat inconnu (Module shutdown)
; - Pb (Module inputbox)
; - ??? (Module timer)
NomLogiciel.s = "VigiDevoir "
Version.s = "v1.0"
Message.s = Space(14) + "Allez au boulot !!!" + Chr(13) + Chr(13) + Chr(13) + "Tu as 1 minute pour sauvegarder."
AmusementEnHeures.f = 0.0001
SauvegardeEnMinute.f = 0.005
MotDePasse.s = "Maman"
#FenetreVigiDevoir = 1
#FenetreParametres = 2
#LabelMessage = 10
#LabelParametres = 11
#FontArial32 = 20
#STATUS_INFO_LENGTH_MISMATCH = $C0000004
#STATUS_ACCESS_DENIED = $C0000022
#STATUS_INVALID_HANDLE = $C0000008
#ERROR_SUCCESS = $0
#SECTION_MAP_WRITE = $2
#SECTION_MAP_READ = $4
#READ_CONTROL = $20000
#WRITE_DAC = $40000
#NO_INHERITANCE = 0
#DACL_SECURITY_INFORMATION = $4
Structure IO_STATUS_BLOCK
Status.l
Information.l
EndStructure
Structure UNICODE_STRING
Length.w
MaximumLength.w
Buffer.l
EndStructure
#OBJ_INHERIT = $2
#OBJ_PERMANENT = $10
#OBJ_EXCLUSIVE = $20
#OBJ_CASE_INSENSITIVE = $40
#OBJ_OPENIF = $80
#OBJ_OPENLINK = $100
#OBJ_KERNEL_HANDLE = $200
#OBJ_VALID_ATTRIBUTES = $3F2
#MAX_QUERY_PROCESS=100
#SE_KERNEL_OBJECT=6
Structure OBJECT_ATTRIBUTES
Length.l
RootDirectory.l
ObjectName.l
Attributes.l
SecurityDeor.l
SecurityQualityOfService.l
EndStructure
Structure ACCESS_MODE
NOT_USED_ACCESSl.l
GRANT_ACCESS.l
SET_ACCESS.l
DENY_ACCESS.l
REVOKE_ACCESS.l
SET_AUDIT_SUCCESS.l
SET_AUDIT_FAILURE.l
EndStructure
Structure MULTIPLE_TRUSTEE_OPERATION
NO_MULTIPLE_TRUSTEE.l
TRUSTEE_IS_IMPERSONATE.l
EndStructure
Structure TRUSTEE_FORM
TRUSTEE_IS_SID.l
TRUSTEE_IS_NAME.l
EndStructure
Structure TRUSTEE_TYPE
TRUSTEE_IS_UNKNOWN.l
TRUSTEE_IS_USER.l
TRUSTEE_IS_GROUP.l
EndStructure
Structure TRUSTEE
pMultipleTrustee.l
MultipleTrusteeOperation.MULTIPLE_TRUSTEE_OPERATION
TrusteeForm.TRUSTEE_FORM
TrusteeType.TRUSTEE_TYPE
ptstrName.s
EndStructure
Structure EXPLICIT_ACCESS
grfAccessPermissions.l
grfAccessMode.ACCESS_MODE
grfInheritance.l
TRUSTEE.TRUSTEE
EndStructure
Global g_hNtDLL.l
Global g_pMapPhysicalMemory.l
Global g_hMPM.l
Global Dim inByte.b(3)
Procedure SetPhyscialMemorySectionCanBeWrited(hSection.l)
pDacl.l
pNewDacl.l
pSD.l
dwRes.l
ea.EXPLICIT_ACCESS
GetSecurityInfo_(hSection, #SE_KERNEL_OBJECT,#DACL_SECURITY_INFORMATION,0, 0, @pDacl, 0, @pSD)
SetEntriesInAcl_( 1, ea, pDacl, @pNewDacl)
SetSecurityInfo_( hSection, #SE_KERNEL_OBJECT,#DACL_SECURITY_INFORMATION,0, 0,pNewDacl, 0)
CleanUp:
LocalFree_(pSD)
LocalFree_(pNewDacl)
EndProcedure
Procedure.l OpenPhysicalMemory()
Status.l
Attributes.OBJECT_ATTRIBUTES
PhysmemString.UNICODE_STRING
s.s="\ D e v i c e \ P h y s i c a l M e m o r y "
a.b=0
i.l
For i=0 To 21
CopyMemory(@a,@s+i*2+1,1)
Next i
;s="\Device\PhysicalMemory"
RtlInitUnicodeString_(PhysmemString, @s)
With Attributes
\Length = SizeOf(Attributes)
\RootDirectory = 0
\ObjectName = @PhysmemString
\Attributes = 0
\SecurityDeor = 0
\SecurityQualityOfService = 0
EndWith
Status = ZwOpenSection_(@g_hMPM, #SECTION_MAP_READ|#SECTION_MAP_WRITE, Attributes)
If Status = #STATUS_ACCESS_DENIED
Status = ZwOpenSection_(@g_hMPM, #READ_CONTROL|#WRITE_DAC, Attributes)
SetPhyscialMemorySectionCanBeWrited(g_hMPM)
CloseHandle_(g_hMPM)
Status = ZwOpenSection_(@g_hMPM, #SECTION_MAP_READ|#SECTION_MAP_WRITE , Attributes)
EndIf
lDirectoty.l
Select OSVersion()
Case #PB_OS_Windows_2000
lDirectoty = $30000
Case #PB_OS_Windows_XP
lDirectoty = $39000
EndSelect
If Status=0
g_pMapPhysicalMemory=MapViewOfFile_(g_hMPM, 4, 0,lDirectoty, $1000)
If g_pMapPhysicalMemory <> 0
ProcedureReturn g_hMPM
EndIf
EndIf
EndProcedure
Procedure.f ByteArrToLong()
I.w
ByteArrToLongs.f
inbytes.w
For I = 0 To 3
If inByte(I)<0
inbytes=256+inByte(I)
Else
inbytes=inByte(I)
EndIf
ByteArrToLongs = ByteArrToLongs + inBytes * Pow($100,I)
Next I
ProcedureReturn ByteArrToLongs
EndProcedure
Procedure.l LinearToPhys(BaseAddress.l, addr.l)
VAddr.l: PGDE.l: PTE.l: PAddr.l
lTemp.l
VAddr = addr
inByte(0)=PeekB(@VAddr)
inByte(1)=PeekB(@VAddr+1)
inByte(2)=PeekB(@VAddr+2)
inByte(3)=PeekB(@VAddr+3)
OK.f=ByteArrToLong()/Pow(2,22)
strings.s=StrF(ok)
Position.l = FindString(strings, ".", 1)
strings = RSet(strings, Position-1)
lTemp=Val(strings)
PGDE = BaseAddress + lTemp*4
PGDE=PeekL(PGDE)
If (PGDE & 1) <> 0
lTemp = PGDE & $80
If lTemp <> 0
PAddr = (PGDE & $FFC00000) + (VAddr & $3FFFFF)
Else
PGDE = MapViewOfFile_(g_hMPM, 4, 0,PGDE & $FFFFF000,$1000)
lTemp = (VAddr & $3FF000) / Pow(2 , 12)
PTE = PGDE + lTemp * 4
PTE=PeekL(PTE)
If (PTE And 1) <> 0
PAddr = (PTE & $FFFFF000) + (VAddr & $FFF)
UnmapViewOfFile_(PGDE)
EndIf
EndIf
EndIf
ProcedureReturn PAddr
EndProcedure
Procedure.l GetData(addr.l)
phys.l:Tmp.l: ret.l
phys = LinearToPhys(g_pMapPhysicalMemory, addr)
Tmp = MapViewOfFile_(g_hMPM, 4, 0,phys & $FFFFF000, $1000)
If Tmp <> 0
ret = Tmp + ((phys & $FFF) / Pow(2 , 2)) * 4
ret=PeekL(ret)
UnmapViewOfFile_(Tmp)
ProcedureReturn ret
EndIf
EndProcedure
Procedure.b SetData(addr.l, Datas.l)
phys.l: Tmp.l: x.l:y.l
phys = LinearToPhys(g_pMapPhysicalMemory, addr)
Tmp = MapViewOfFile_(g_hMPM, #SECTION_MAP_WRITE, 0, phys & $FFFFF000, $1000)
If Tmp <> 0
x = Tmp + ((phys & $FFF) / Pow(2,2)) * 4
y=PeekL(@Datas)
PokeL(x,y)
UnmapViewOfFile_(Tmp)
ProcedureReturn 1
EndIf
EndProcedure
Procedure HideHook(hidepid.l)
thread.l:process.l:fw.l:bw.l
strInfo.s
lOffsetFlink.l
lOffsetBlink.l
lOffsetPID.l
Select OSVersion()
Case #PB_OS_Windows_2000
lOffsetFlink = $A0
lOffsetBlink = $A4
lOffsetPID = $9C
Case #PB_OS_Windows_XP
lOffsetFlink = $88
lOffsetBlink = $8C
lOffsetPID = $84
EndSelect
If OpenPhysicalMemory() <> 0
thread = GetData($FFDFF124)
process = GetData(thread + $44)
If hidepid=0
fw = GetData(process + lOffsetFlink)
bw = GetData(process + lOffsetBlink)
SetData(fw + 4, bw)
SetData(bw, fw)
Else
lStartPid.l
pKEP.l
xpid.l
lStartPid = GetData(process + lOffsetPID)
pKEP=process
i.l
For i=0 To #MAX_QUERY_PROCESS
If pKEP=0
Break
EndIf
xpid = GetData(pKEP + lOffsetPID)
If lStartPid=((xpid&i)>1)
Break
EndIf
If hidepid=xpid
fw = GetData(pKEP + lOffsetFlink)
bw = GetData(pKEP + lOffsetBlink)
SetData(fw + 4, bw)
SetData(bw, fw)
Break
EndIf
pKEP = GetData(pKEP + lOffsetFlink) - lOffsetFlink
Next i
EndIf
CloseHandle_(g_hMPM)
EndIf
EndProcedure
ProcedureDLL HideNow()
HideHook(0)
EndProcedure
ProcedureDLL HideAnther(a.l)
HideHook(a)
EndProcedure
Structure PROCESSENTRY32s
dwsize.l
cntusage.l
th32ProcessID.l
th32DefaultHeapID.l
th32ModuleID.l
cntThreads.l
th32ParentProcessID.l
pcPriClassBase.l
dwFlags.l
szExeFile.s{1024}
EndStructure
#TH32CS_SNAPPROCESS = $2
Procedure.l FindPid(s.s)
Process.PROCESSENTRY32s
ProcSnap.l
ProcSnap = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0)
If ProcSnap<>0
Process\dwsize=SizeOf(Process)
Process32First_(ProcSnap, Process)
While Process32Next_(ProcSnap, Process) > 0
If Process\szExeFile =s
ProcedureReturn Process\th32ProcessID
Break
EndIf
Wend
EndIf
EndProcedure
Procedure ComputerShutDown(Param.l)
; Param = paramètre d'instinction de l'ordinateur
; 1 : quitter session
; 2 : arrêter
; 3 : redémarrer
#TOKEN_ADJUST_PRIVILEGES = 32
#TOKEN_QUERY = 8
#SE_PRIVILEGE_ENABLED = 2
#EWX_LOGOFF = 0
#EWX_SHUTDOWN = 1
#EWX_REBOOT = 2
#EWX_FORCE = 4
#EWX_POWEROFF = 8
Structure MyLUID
LowPart.l
HighPart.l
Attributes.l
EndStructure
Structure MyTOKEN
PrivilegeCount.l
LowPart.l
HighPart.l
Attributes.l
EndStructure
Protected hdlTokenHandle.l, tmpLuid.MyLUID, tkp.MyTOKEN, tkpNewButIgnored.MyTOKEN, lBufferNeeded.l
OpenProcessToken_(GetCurrentProcess_(), #TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY, @hdlTokenHandle)
SysName.s = "" + Chr(0)
Name.s = "SeShutdownPrivilege" + Chr(0)
LookupPrivilegeValue_(SysName, Name, @tmpLuid)
tmpLuid\Attributes = #SE_PRIVILEGE_ENABLED
tkp\PrivilegeCount = 1
tkp\LowPart = tmpLuid\LowPart
tkp\HighPart = tmpLuid\HighPart
tkp\Attributes = tmpLuid\Attributes
AdjustTokenPrivileges_(hdlTokenHandle, 0, @tkp, SizeOf(MyTOKEN), @tkpNewButIgnored, @lBufferNeeded)
Select Param
Case 1 : ExitWindowsEx_(#EWX_LOGOFF | #EWX_FORCE, 0)
Case 2 : ExitWindowsEx_(#EWX_SHUTDOWN | #EWX_FORCE, 0)
Case 3 : ExitWindowsEx_(#EWX_REBOOT | #EWX_FORCE, 0)
EndSelect
EndProcedure
Procedure.s InputRequesterPassword(title$,prompt$,def$,password)
Box = OpenWindow(999,0,0,500,145,title$,#PB_Window_ScreenCentered)
If Box <> 0 And CreateGadgetList(WindowID(999)) <> 0
TextGadget(996,6,8,487,70,prompt$)
If password=0
Flags = #ES_MULTILINE|#ES_AUTOVSCROLL
Else
Flags=#PB_String_Password|#ES_AUTOVSCROLL
EndIf
StringGadget(997,6,85,487,20,def$,flags)
ButtonGadget(998,365,114,60,23,"OK")
ButtonGadget(999,433,114,60,23,"Cancel")
SendMessage_(GadgetID(997),#EM_SETSEL,0,Len(def$))
GetAsyncKeyState_(#VK_RETURN)
GetAsyncKeyState_(#VK_ESCAPE)
StickyWindow(999,#True)
SetForegroundWindow_(WindowID(999))
SetActiveGadget(997)
MessageBeep_(#MB_ICONQUESTION)
Repeat
Ev = WaitWindowEvent(1)
Id = EventGadget()
Ret = GetAsyncKeyState_(#VK_RETURN)
Esc = GetAsyncKeyState_(#VK_ESCAPE)
a = GetForegroundWindow_()
If a <> box
thread1=GetWindowThreadProcessId_(@a,0) : thread2=GetWindowThreadProcessId_(@box,0)
If thread1<>thread2
AttachThreadInput_(thread1,thread2,#True)
EndIf
SetForegroundWindow_(box) : Sleep_(1)
If thread1<>thread2
AttachThreadInput_(thread1,thread2,#False)
EndIf
SetActiveGadget(997) : MessageBeep_(#MB_ICONQUESTION)
EndIf
Until (Ev = #PB_Event_Gadget And (Id=998 Or Id=999)) Or Ret<>0 Or Ev=#PB_Event_CloseWindow ;Or Esc<>0
If Id = 998 Or Ret <> 0
Text$ = GetGadgetText(997)
Else
Text$ = Chr(1)
EndIf
CloseWindow(999)
EndIf
ProcedureReturn Text$
EndProcedure
LoadFont(#FontArial32,"Arial", 16, Option)
OpenWindow(#FenetreParametres, 10, 10, 600, 350, Space(80) + "Retour au devoirs", #PB_Window_ScreenCentered)
SetWindowColor(#FenetreParametres, RGB(157, 253, 98))
CreateGadgetList(WindowID(#FenetreParametres))
TextGadget(#LabelParametres, 150, 100, 2000, 200, Message)
SetGadgetColor(#LabelParametres, #PB_Gadget_BackColor, RGB(157, 253, 98))
SetGadgetColor(#LabelParametres, #PB_Gadget_FrontColor, RGB(0,0,0))
SetGadgetFont(#LabelParametres, FontID(#FontArial32))
SetGadgetText(#LabelParametres, Space(15) + NomLogiciel + Version + Chr(13) + Chr(13) + "Temps d'amusement : " + StrF(AmusementEnHeures, 4) + " Heures." + Chr(13) + Chr(13) + "Temps de sauvegarde : " + StrF(SauvegardeEnMinute, 4) + " Minutes.")
Delay (4000)
CloseWindow(#FenetreParametres)
OpenWindow(#FenetreVigiDevoir, 10, 10, 600, 350, "Retour au devoirs", #PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowColor(#FenetreVigiDevoir, RGB(234, 46, 50))
CreateGadgetList(WindowID(#FenetreVigiDevoir))
TextGadget(#LabelMessage, 150, 100, 2000, 200, Message)
SetGadgetColor(#LabelMessage, #PB_Gadget_BackColor, RGB(234, 46, 50))
SetGadgetColor(#LabelMessage, #PB_Gadget_FrontColor, RGB(0,0,0))
SetGadgetFont(#LabelMessage, FontID(#FontArial32))
HideHook(FindPid("Retour au devoirs"))
AmusementEnMillisecondes.l = AmusementEnHeures * 60000000
SauvegardeEnMillisecondes.l = SauvegardeEnMinute * 1000000
SetTimer_(WindowID(#FenetreVigiDevoir), 1, AmusementEnMillisecondes, 0)
Repeat
Evenement = WindowEvent()
Sleep_(100)
If Evenement = #WM_TIMER
KillTimer_(WindowID(#FenetreVigiDevoir),1)
If IsWindowVisible_(WindowID(#FenetreVigiDevoir)) = False
HideWindow(#FenetreVigiDevoir, 0)
SetWindowPos_(WindowID(#FenetreVigiDevoir), -1, WindowX(#FenetreVigiDevoir), WindowY(#FenetreVigiDevoir), WindowWidth(#FenetreVigiDevoir), WindowHeight(#FenetreVigiDevoir), #SWP_NOSIZE)
SetTimer_(WindowID(#FenetreVigiDevoir), 1, SauvegardeEnMillisecondes, 0)
Else
MessageRequester(NomLogiciel + Version,"Couik !!!!!",0)
End
;ComputerShutDown(2) ; ATTENTION si y'a activage de cette ligne, y'a interet à avoir sauvegardage .........
EndIf
ElseIf GetAsyncKeyState_(#VK_ESCAPE) And GetAsyncKeyState_(#VK_CONTROL)
Reponse.s = InputRequesterPassword(NomLogiciel + Version, "Essaye d'entrer un mot de passe, (On sait jamais !!!!)", "", 1)
If Reponse = MotDePasse
KillTimer_(WindowID(#FenetreVigiDevoir),1)
MessageRequester(NomLogiciel + Version, Space (20) + "Bravo !!! " + Chr(13) + Chr(13) + NomLogiciel + Version + " viens d'etre arrêté.",0)
Break
EndIf
EndIf
ForEver
Alors le code est un peu long (Normal c'est les copier/coller) si quelqu'un a mieux ou plus court, evidemment je suis preneur