bonjour,
y a t-il une fonction qui nous permet d'arrêter complètement la machine tournant sous windows 2000 ou XP ?
mes remerciements.
bonjour,
y a t-il une fonction qui nous permet d'arrêter complètement la machine tournant sous windows 2000 ou XP ?
mes remerciements.
Dans la FAQ Delphi :
http://www.developpez.com/delphi/faq...StopRunWindows
Voici un exe, qui fait le boulot (c'était pour rebooter un ordi via maintenance a distance, lorsque l'outil de controle ne propose pas le reboot, j'ai fait ça pour un collègue), c'est juste un dpr ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 program ForceShutDown; uses Forms, Windows; {$R *.res} procedure ExitWindowsMsg(const PlatformCaption: PChar); begin case MessageBox(Application.Handle, PChar('Windows '+PlatformCaption+' : ShutDown(Yes) or Reboot(No) ?'), 'Confirmation', MB_YESNOCANCEL) of IDYES : if System.DebugHook = 0 then ExitWindowsEx(EWX_SHUTDOWN, 0) else Beep(3000, 1); IDNO : if System.DebugHook = 0 then ExitWindowsEx(EWX_REBOOT, 0) else Beep(2000, 1); else if System.DebugHook = 0 then Exit else Beep(1000, 1); end; end; var OSInfo: OSVERSIONINFO; TokenHandle, ReturnLength: Cardinal; NewState, PreviousState: TTokenPrivileges; lpLuid: TLargeInteger; begin Application.Initialize(); Application.Run(); OSInfo.dwOSVersionInfoSize := SizeOf(OSVERSIONINFO); if GetVersionEx(OSInfo) then begin if OSInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then begin if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TokenHandle) then begin try if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', lpLuid) then begin NewState.PrivilegeCount := 1; NewState.Privileges[0].Luid := lpLuid; NewState.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; if AdjustTokenPrivileges(TokenHandle, False, NewState, SizeOf(NewState), PreviousState, ReturnLength) then begin ExitWindowsMsg('NT'); end; end; finally CloseHandle(TokenHandle); end; end; end else begin ExitWindowsMsg('9x'); end; end; end.
Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !![]()
Attention Troll Méchant !
"Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
L'ignorance n'excuse pas la médiocrité !
L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
Il faut avoir le courage de se tromper et d'apprendre de ses erreurs
Yep !
J'ai testé sur 2K le dpr de Shai : brut de copier/coller, ça n'éteint pas la machine.
Il faut certainement remplacer EWX_SHUTDOWN par EWX_POWEROFF pour l'extinction, mais c'est difficile à tester en cours de travail, hein,![]()
Mes 2 cts,
--
jp
Il faut modifier d'abord réclamer le privilège gentiment à Windows 2000 (c'est comme pour XP), voir la FAQ citée plus haut![]()
Yep !
J'ai testé pour vous avec EWX_POWEROFF, ça s'éteint correctement.
Et le reboot fonctionne également.
@Waskol : pas compris ton post...
Mes 2 cts,
--
jp
Partager