Click here to Skip to main content
15,920,576 members
Home / Discussions / C#
   

C#

 
GeneralRe: Modeless dialog issue Pin
aei_totten20-Apr-10 2:11
aei_totten20-Apr-10 2:11 
GeneralRe: Modeless dialog issue Pin
aei_totten20-Apr-10 3:33
aei_totten20-Apr-10 3:33 
GeneralRe: Modeless dialog issue Pin
Richard Blythe20-Apr-10 5:48
Richard Blythe20-Apr-10 5:48 
GeneralRe: Modeless dialog issue Pin
aei_totten20-Apr-10 6:11
aei_totten20-Apr-10 6:11 
GeneralRe: Modeless dialog issue Pin
Richard Blythe20-Apr-10 7:10
Richard Blythe20-Apr-10 7:10 
GeneralRe: Modeless dialog issue Pin
aei_totten20-Apr-10 7:31
aei_totten20-Apr-10 7:31 
GeneralRe: Modeless dialog issue Pin
Richard Blythe20-Apr-10 8:00
Richard Blythe20-Apr-10 8:00 
QuestionEject a remote computers CD rom Pin
Jacob Dixon19-Apr-10 7:46
Jacob Dixon19-Apr-10 7:46 
I was wondering if it was possible to eject USB and CD roms drives of a remote computer? I have seen code out there for local machines, but nothing really remote.

I have tried this one for a remote that I found:

const int OPEN_EXISTING = 3;
const uint GENERIC_READ = 0x80000000;
const uint GENERIC_WRITE = 0x40000000;
const uint IOCTL_STORAGE_EJECT_MEDIA = 2967560;

[DllImport("kernel32")]
private static extern IntPtr CreateFile
    (string filename, uint desiredAccess,
     uint shareMode, IntPtr securityAttributes,
     int creationDisposition, int flagsAndAttributes,
     IntPtr templateFile);

[DllImport("kernel32")]
private static extern int DeviceIoControl
    (IntPtr deviceHandle, uint ioControlCode,
     IntPtr inBuffer, int inBufferSize,
     IntPtr outBuffer, int outBufferSize,
     ref int bytesReturned, IntPtr overlapped);

[DllImport("kernel32")]
private static extern int CloseHandle(IntPtr handle);

public static void EjectMedia(string computer, char driveLetter)
{
    string path = "\\\\" + computer + "\\" + driveLetter + ":";
    IntPtr handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0,
                               IntPtr.Zero, OPEN_EXISTING, 0,
                               IntPtr.Zero);
    if ((long)handle == -1)
    {
        throw new IOException("Unable to open drive " + driveLetter);
    }
    int dummy = 0;
    DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0,
                    IntPtr.Zero, 0, ref dummy, IntPtr.Zero);
    CloseHandle(handle);
}


But have had no luck with it...
AnswerRe: Eject a remote computers CD rom Pin
Dave Kreskowiak19-Apr-10 10:29
mveDave Kreskowiak19-Apr-10 10:29 
GeneralRe: Eject a remote computers CD rom Pin
Jacob Dixon19-Apr-10 12:40
Jacob Dixon19-Apr-10 12:40 
GeneralRe: Eject a remote computers CD rom Pin
Luc Pattyn19-Apr-10 12:59
sitebuilderLuc Pattyn19-Apr-10 12:59 
GeneralRe: Eject a remote computers CD rom Pin
Dave Kreskowiak19-Apr-10 14:01
mveDave Kreskowiak19-Apr-10 14:01 
Questionwhy move using statement into namespace? [modified][Solved] Pin
yu-jian19-Apr-10 6:33
yu-jian19-Apr-10 6:33 
AnswerRe: why move using statement into namespace? [modified] Pin
dan!sh 19-Apr-10 6:56
professional dan!sh 19-Apr-10 6:56 
GeneralRe: why move using statement into namespace? Pin
PIEBALDconsult19-Apr-10 7:19
mvePIEBALDconsult19-Apr-10 7:19 
GeneralRe: why move using statement into namespace? Pin
yu-jian20-Apr-10 6:52
yu-jian20-Apr-10 6:52 
AnswerRe: why move using statement into namespace? Pin
Luc Pattyn19-Apr-10 7:00
sitebuilderLuc Pattyn19-Apr-10 7:00 
GeneralRe: why move using statement into namespace? Pin
dan!sh 19-Apr-10 7:03
professional dan!sh 19-Apr-10 7:03 
AnswerRe: why move using statement into namespace? [modified] Pin
PIEBALDconsult19-Apr-10 7:16
mvePIEBALDconsult19-Apr-10 7:16 
Questionhashtable or Dictionary! Pin
Jassim Rahma19-Apr-10 5:36
Jassim Rahma19-Apr-10 5:36 
AnswerMessage Removed Pin
19-Apr-10 5:48
professionalN_tro_P19-Apr-10 5:48 
GeneralRe: hashtable or Dictionary! Pin
Jassim Rahma19-Apr-10 9:16
Jassim Rahma19-Apr-10 9:16 
AnswerRe: hashtable or Dictionary! Pin
PIEBALDconsult19-Apr-10 5:54
mvePIEBALDconsult19-Apr-10 5:54 
GeneralRe: hashtable or Dictionary! Pin
Anindya Chatterjee19-Apr-10 6:08
Anindya Chatterjee19-Apr-10 6:08 
GeneralRe: hashtable or Dictionary! Pin
PIEBALDconsult19-Apr-10 6:23
mvePIEBALDconsult19-Apr-10 6:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.