Solved

Force Windows Reboot

Posted on 1998-07-15
20
469 Views
Last Modified: 2013-11-20
I use the function ExitWindowsEx to reboot my computer. Everything works just fine except for the fact that if I try to force a reboot (EWX_FORCE | EWX_REBOOT )my system does shutdown but not reboot... it simply hangs up at a certain point after the shutdown is already done. What can I do ? (This only happens with Win95; with WinNT it works !!)
 
0
Comment
Question by:_punisher
  • 10
  • 9
20 Comments
 
LVL 3

Expert Comment

by:shaig
ID: 1319189
Check if your system can reboot normally. this means through the shutdown menu.
if not succesful - the problem is in your 95 installation.
if succesful - i just tried to help :-)
0
 

Author Comment

by:_punisher
ID: 1319190
nop ... as I already mentioned ... it can reboot also with my program ! It only does not work with EWX_FORCE !
But thanx for trying to help ...
0
 
LVL 8

Accepted Solution

by:
trestan earned 150 total points
ID: 1319191
You can use the Win32 API ExitWindowsEx() on Windows NT to force a logoff. You accomplish this by combining the EWX_LOGOFF and EWX_FORCE flags. Unfortunately, this combination is not supported on Windows 95. Pls refer to MS online support for more information:
http://support.microsoft.com/support/kb/articles/q168/6/90.asp
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:_punisher
ID: 1319192
I get the following error when I try to compile the sourcecode I found on the Homepage you gave me. I use Visual C++ 5.0 and I have already experienced this problem before. I did not find it in Visual C++ 4.1.

Sorry ... I have a German Compiler!
It says: Conversion of parameter 1 from ... to ... not possible.

error C2664: 'EnumWindows' : Konvertierung des Parameters 1 von 'int (struct HWND__ *,unsigned long)' in 'int (__stdcall *)(struct HWND__ *,long)' nicht moeglich

What do I have to do ?
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319193
Use EnumWindows((WNDENUMPROC)EnumWindowsProc, 0);  can correct the problem.

0
 

Author Comment

by:_punisher
ID: 1319194
That does not work either. Now I get the following message:

error C2440: 'type cast' : 'ueberladener Funktionstyp' kann nicht in 'int (__stdcall *)(struct HWND__ *,long)' konvertiert werden
Keine Funktion mit diesem Namen im Gueltigkeitsbereich stimmt mit dem Zieltyp ueberein

I hope you understand this compiler message because it is difficult to translate.
I`ll give it a try:
overloaded functiontype ... cannot be converted into ...

No function with this name in the valid range is identical to the destination type.

0
 
LVL 8

Expert Comment

by:trestan
ID: 1319195
This paragraph of file compiles fine on my machine (NT, VC5). You set the output setting to windows, right? WNDENUMPROC is the parameter type. Sould be no problem. Or would you like me to email my exe file?
0
 

Author Comment

by:_punisher
ID: 1319196
Thank you...but I need the sourcecode because it is a part of a larger program.
What do you mean by setting the output setting to windows ?
I use Win95 and have the ServicePack3 for VisualC++5.0.
I have this problem with callback functions in general (cf.TimerProc(SetTimer)). Is it Ok that in my SourceCode this CallbackFunction is part of a class:
CShutdownDlg::EnumWindowsProc ?
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319197
I prefer you try the codes in a seperate project to see whether it is your desired. When the callback function is a member function of a class, it will be more complicated. Seems that it should be defined as static function. But I need to try it.
0
 

Author Comment

by:_punisher
ID: 1319198
Ok ... I´ll give it a try ... but if you have any news for me, please tell me !
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319199
Define the member function as: static void CALLBACK.
0
 

Author Comment

by:_punisher
ID: 1319200
My compiler says that member functions must not be static. It does not change anything concerning this __stdcall. I also get this message when I do not use classes (as in the sample).
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319201
I think there are some problems with your compiler. At least, no thing wrong when a function is declared as static. Compilation is really Ok after I add WNDENUMPROC. Can you try it on a NT? Nothing to do with the codes now. Change the project settings, link, in Project Options: subsystem:windows . However, this should not be the problem according to the error message.
0
 

Author Comment

by:_punisher
ID: 1319202
Somehow I need a solution for this problem ... would you mind if I reopen the question to other experts because I do not have enough points to ask a new question ...
0
 

Author Comment

by:_punisher
ID: 1319203
Ok ... I solved the problem ... thanks for your help !
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319204
Would you mind tell me what is the problem? I am a little curious about what has happened. Thx.
0
 

Author Comment

by:_punisher
ID: 1319205
Yes of course. You suggested to declare the function as static void. That did not work. Instead I declared it like this:

static BOOL CALLBACK EnumWindowsProc(HWND hwnd,long lParam);

and in the implementation part I left it as it was. What I don`t understand is the fact that it did not work as described on the Homepage you gave me when I used a new Win32 application.
Well but I am happy that it works now.

But there is still another problem and perhaps you have an idea. I told you that I wanted to force a reboot and with your help it almost works. Unless there are no remote connections there is no problem but as soon as there are any, this stupid message "there are x computers conected to you" appears when I execute my program. Do you know the command to disconnect those computers before I shutdown ? It has to do the same that netwatch does (disconnect user). Please ... can you help ?
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319206
So it is not a big error, just ignorance in some sense. Since you said your compiler does not even allow to declare a static function, I think it is mainly the compiler problem. I did not check the return type of the function. Anyway, it is a general ignorance in programming.
As of your question, actually I think it is worth to open a new question. I think you can use WNetOpenEnum to start WNetEnumResource to continue the enumeration of resources on the network and enumeration of currently connected resources. Then use WNetAddConnection to disconnect each of them. WNetCloseEnum to stop the enumeration. Hope it is helpful.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319207
Sorry, it should be WNetCancelConnection to disconnect a resource, not the contrarial WNetAddConnection.
0
 

Author Comment

by:_punisher
ID: 1319208
I managed to solve the problem of disconnecting all remote computers from mine by using NetSessionEnum and NetSessionDel but when I tried the whole program on another computer it did not work because some task where not closed and I had to terminate them. Actually I thaught this problem would not appear with your sourcecode since this was the main reason for me to ask this question.Do you have any ideas why the sourcecode you gave me does not close all the tasks ? I really do need code that closes all tasks because I am not on my computer when the program runs so I cannot manually kill any tasks. Please help me.

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 94
Get filename and folder into excel 7 79
building a service to accessed via telnet client, want colors ? 4 92
Not needed 13 119
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question