Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A few simple questions
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Acid




PostPosted: Wed Jun 02, 2004 2:34 pm   Post subject: A few simple questions

These may not seem hard, but I've had nobody to teach me and nobody else to ask.

Is it possible to make my program shut down the computer, and how?

How can I make the program open the CD-ROM drive of my computer?
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Wed Jun 02, 2004 4:54 pm   Post subject: (No subject)

I don't know anything about VB, but this might help u
http://www.vb-helper.com/howto_shutdown_exitwindowsex.html
for shutdown
and
for opening CD rom drive
http://www.freevbcode.com/ShowCode.asp?ID=68
Brightguy




PostPosted: Wed Jun 02, 2004 5:18 pm   Post subject: Re: A few simple questions

Yep, after a quick search for API fucntions, I came up with:
ExitWindowsEx
mciSendString

code:
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Private Const EWX_LOGOFF = 0
Private Const EWX_REBOOT = 2
Private Const EWX_SHUTDOWN = 1
Private Const EWX_FORCE = 4

Private Sub cmdShutDown_Click()
    Dim lngShutDown As Long, intConfirm As Integer
    intConfirm = MsgBox("Shut down computer?", vbOKCancel)
    If intConfirm = vbOK Then lngShutDown = ExitWindowsEx(EWX_SHUTDOWN, 0&)
End Sub

Private Sub cmdOpen_Click()
    Call mciSendString("Set CDAudio Door Open Wait", 0&, 0&, 0&)
End Sub

Private Sub cmdClose_Click()
    Call mciSendString("Set CDAudio Door Closed Wait", 0&, 0&, 0&)
End Sub
Acid




PostPosted: Thu Jun 03, 2004 9:49 am   Post subject: (No subject)

Thanks a bunch.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: