• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

Force Windows Reboot

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
_punisher
Asked:
_punisher
  • 10
  • 9
1 Solution
 
shaigCommented:
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
 
_punisherAuthor Commented:
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
 
trestanCommented:
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
_punisherAuthor Commented:
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
 
trestanCommented:
Use EnumWindows((WNDENUMPROC)EnumWindowsProc, 0);  can correct the problem.

0
 
_punisherAuthor Commented:
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
 
trestanCommented:
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
 
_punisherAuthor Commented:
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
 
trestanCommented:
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
 
_punisherAuthor Commented:
Ok ... I´ll give it a try ... but if you have any news for me, please tell me !
0
 
trestanCommented:
Define the member function as: static void CALLBACK.
0
 
_punisherAuthor Commented:
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
 
trestanCommented:
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
 
_punisherAuthor Commented:
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
 
_punisherAuthor Commented:
Ok ... I solved the problem ... thanks for your help !
0
 
trestanCommented:
Would you mind tell me what is the problem? I am a little curious about what has happened. Thx.
0
 
_punisherAuthor Commented:
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
 
trestanCommented:
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
 
trestanCommented:
Sorry, it should be WNetCancelConnection to disconnect a resource, not the contrarial WNetAddConnection.
0
 
_punisherAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now