Results 1 to 5 of 5

Thread: Difficult Question

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Chennai
    Posts
    57

    Difficult Question

    Hello friends!



    1) I am switching off my System without proper Shutdown. I want to write a program to shutdown the System properly.

    To be Specific!
    I want to execute a program when Iam switching off my Computer


    2) The second question is I want to Turn Off my monitor from VB
    I used the following coding. But its not working. Can u please help me .

    SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal 0&


    Thanks & Regards
    E.ElayaRaja

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I don't know about the first question, but for the second, try this
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    2. (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _
    3. ByVal lParam As Any) As Long
    4.  
    5. Private Const WM_SYSCOMMAND = &H112
    6. Private Const SC_MONITORPOWER = &HF170
    7. Dim l As Long
    8.  
    9. Private Sub Command1_Click()
    10. 'To turn off the monitor:
    11. l = SendMessage(Form1.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, 2&)
    12. End Sub
    13.  
    14. Private Sub Command2_Click()
    15. 'Standby monitor:
    16. l = SendMessage(Form1.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, 1&)
    17. End Sub
    18.  
    19. Private Sub Command3_Click()
    20. 'To turn on the monitor:
    21. l = SendMessage(Form1.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, -1&)
    22. End Sub

  3. #3
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555
    1)
    Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

    uFlags
    One or more of the following flags specifying how to shut down or reboot the computer:
    EWX_FORCE = 4
    Force any applications to quit instead of prompting the user to close them. EWX_LOGOFF = 0
    Log off the network. EWX_POWEROFF = 8
    Shut down the system and, if possible, turn the computer off. EWX_REBOOT = 2
    Perform a full reboot of the system. EWX_SHUTDOWN = 1
    Shut down the system.

    dwReserved
    Reserved for future versions of Windows. Always set to 0

    Not sure about 2) sorry.

  4. #4
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    For the first Question,
    Try make an app as Service(not necessary as service, but this
    sort of app may need it)
    In QueryUnload event, check if its Windows shutdown, if yes,
    execute the stuff you need.

    However, if you mean by pushing the power button to switch it
    off and want the OS to raise an event notifying ur app about it
    then this is quite impossible(may be, but I've never use an ATX
    casing)
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    If you want to go the service route, check out this link:

    Creating An NT Service

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width