Sponsored links

Go Back   MP3Car.com > Mp3Car Technical > General MP3Car Discussion


Reply
 
Share Thread Tools Display Modes
Old 07-15-2003, 12:43 PM   #1
Constant Bitrate
 
captain_jim1's Avatar
 
Join Date: Nov 2002
Location: New Jersey
Posts: 192
captain_jim1
Hibernate - Windows XP v Windows ME

Hey all -- I had written a small program that would detect whether or not a laptop was running on a battery on AC ... if it was on the battery it would display a message and go into hibernation mode...

It worked great on WinME .. but when I upgraded to XP it no longer functions. It will detect it's on the battery, but never goes into Hibernation. I have checked and Hibernation is enabled in the Display settings.

The program was written in visual basic... Thanks!

-Brad
83 mp320i 285k
captain_jim1 is offline   Reply With Quote
Advertisement
 
Advertisement
Sponsored links

Old 07-15-2003, 12:47 PM   #2
jol
FLAC
 
jol's Avatar
 
Join Date: Jan 2002
Location: Mellansel, Sweden
Posts: 1,299
jol is on a distinguished road
you're welcome.
__________________
-
My cars
-
jol is offline   Reply With Quote
Old 07-15-2003, 12:54 PM   #3
Registered User
 
osirisdon's Avatar
 
Join Date: Feb 2003
Location: South Florida
Posts: 686
osirisdon
Quote:
Originally posted by jol
you're welcome.

bwahahhahaha I laughed so hard at this. HILATIOUS!!

Although the author of the thread, I guess needs help from the programering gurus of these vast lands of information regarding MP3's a quick question??? shouldnt this go into the software section? sounds like software dont it???



osirisdon is offline   Reply With Quote
Old 07-15-2003, 01:50 PM   #4
Maximum Bitrate
 
CarComp's Avatar
 
Join Date: Oct 2001
Location: Indiana
Posts: 506
CarComp is on a distinguished road
Paste the following code into a module.

Call anywhere in your program by ...

ShutDown(shutdownmode)
where shutdownmode = one of the modes below


Code:
'These are your modes.... Public Const ShutDownComplete = 0 Public Const ShutDownHibernate = 1 Public Const ShutDownStandby = 2 Private Const EWX_LOGOFF = 0 Private Const EWX_SHUTDOWN = 1 Private Const EWX_REBOOT = 2 Private Const EWX_FORCE = 4 Private Const EWX_POWEROFF = 8 Private Const TOKEN_ADJUST_PRIVILEGES = &H20 Private Const TOKEN_QUERY = &H8 Private Const SE_PRIVILEGE_ENABLED = &H2 Private Const ANYSIZE_ARRAY = 1 Private Const VER_PLATFORM_WIN32_NT = 2 Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Type LUID LowPart As Long HighPart As Long End Type Type LUID_AND_ATTRIBUTES pLuid As LUID Attributes As Long End Type Type TOKEN_PRIVILEGES PrivilegeCount As Long Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES End Type Declare Function SetSuspendState Lib "powrprof.dll" (ByVal Hibernate As Long, ByVal ForceCritical As Long, ByVal DisableWakeEvent As Long) As Long Private Declare Function SetSystemPowerState Lib "kernel32" (ByVal fSuspend As Long, ByVal fForce As Long) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long Private Declare Function ExitWindowsEx Lib "User32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long 'Detect if the program is running under Windows NT Public Function IsWinNT() As Boolean Dim myOS As OSVERSIONINFO myOS.dwOSVersionInfoSize = Len(myOS) GetVersionEx myOS IsWinNT = (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT) End Function 'set the shut down privilege for the current application Private Sub EnableShutDown() Dim hProc As Long Dim hToken As Long Dim mLUID As LUID Dim mPriv As TOKEN_PRIVILEGES Dim mNewPriv As TOKEN_PRIVILEGES hProc = GetCurrentProcess() OpenProcessToken hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken LookupPrivilegeValue "", "SeShutdownPrivilege", mLUID mPriv.PrivilegeCount = 1 mPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED mPriv.Privileges(0).pLuid = mLUID ' enable shutdown privilege for the current application AdjustTokenPrivileges hToken, False, mPriv, 4 + (12 * mPriv.PrivilegeCount), mNewPriv, 4 + (12 * mNewPriv.PrivilegeCount) End Sub ' Shut Down NT Public Sub ShutDownNT(force As Boolean) Dim ret As Long Dim flags As Long flags = EWX_POWEROFF If force Then flags = flags + EWX_FORCE If IsWinNT Then EnableShutDown ExitWindowsEx flags, 0 End Sub 'Restart NT Public Sub RebootNT(force As Boolean) Dim ret As Long Dim flags As Long flags = EWX_REBOOT If force Then flags = flags + EWX_FORCE If IsWinNT Then EnableShutDown ExitWindowsEx flags, 0 End Sub 'Log off the current user Public Sub LogOffNT(force As Boolean) Dim ret As Long Dim flags As Long flags = EWX_LOGOFF If force Then flags = flags + EWX_FORCE ExitWindowsEx flags, 0 End Sub Public Sub ShutDown9X(force As Boolean) On Error GoTo ShutDown9X_Err Dim flags As Long flags = EWX_POWEROFF If force Then flags = flags + EWX_FORCE ExitWindowsEx flags, 0 Exit Sub ShutDown9X_Err: msgbox "Error occured in Shutdown Module" End Sub Public Sub ShutDown(byval SDMode as long) 'Kill winamp If WinAMP_FindWindow Then WinAMP_SendCommandMessage WA_STOP WinAMP_ClearPlaylist WinAMP_SendCommandMessage WA_CLOSE End If Select Case SDMode Case ShutDownComplete If IsWinNT Then ShutDownNT (True) Else ShutDown9X (True) End If Case ShutDownHibernate 'Go into hibernate, force it, but don't disable wake events 'this may need work, I dont know what these wake events are... SetSuspendState 1, 1, 0 Case ShutDownStandby 'enable the shutdown privilege EnableShutDown 'on Windows2000: hibernate 'on Windows9x/ME: suspend SetSystemPowerState True, True 'SetSystemPowerState False, False End Select End Sub

__________________
Get MediaEngine !!!
Media Engine Download
CarComp is offline   Reply With Quote
Old 07-15-2003, 06:53 PM   #5
Constant Bitrate
 
captain_jim1's Avatar
 
Join Date: Nov 2002
Location: New Jersey
Posts: 192
captain_jim1
Thanks CarComp .. I'll try that out later tonight..

-Brad
__________________
-Brad
83 mp320i
99 mp323i
_________

7" Lilliput w/Touch, 150 W Opus, 2.4ghz P4 533fsb, 512 DDR 333mhz, GPS, WiFi Inet, 40g Maxtor 7200rpm, Laptop DVD/CD-RW w/USB2.0 Bridge, WinXP Pro.
captain_jim1 is offline   Reply With Quote
Sponsored links
Advertisement
 
Advertisement
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




All times are GMT -5. The time now is 12:34 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2
Copyright © 1999 - 2008 Mp3Car.com Inc.Ad Management by RedTyger
Message Board Statistics