intercettare spegnimento xp (Wm_queryendsession) |
tom |
04/11/2004 |
Difficoltà:
Medio
|
|
ho
trovato
questo
codice
per
intercettare
la
chiusura
della
sessione,
lho
provato
in
vb
,
e
funziona
egregiamnete.
ora
pero'
vorrei
capire
bene
come
funziona,
qualcuno
sarebbe
cosi
gentile
da
spiegarmelo?
Attribute
VB_Name
=
"Module1"
Public
Const
GWL_WNDPROC
=
(-4)
Public
Const
WM_ENDSESSION
=
&H16
Public
Const
WM_QUERYENDSESSION
=
&H11
Public
WndProc
As
Long
Declare
Function
CallWindowProc
Lib
"user32"
Alias
"CallWindowProcA"
(ByVal
lpPrevWndFunc
As
Long,
Byval
hwnd
As
Long,
Byval
Msg
As
Long,
Byval
wParam
As
Long,
Byval
lParam
As
Long)
As
Long
Declare
Function
SetWindowLong
Lib
"user32"
Alias
"SetWindowLongA"
(ByVal
hwnd
As
Long,
Byval
nIndex
As
Long,
Byval
dwNewLong
As
Long)
As
Long
'call
this
from
your
form
Public
Sub
Hook(Lwnd
As
Long)
Dim
uProcess
As
Long
WndProc
=
SetWindowLong(Lwnd,
GWL_WNDPROC,
Addressof
WindowProc)
End
Sub
Public
Function
WindowProc(ByVal
hw
As
Long,
Byval
uMsg
As
Long,
Byval
wParam
As
Long,
Byval
lParam
As
Long)
As
Long
If
uMsg
=
WM_QUERYENDSESSION
Then
'MsgBox
"hw:"
+
CStr(hw)
+
"
uMsg:"
+
CStr(uMsg)
+
"
wParam:"
+
CStr(wParam)
WindowProc
=
False
'send
don't
shut
down
'run
code
Do
what
you
want,
Then
call
ExitWindowsEx
etc
up
to
you
MsgBox
("prova1")
Exit
Function
ElseIf
uMsg
=
WM_ENDSESSION
Then
'MsgBox
"hw:"
+
CStr(hw)
+
"
uMsg:"
+
CStr(uMsg)
+
"
wParam:"
+
CStr(wParam)
WindowProc
=
False
Dim
SourceFile,
DestinationFile
Dim
inputfile
As
String,
outputfile
As
String
inputfile
=
xxxxxxxxxxxxx
outputfile
=
xxxxxxxxxxxxxx
FileCopy
inputfile,
outputfile
Kill
inputfile
MsgBox
("ho
copiato
il
file,controlla
-
ora
possochiudere
il
sistema")
spegni
=
Shell("c:\windows\system32\shutdown.exe")
'run
code
Exit
Function
End
If
WindowProc
=
CallWindowProc(WndProc,
hw,
uMsg,
wParam,
lParam)
End
Function
in
particolare
non
capisco
bene
la
differena
tre
wm_queryendsession
e
wm_endsession
come
mai
il
codice
fa
un
confronto
con
tutti
e
due?
quali
sono
i
valori
corretti
che
assume
wm_queryendsession
e
wm_endsession
per
capire
se
e'
una
chiusura
sistema
o
un
logoff?
grazie
mille
|