dodaj pliki czy cos

This commit is contained in:
Erdef119 2026-04-26 20:39:48 +02:00
commit b0bcf53bdb
213 changed files with 811368 additions and 0 deletions

47
watykanczyk/EjectMedia.cs Normal file
View file

@ -0,0 +1,47 @@
using System;
using System.Runtime.InteropServices;
internal class EjectMedia
{
private const uint GENERICREAD = 2147483648u;
private const uint OPENEXISTING = 3u;
private const uint IOCTL_STORAGE_EJECT_MEDIA = 2967560u;
private const int INVALID_HANDLE = -1;
private static IntPtr fileHandle;
private static uint returnedBytes;
[DllImport("kernel32", SetLastError = true)]
private static extern IntPtr CreateFile(string fileName, uint desiredAccess, uint shareMode, IntPtr attributes, uint creationDisposition, uint flagsAndAttributes, IntPtr templateFile);
[DllImport("kernel32", SetLastError = true)]
private static extern int CloseHandle(IntPtr driveHandle);
[DllImport("kernel32", SetLastError = true)]
private static extern bool DeviceIoControl(IntPtr driveHandle, uint IoControlCode, IntPtr lpInBuffer, uint inBufferSize, IntPtr lpOutBuffer, uint outBufferSize, ref uint lpBytesReturned, IntPtr lpOverlapped);
public static void Eject(string driveLetter)
{
try
{
fileHandle = CreateFile(driveLetter, 2147483648u, 0u, IntPtr.Zero, 3u, 0u, IntPtr.Zero);
if ((int)fileHandle != -1)
{
DeviceIoControl(fileHandle, 2967560u, IntPtr.Zero, 0u, IntPtr.Zero, 0u, ref returnedBytes, IntPtr.Zero);
}
}
catch
{
throw new Exception(Marshal.GetLastWin32Error().ToString());
}
finally
{
CloseHandle(fileHandle);
fileHandle = IntPtr.Zero;
}
}
}