|
-
Jul 19th, 2005, 10:48 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Restart computer
I am trying to restart the user's computer, and I don't know which to use, ExitWindowsEx or Shell (Shutdown.exe -t 0 -r). I tried using:
VB Code:
ExitWindowsEx (EWX_Force And EWX_Reboot, 0&)
but that didn't work. 
What should I do?
Thank you,
Sir Loin
Last edited by Sir Loin; Jul 20th, 2005 at 08:30 AM.
-
Jul 20th, 2005, 01:06 AM
#2
Re: Restart computer
To shutdown the PC without shelling shutdown.exe your process must have the appropriate permissions set. It works when you use shutdown.exe because it is a separate process that has the permissions to shiut down the system.
-
Jul 20th, 2005, 01:32 AM
#3
Lively Member
Re: Restart computer
Try
VB Code:
Shell ("C:\Windows\System32\CMD.exe /C shutdown -r -t 45 -c "See you soon"), vbHide
The above is broken down like this
-r = Restart
-t = The time in seconds before computer restarts
-c = What ever comment you want
this just sends a command to the cmd
hope that helps
I'm not a pain in the ass, Im just making things intresting......
-
Jul 20th, 2005, 01:44 AM
#4
Re: Restart computer
There is no need to shell cmd.exe because you can shell shutdown.exe directly 
Also, he knows how to do it that way, he is asking for a better way
Last edited by penagate; Jul 20th, 2005 at 01:57 AM.
Reason: Somehow managed to turn "shutdown" into profanity. Whoops.
-
Jul 20th, 2005, 02:16 AM
#5
Thread Starter
Fanatic Member
Re: Restart computer
If I shell shutdown.exe, it will only work on WinXP computers, right? I need to restart older versions of Windows as well... 
Thank You,
Sir Loin
-
Jul 20th, 2005, 02:25 AM
#6
Re: Restart computer
If you don't mind showing the shutdown dialog?
VB Code:
Declare Function SHShutDownDialog Lib "shell32" Alias "#60" ( _
ByVal IDontKnowWhatOnEarthThisDoes As Long _
) As Long
' Show the Shutdown dialog box
SHShutDownDialog 0&
Otherwise, since on 9x based OS's I don't believe there is a process permissions model, you could try shutdown.exe on Win2k+ OS's and ExitWindowsEx on Win 95+ OS's,
-
Jul 20th, 2005, 07:43 AM
#7
Thread Starter
Fanatic Member
Re: Restart computer
Here is my restart code, it seems to work well, but i'm not sure if it will work on older OS's.
VB Code:
Private Sub RestartComputer()
On Error Resume Next
Shell "Shutdown.exe -t 0 -r"
Call ExitWindowsEx(EWX_REBOOT, 0&)
End Sub
Since shelling "Shutdown.exe -t 0 -r" would probably error on older OS's I just put an "On Error Resume Next".
For non XP systems (95/98) try
VB Code:
ExitWindowsEx (EWX_LogOff Or EWX_FORCE), &HFFFF
That's the problem, I don't know which OS the user is using... 
Thank you,
Sir Loin
-
Jul 20th, 2005, 07:11 AM
#8
Re: Restart computer
 Originally Posted by Sir Loin
I am trying to restart the user's computer, and I don't know which to use, ExitWindowsEx or Shell ( Shutdown.exe -t 0 -r). I tried using:
VB Code:
ExitWindowsEx (EWX_Force And EWX_Reboot, 0&)
but that didn't work.
What should I do?
Thank you,
Sir Loin
For non XP systems (95/98) try
VB Code:
ExitWindowsEx (EWX_LogOff Or EWX_FORCE), &HFFFF
-
Jul 20th, 2005, 07:47 AM
#9
Re: Restart computer
Use GetVersionEx().
VB Code:
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (_
ByRef lpVersionInformation As OSVERSIONINFO _
) As Long
' Get OS version
Dim udtOSVer As OSVERSIONINFO
udtOSVer.dwOSVersionInfoSize = Len(udtOSVer)
GetVersionEx udtOSVer
' And then use (udtOSVer.dwMajor >= 5) to determine if you can call shutdown.exe.
-
Jul 20th, 2005, 07:58 AM
#10
Thread Starter
Fanatic Member
Re: Restart computer
Oh... I was thinking about using GetVersionEx, but I was getting the platform, and if it returned 2 then that was NT, and I think Win2000, XP, and ME are all WinNT OS's.
Thanks a lot!
-Sir Loin
-
Jul 20th, 2005, 08:33 AM
#11
Thread Starter
Fanatic Member
Re: Restart computer
I have 1 final question. Is Win95's major build number 1, and 98's 2 and so on...?
Thanks,
Sir Loin
-
Jul 20th, 2005, 08:41 AM
#12
Re: Restart computer
No, the version numbers go like this
Edit: Major.Minor.Build
Win 95 - 4.00.xxx
Win 98 - 4.01
Win 2K - 5.00
Win XP - 5.1
As for NT, I believe shutdown.exe exists on all NT from 4 up (maybe). But the NT version numbers are obvious anyway. There are also platform constants you can use with .dwPlatformID, if you search GetVersionEx on MSDN you should be able to find these.
-
Jul 20th, 2005, 08:58 AM
#13
Thread Starter
Fanatic Member
Re: Restart computer
Oh, thank you for ALL of your help! 
-Sir Loin
Last edited by Sir Loin; Jul 20th, 2005 at 09:57 AM.
-
Jul 20th, 2005, 09:14 AM
#14
Re: Restart computer
No worries
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
|