Click here to Skip to main content
15,900,254 members
Home / Discussions / C#
   

C#

 
GeneralRe: .loadXml throwing exception Pin
illuminatisucks27-Aug-09 8:04
illuminatisucks27-Aug-09 8:04 
GeneralRe: .loadXml throwing exception Pin
PIEBALDconsult27-Aug-09 8:08
mvePIEBALDconsult27-Aug-09 8:08 
GeneralRe: .loadXml throwing exception Pin
Ian Shlasko27-Aug-09 8:02
Ian Shlasko27-Aug-09 8:02 
GeneralRe: .loadXml throwing exception Pin
illuminatisucks27-Aug-09 8:11
illuminatisucks27-Aug-09 8:11 
GeneralRe: .loadXml throwing exception Pin
illuminatisucks27-Aug-09 8:38
illuminatisucks27-Aug-09 8:38 
GeneralRe: .loadXml throwing exception Pin
harold aptroot27-Aug-09 8:44
harold aptroot27-Aug-09 8:44 
GeneralRe: .loadXml throwing exception Pin
illuminatisucks27-Aug-09 8:48
illuminatisucks27-Aug-09 8:48 
QuestionPreventing the user from Ejecting the CD during crucial Process. [modified] Pin
tyranin27-Aug-09 6:30
tyranin27-Aug-09 6:30 
Hi everyone, I am currently looking for a solution to prevent a user from opening the CD drive during a cruicial burning process. I think I'm close, like real close but the last hurdle is keeping me back.

I've found the right api for the job, but it's unmanaged in C++ and porting to C# is real tricky. So essentially that is the answer I am after.

I've figured out that at some point my solution involves: IOCTL_STORAGE_EJECT_CONTROL and PREVENT_MEDIA_REMOVAL, being used with the function DeviceIoControl()

I have these snippets which I have edited into my code.

/// <summary>DeviceIoControl uses IOCTL_STORAGE_EJECT_CONTROL</summary>
[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool DeviceIoControl(
    IntPtr hDevice,
    uint dwIoControlCode,
    ref long InBuffer,
    int nInBufferSize,
    ref long OutBuffer,
    int nOutBufferSize,
    ref int pBytesReturned,
    [In] ref NativeOverlapped lpOverlapped);

/// <summary>AIDS THE USE OF IOCTL_STORAGE_EJECT_CONTROL</summary>
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateFile(
    string fileName,
    [MarshalAs(UnmanagedType.U4)] FileAccess fileAccess,
    [MarshalAs(UnmanagedType.U4)] FileShare fileShare,
    IntPtr securityAttributes,
    [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
    int flags,
    IntPtr template);

private void SomethingMethod()
{
    IntPtr tHandle = CreateFile(@"\\.\" + destVolume, FileAccess.Read, FileShare.ReadWrite, IntPtr.Zero,
        FileMode.Open, 0, IntPtr.Zero);

    Bool success = DeviceIoControl(something, IOCTL_STORAGE_EJECT_CONTROL, something, something,    
        something, and so on);
}


I'm sure most of you will recognise that I am importing the dll libraries but the issue I am having is the Structure or Enums (I'm not quite which which is which) as I believe that IOCTL_STORAGE_EJECT_CONTROL and PREVENT_MEDIA_REMOVAL are stored as 'structs' somewhere.

So in brief, all I need to know are what parameters I need to pass to DeviceIoControl to stop the drive from ejecting.

Many Thanks.

modified on Friday, August 28, 2009 4:18 AM

AnswerRe: Preventing the user from Ejecting the CD during crucial Process. Pin
Luc Pattyn27-Aug-09 7:25
sitebuilderLuc Pattyn27-Aug-09 7:25 
AnswerRe: Preventing the user from Ejecting the CD during crucial Process. Pin
DaveyM6927-Aug-09 7:51
professionalDaveyM6927-Aug-09 7:51 
AnswerRe: Preventing the user from Ejecting the CD during crucial Process. Pin
PIEBALDconsult27-Aug-09 7:56
mvePIEBALDconsult27-Aug-09 7:56 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process. Pin
Dan Neely27-Aug-09 8:25
Dan Neely27-Aug-09 8:25 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process. Pin
PIEBALDconsult27-Aug-09 8:34
mvePIEBALDconsult27-Aug-09 8:34 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process. Pin
Dan Neely27-Aug-09 8:51
Dan Neely27-Aug-09 8:51 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process. Pin
PIEBALDconsult27-Aug-09 9:12
mvePIEBALDconsult27-Aug-09 9:12 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process. Pin
Dan Neely27-Aug-09 9:35
Dan Neely27-Aug-09 9:35 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process. Pin
tyranin27-Aug-09 22:28
tyranin27-Aug-09 22:28 
AnswerRe: Preventing the user from Ejecting the CD during crucial Process. PinPopular
DaveyM6927-Aug-09 8:58
professionalDaveyM6927-Aug-09 8:58 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process. Pin
Luc Pattyn27-Aug-09 9:15
sitebuilderLuc Pattyn27-Aug-09 9:15 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process. Pin
DaveyM6927-Aug-09 9:21
professionalDaveyM6927-Aug-09 9:21 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process. Pin
DaveyM6927-Aug-09 9:31
professionalDaveyM6927-Aug-09 9:31 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process.[modified] Pin
Luc Pattyn27-Aug-09 9:33
sitebuilderLuc Pattyn27-Aug-09 9:33 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process [modified] Pin
DaveyM6927-Aug-09 10:10
professionalDaveyM6927-Aug-09 10:10 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process Pin
Luc Pattyn27-Aug-09 10:27
sitebuilderLuc Pattyn27-Aug-09 10:27 
GeneralRe: Preventing the user from Ejecting the CD during crucial Process Pin
harold aptroot27-Aug-09 11:08
harold aptroot27-Aug-09 11:08 

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.