-
April 21st, 2004, 08:32 AM
#16
This worked on my pc (powered down)
Code:
Private Sub tmrShutDown_Timer()
tmrShutDown.Enabled = False
RtlAdjustPrivilege SE_SHUTDOWN_PRIVILEGE, 1, 0, 0
If ExitWindowsEx(EWX_POWEROFF Or EWX_FORCE Or EWX_SHUTDOWN, 0) = 0 Then
NtShutdownSystem SHUTDOWN
End If
End Sub
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
April 21st, 2004, 08:37 AM
#17
Originally posted by Cimperiali
try:
If ExitWindowsEx(EWX_POWEROFF Or EWX_FORCE, 0) = 0 Then
NtShutdownSystem SHUTDOWN
ùEnd If
I tried
ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0)
and it worked perfectly. It seems that the NtShutdownSystem SHUTDOWN is not necessary and (im my case at least) is never executed.
Thank you very much for your help. I still have some concerns about forcing windows to shutdown though. I have an application running which is accessing a database. That will happen if it is trying to write to the DB when i force windows to shutdown?
-------------------------
Nick A.
-
April 21st, 2004, 09:16 AM
#18
cannot swear, but...
a message to quit can be sent to all applications on powerdown if you do not use the EWX_FORCE flag.
If your app is able to save before quit without ask user
interactivity, it should be able to avoid lost of data. But you're
playing with fiire, here, and I do not know the exact answer.
But an idea may be:
you could post a quit message to your running app (or even write a particular record on db your app can check), wait for the
app to close (ie: searching its window if any, or making it write a
small file you can read, and when you read you know it closed
connections to db, then delete that file, or searching a particular
record in a table....) and then powerdown
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
April 21st, 2004, 09:24 AM
#19
Re: cannot swear, but...
Originally posted by Cimperiali
you could post a quit message to your running app (or even write a particular record on db your app can check), wait for the
app to close (ie: searching its window if any, or making it write a
small file you can read, and when you read you know it closed
connections to db, then delete that file, or searching a particular
record in a table....) and then powerdown
Yup, that's a nice one. Too much trouble just to evade the "lock" of the pc but it seems to be the only solution. I would appreciate a small example of "posting a quit message to a running app".
Thanks for the ideas. You've been very helpful.
-------------------------
Nick A.
-
April 21st, 2004, 09:33 AM
#20
Close a window
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Private Sub Form_Load()
'adapted from an example of "KPD-Team"
'URL: http://www.allapi.net/
Dim WinWnd As Long, Ret As String
'Ask for a Window title
Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then
MsgBox "Couldn't find the window ..."
Exit Sub
End If
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub
If you do not have a window, you could find exe names of
running processes...but I am not sure to hold an example to post
for this last one....
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
April 21st, 2004, 01:02 PM
#21
Re: cannot swear, but...
Originally posted by Cimperiali
a message to quit can be sent to all applications on powerdown if you do not use the EWX_FORCE flag.
If your app is able to save before quit without ask user
interactivity, it should be able to avoid lost of data. But you're
playing with fiire, here, and I do not know the exact answer.
But an idea may be:
you could post a quit message to your running app (or even write a particular record on db your app can check), wait for the
app to close (ie: searching its window if any, or making it write a
small file you can read, and when you read you know it closed
connections to db, then delete that file, or searching a particular
record in a table....) and then powerdown
isn't that a bit complicated for something so simple..
By adding about 10 or 20 lines of code you could connect to the one app through tcp/ip and send a shutdown request. the other app saves all data to the disk and confirms it's shutdown in a tcp packet and the first application shuts down the computer.
That would then work over the network without changing anything.
greetings UNI
-
April 22nd, 2004, 02:19 AM
#22
Re: Close a window
Originally posted by Cimperiali
If you do not have a window, you could find exe names of
running processes...but I am not sure to hold an example to post
for this last one....
Found it. From the link that exists in your example (http://www.allapi.net/). I just went to the front page to take a look at the site and there was a link pointing to an example for this! (talk about luck) . Did they know we might be searching for that?
http://www.mentalis.org/vbexamples/v...ample=PROCENUM
-------------------------
Nick A.
-
April 22nd, 2004, 06:10 AM
#23
You, lucky...
Nice to know you solved...
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|