Thread: Help on opening drives

  1. #1
    Unregistered
    Guest

    Question Help on opening drives

    i was making a convenience program to open my D and E drives, what would the code be to do these tasks, and is there a way to make the program run and exit its self withouth having to hit a button? thanks alot

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Would this be for a trojan of somesorts? It's not as if those buttons are that hard to press. The power button is way harder, because it is more springy, the CD buttons are just little objongs you have to tap. And making the drive go in is even easier, you just push it. You can also right click on the D drive in my computer and select eject.

  3. #3
    Unregistered
    Guest
    no no i am using it because my d drive broke, it will not open manually using the open button, i need the use the windows cd player to open it and it gets to be annoying, and i just wanted to hit the button so it runs the program and opens it, then the program closes, so if anyone can help that would be great

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    This code doesn't work for me, could work for you..
    Code:
    #define STRICT 
    #include <windows.h>
    #include <mmsystem.h>
    
    int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int ) 
    { 
    // first find CD-ROM drive 
    CHAR cCDRom = 'A'; 
    CHAR szCDRomRoot[ 4 ]; 
    while( cCDRom <= 'Z' ) 
    { 
    wsprintf( szCDRomRoot, "%c:", cCDRom ); 
    if( ( GetDriveType( szCDRomRoot ) & DRIVE_CDROM ) == DRIVE_CDROM ) 
    break; 
    else 
    cCDRom++; 
    } 
     
    if( cCDRom > 'Z' ) 
    return 1; // apparently no CD-ROM on this machine! 
     
    // open the CD-ROM 
    MCI_OPEN_PARMS mop; 
    memset( &mop, 0, sizeof( mop ) ); 
    mop.lpstrDeviceType = (LPTSTR) MCI_DEVTYPE_CD_AUDIO; 
    mop.lpstrElementName = szCDRomRoot; 
    mop.lpstrAlias = ""; 
    MCIERROR ret = mciSendCommand( 0, 
    MCI_OPEN, 
    MCI_WAIT | 
    MCI_OPEN_TYPE | 
    MCI_OPEN_ELEMENT | 
    MCI_OPEN_TYPE_ID | 
    MCI_OPEN_SHAREABLE, 
    (DWORD) &mop ); 
    if( ret != 0 ) 
    return 1; // could not open for some reason 
     
    // open shop 
    MCI_SET_PARMS msp; 
    memset( &msp, 0, sizeof( msp ) ); 
    mciSendCommand( mop.wDeviceID, 
    MCI_SET, MCI_WAIT | 
    MCI_SET_DOOR_OPEN, 
    (DWORD) &msp ); 
     
    // close shop 
    memset( &msp, 0, sizeof( msp ) ); 
    mciSendCommand( mop.wDeviceID, 
    MCI_SET, MCI_WAIT | 
    MCI_SET_DOOR_CLOSED, 
    (DWORD) &msp ); 
     
    // clean-up 
    MCI_GENERIC_PARMS mgp; 
    memset( &mgp, 0, sizeof( mgp ) ); 
    mciSendCommand( mop.wDeviceID, 
    MCI_CLOSE, 
    MCI_WAIT, 
    (DWORD) &mgp ); 
     
    return 0; 
    }

  5. #5
    Unregistered
    Guest
    yeah i am getting 3 errors on that, one of which was 2 unresolved externals...

  6. #6
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    What compiler do you use?

  7. #7
    Unregistered
    Guest
    microsoft visual c++ 6.0

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    Wink opening cd tray from dialog...sample

    This worked for me... check out the sample

    just make sure you include the proper headers and the file

    winmm.lib through your project settings if you are using VC++..

    Code:
    //** mci files for access to cd drive
    //** insure to include the winmm.lib in the links tab of the project settings
    #include "mmsystem.h"
    #include "vfw.h"
    
    
    void CCupHolderDlg::OnButton1() 
    {
    
    	MCIERROR i = mciSendString("open cdaudio alias cd2", 0, 0, 0);
    	
    	if( i )
    		ShowError( (DWORD)i );
    
    
    	MCIERROR error = mciSendString("set cd2 door open wait", 0, 0, 0);
    
    	if( error )
    		ShowError( error );
    
    
    //	::Sleep( 3000 );
    //	error = mciSendString("set cd2 door closed wait", 0, 0, 0);
    
    	if( error )
    		ShowError( error );
    
    	error = mciSendString("close cd2", 0, 0, 0);
    	if( error )
    		ShowError( error );
    
    	Invalidate( FALSE );
    
    }
    any feedback is appreciated....
    zMan

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    223
    O by the way uncomment the lines
    Code:
    //	::Sleep( 3000 );
    //	error = mciSendString("set cd2 door closed wait", 0, 0, 0);
    to have it close the tray...
    zMan

  10. #10
    Unregistered
    Guest
    just make sure you include the proper headers and the file

    winmm.lib through your project settings if you are using VC++..

    -
    that is what is getting my right there, were do i need to add that in?

  11. #11
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Project -> Settings (Alt + F7) -> Link -> Object/Library Modules
    Add winmm.lib to the textbox.

  12. #12
    Unregistered
    Guest
    alright thanks it works great!

  13. #13
    Registered User
    Join Date
    Feb 2002
    Posts
    98

    help on opening drives

    ok, that is nice, now how would you do that on a network drive?im on the server machine and the other computer hooked to it is networked

  14. #14
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    LoL
    are you trying to open someone's drive at school to freak them out or something?

  15. #15
    Registered User
    Join Date
    Feb 2002
    Posts
    98

    help on opening drives

    thanks for the idea okiesmokie lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Determine drives attached
    By niqo in forum Windows Programming
    Replies: 2
    Last Post: 10-05-2007, 09:49 AM
  2. need help with file opening errors
    By lld4rkll in forum C++ Programming
    Replies: 6
    Last Post: 07-13-2006, 06:20 AM
  3. USB Drives???
    By khpuce in forum Tech Board
    Replies: 14
    Last Post: 12-12-2003, 09:01 AM
  4. installing hard drives and IDE cables...
    By dbaryl in forum Tech Board
    Replies: 14
    Last Post: 09-02-2002, 10:11 AM
  5. Probs with CD drives
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 03-11-2002, 11:09 AM