using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace LockCD
{
public partial class Form1 : Form
{
public const int INVALID_HANDLE_VALUE = -1;
public const int GENERIC_READ = unchecked((int)0x80000000);
public const int GENERIC_WRITE = unchecked((int)0x40000000);
public const int FSCTL_LOCK_VOLUME = unchecked((int)0x00090018);
public const int FSCTL_DISMOUNT_VOLUME = unchecked((int)0x00090020);
public const int IOCTL_STORAGE_EJECT_MEDIA = unchecked((int)0x002D4808);
public const int IOCTL_STORAGE_MEDIA_REMOVAL = unchecked((int)0x002D4804);
//Share constants
public const uint FILE_SHARE_READ = 0x00000001;
public const uint FILE_SHARE_WRITE = 0x00000002;
public const uint FILE_SHARE_DELETE = 0x00000004;
//CreationDisposition constants
public const uint CREATE_NEW = 1;
public const uint CREATE_ALWAYS = 2;
public const uint OPEN_EXISTING = 3;
public const uint OPEN_ALWAYS = 4;
public const uint TRUNCATE_EXISTING = 5;
[DllImport("kernel32.dll", EntryPoint = "CreateFileW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern IntPtr CreateFile(
string lpFileName,
int dwDesiredAccess,
int dwShareMode,
IntPtr lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
IntPtr hTemplateFile);
[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
private static extern bool CloseHandle(IntPtr handle);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
IntPtr InBuffer, uint InBufferSize,
[Out] CDROM_TOC OutTOC, uint OutBufferSize,
ref uint BytesReturned,
IntPtr Overlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
[In] PREVENT_MEDIA_REMOVAL InMediaRemoval, uint InBufferSize,
IntPtr OutBuffer, uint OutBufferSize,
ref uint BytesReturned,
IntPtr Overlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
[In] RAW_READ_INFO rri, uint InBufferSize,
[In, Out] byte[] OutBuffer, uint OutBufferSize,
ref uint BytesReturned,
IntPtr Overlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
IntPtr lpInBuffer, uint InBufferSize,
IntPtr lpOutBuffer, uint nOutBufferSize,
ref uint lpBytesReturned,
IntPtr lpOverlapped);
[StructLayout(LayoutKind.Sequential)]
public struct TRACK_DATA
{
public byte Reserved;
private byte BitMapped;
public byte Control
{
get
{
return (byte)(BitMapped & 0x0F);
}
set
{
BitMapped = (byte)((BitMapped & 0xF0) | (value & (byte)0x0F));
}
}
public byte Adr
{
get
{
return (byte)((BitMapped & (byte)0xF0) >> 4);
}
set
{
BitMapped = (byte)((BitMapped & (byte)0x0F) | (value << 4));
}
}
public byte TrackNumber;
public byte Reserved1;
/// <summary>
/// Don't use array to avoid array creation
/// </summary>
public byte Address_0;
public byte Address_1;
public byte Address_2;
public byte Address_3;
};
public const int MAXIMUM_NUMBER_TRACKS = 100;
[StructLayout(LayoutKind.Sequential)]
public class TrackDataList
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXIMUM_NUMBER_TRACKS * 8)]
private byte[] Data;
public TRACK_DATA this[int Index]
{
get
{
if ((Index < 0) | (Index >= MAXIMUM_NUMBER_TRACKS))
{
throw new IndexOutOfRangeException();
}
TRACK_DATA res;
GCHandle handle = GCHandle.Alloc(Data, GCHandleType.Pinned);
try
{
IntPtr buffer = handle.AddrOfPinnedObject();
buffer = (IntPtr)(buffer.ToInt32() + (Index * Marshal.SizeOf(typeof(TRACK_DATA))));
res = (TRACK_DATA)Marshal.PtrToStructure(buffer, typeof(TRACK_DATA));
}
finally
{
handle.Free();
}
return res;
}
}
public TrackDataList()
{
Data = new byte[MAXIMUM_NUMBER_TRACKS * Marshal.SizeOf(typeof(TRACK_DATA))];
}
}
[StructLayout(LayoutKind.Sequential)]
public class CDROM_TOC
{
public ushort Length;
public byte FirstTrack = 0;
public byte LastTrack = 0;
public TrackDataList TrackData;
public CDROM_TOC()
{
TrackData = new TrackDataList();
Length = (ushort)Marshal.SizeOf(this);
}
}
[StructLayout(LayoutKind.Sequential)]
public class PREVENT_MEDIA_REMOVAL
{
public byte PreventMediaRemoval = 0;
}
public enum TRACK_MODE_TYPE { YellowMode2, XAForm2, CDDA }
[StructLayout(LayoutKind.Sequential)]
public class RAW_READ_INFO
{
public long DiskOffset = 0;
public uint SectorCount = 0;
public TRACK_MODE_TYPE TrackMode = TRACK_MODE_TYPE.CDDA;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IntPtr hDevice = CreateFile(@"\\.\F:", (int)GENERIC_READ, (int)FILE_SHARE_READ | (int)FILE_SHARE_WRITE, IntPtr.Zero, (int)OPEN_EXISTING, 0, IntPtr.Zero);
uint dwBytesReturned = 0;
PREVENT_MEDIA_REMOVAL pmr = new PREVENT_MEDIA_REMOVAL();
pmr.PreventMediaRemoval = 1;
if (DeviceIoControl(hDevice, (uint)IOCTL_STORAGE_MEDIA_REMOVAL, pmr, (uint)128, IntPtr.Zero, (uint)0, ref dwBytesReturned, IntPtr.Zero) == 0)
{
MessageBox.Show("Бла-бла-бла....");
}
CloseHandle(hDevice);
}
private void button2_Click(object sender, EventArgs e)
{
IntPtr hDevice = CreateFile(@"\\.\F:", (int)GENERIC_READ, (int)FILE_SHARE_READ | (int)FILE_SHARE_WRITE, IntPtr.Zero, (int)OPEN_EXISTING, 0, IntPtr.Zero);
uint dwBytesReturned = 0;
PREVENT_MEDIA_REMOVAL pmr = new PREVENT_MEDIA_REMOVAL();
pmr.PreventMediaRemoval = 0;
if (DeviceIoControl(hDevice, (uint)IOCTL_STORAGE_MEDIA_REMOVAL, pmr, (uint)128, IntPtr.Zero, (uint)0,ref dwBytesReturned, IntPtr.Zero) == 0)
{
MessageBox.Show("Бла-бла-бла....");
}
CloseHandle(hDevice);
}
}
}
Блокировка CD-ROM
https://lists.ubuntu.com/archives/ubuntu-ru/2007-June/004954.html
Не могли бы вы перевести его на СиШарп? Я бы перевел, но не знаю значения константов в делфи и не имею дика с чем-нибудь делфиёподобным.
Чуть напряг последнюю свою прямую извилину:
Мне ета прога очень надо.... помогите плз...
Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace LockCD
{
public partial class Form1 : Form
{
public const uint FILE_DEVICE_FILE_SYSTEM = 0x00000009;
public const uint FILE_ANY_ACCESS = 0;
public const int INVALID_HANDLE_VALUE = -1;
public const int GENERIC_READ = unchecked((int)0x80000000);
public const int GENERIC_WRITE = unchecked((int)0x40000000);
public const int FSCTL_LOCK_VOLUME = unchecked((int)0x00090018);
public const int FSCTL_UNLOCK_VOLUME = unchecked((int)0x0009001c);
public const int FSCTL_DISMOUNT_VOLUME = unchecked((int)0x00090020);
public const int IOCTL_STORAGE_EJECT_MEDIA = unchecked((int)0x002D4808);
public const int IOCTL_STORAGE_MEDIA_REMOVAL = unchecked((int)0x002D4804);
//Share constants
public const uint FILE_SHARE_READ = 0x00000001;
public const uint FILE_SHARE_WRITE = 0x00000002;
public const uint FILE_SHARE_DELETE = 0x00000004;
//CreationDisposition constants
public const uint CREATE_NEW = 1;
public const uint CREATE_ALWAYS = 2;
public const uint OPEN_EXISTING = 3;
public const uint OPEN_ALWAYS = 4;
public const uint TRUNCATE_EXISTING = 5;
[DllImport("kernel32.dll", EntryPoint = "CreateFileW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern IntPtr CreateFile(
string lpFileName,
int dwDesiredAccess,
int dwShareMode,
IntPtr lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
IntPtr hTemplateFile);
[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
private static extern bool CloseHandle(IntPtr handle);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
IntPtr InBuffer, uint InBufferSize,
[Out] CDROM_TOC OutTOC, uint OutBufferSize,
ref uint BytesReturned,
IntPtr Overlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
[In] PREVENT_MEDIA_REMOVAL InMediaRemoval, uint InBufferSize,
IntPtr OutBuffer, uint OutBufferSize,
ref uint BytesReturned,
IntPtr Overlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
[In] RAW_READ_INFO rri, uint InBufferSize,
[In, Out] byte[] OutBuffer, uint OutBufferSize,
ref uint BytesReturned,
IntPtr Overlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
IntPtr lpInBuffer, uint InBufferSize,
IntPtr lpOutBuffer, uint nOutBufferSize,
ref uint lpBytesReturned,
IntPtr lpOverlapped);
[StructLayout(LayoutKind.Sequential)]
public struct TRACK_DATA
{
public byte Reserved;
private byte BitMapped;
public byte Control
{
get
{
return (byte)(BitMapped & 0x0F);
}
set
{
BitMapped = (byte)((BitMapped & 0xF0) | (value & (byte)0x0F));
}
}
public byte Adr
{
get
{
return (byte)((BitMapped & (byte)0xF0) >> 4);
}
set
{
BitMapped = (byte)((BitMapped & (byte)0x0F) | (value << 4));
}
}
public byte TrackNumber;
public byte Reserved1;
/// <summary>
/// Don't use array to avoid array creation
/// </summary>
public byte Address_0;
public byte Address_1;
public byte Address_2;
public byte Address_3;
};
public const int MAXIMUM_NUMBER_TRACKS = 100;
[StructLayout(LayoutKind.Sequential)]
public class TrackDataList
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXIMUM_NUMBER_TRACKS * 8)]
private byte[] Data;
public TRACK_DATA this[int Index]
{
get
{
if ((Index < 0) | (Index >= MAXIMUM_NUMBER_TRACKS))
{
throw new IndexOutOfRangeException();
}
TRACK_DATA res;
GCHandle handle = GCHandle.Alloc(Data, GCHandleType.Pinned);
try
{
IntPtr buffer = handle.AddrOfPinnedObject();
buffer = (IntPtr)(buffer.ToInt32() + (Index * Marshal.SizeOf(typeof(TRACK_DATA))));
res = (TRACK_DATA)Marshal.PtrToStructure(buffer, typeof(TRACK_DATA));
}
finally
{
handle.Free();
}
return res;
}
}
public TrackDataList()
{
Data = new byte[MAXIMUM_NUMBER_TRACKS * Marshal.SizeOf(typeof(TRACK_DATA))];
}
}
[StructLayout(LayoutKind.Sequential)]
public class CDROM_TOC
{
public ushort Length;
public byte FirstTrack = 0;
public byte LastTrack = 0;
public TrackDataList TrackData;
public CDROM_TOC()
{
TrackData = new TrackDataList();
Length = (ushort)Marshal.SizeOf(this);
}
}
[StructLayout(LayoutKind.Sequential)]
public class PREVENT_MEDIA_REMOVAL
{
public byte PreventMediaRemoval = 0;
}
public enum TRACK_MODE_TYPE { YellowMode2, XAForm2, CDDA }
[StructLayout(LayoutKind.Sequential)]
public class RAW_READ_INFO
{
public long DiskOffset = 0;
public uint SectorCount = 0;
public TRACK_MODE_TYPE TrackMode = TRACK_MODE_TYPE.CDDA;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IntPtr hDevice = CreateFile(@"\\.\F:", (int)GENERIC_READ, (int)FILE_SHARE_READ | (int)FILE_SHARE_WRITE, IntPtr.Zero, (int)OPEN_EXISTING, 0, IntPtr.Zero);
uint dwBytesReturned = 0;
PREVENT_MEDIA_REMOVAL pmr = new PREVENT_MEDIA_REMOVAL();
pmr.PreventMediaRemoval = 1;
if (DeviceIoControl(hDevice, (uint)IOCTL_STORAGE_MEDIA_REMOVAL, pmr, (uint)128, IntPtr.Zero, (uint)0, ref dwBytesReturned, IntPtr.Zero) == 0)
{
MessageBox.Show("Бла-бла-бла....");
}
CloseHandle(hDevice);
}
private void button2_Click(object sender, EventArgs e)
{
IntPtr hDevice = CreateFile(@"\\.\F:", (int)GENERIC_READ, (int)FILE_SHARE_READ | (int)FILE_SHARE_WRITE, IntPtr.Zero, (int)OPEN_EXISTING, 0, IntPtr.Zero);
uint dwBytesReturned = 0;
PREVENT_MEDIA_REMOVAL pmr = new PREVENT_MEDIA_REMOVAL();
pmr.PreventMediaRemoval = 0;
if (DeviceIoControl(hDevice, (uint)IOCTL_STORAGE_MEDIA_REMOVAL, pmr, (uint)128, IntPtr.Zero, (uint)0,ref dwBytesReturned, IntPtr.Zero) == 0)
{
MessageBox.Show("Бла-бла-бла....");
}
CloseHandle(hDevice);
}
private void button3_Click(object sender, EventArgs e)
{
IntPtr hDevice = CreateFile(@"\\.\H:", (int)GENERIC_READ | (int)GENERIC_WRITE, (int)FILE_SHARE_READ | (int)FILE_SHARE_WRITE, IntPtr.Zero, (int)OPEN_EXISTING, 0, IntPtr.Zero);
uint mlock = 1;
if (DeviceIoControl(hDevice, FSCTL_LOCK_VOLUME, IntPtr.Zero, (uint)0, IntPtr.Zero, 0, ref mlock, IntPtr.Zero) != 0)
{
MessageBox.Show("Done. Close message to unlock device.");
}
CloseHandle(hDevice);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace LockCD
{
public partial class Form1 : Form
{
public const uint FILE_DEVICE_FILE_SYSTEM = 0x00000009;
public const uint FILE_ANY_ACCESS = 0;
public const int INVALID_HANDLE_VALUE = -1;
public const int GENERIC_READ = unchecked((int)0x80000000);
public const int GENERIC_WRITE = unchecked((int)0x40000000);
public const int FSCTL_LOCK_VOLUME = unchecked((int)0x00090018);
public const int FSCTL_UNLOCK_VOLUME = unchecked((int)0x0009001c);
public const int FSCTL_DISMOUNT_VOLUME = unchecked((int)0x00090020);
public const int IOCTL_STORAGE_EJECT_MEDIA = unchecked((int)0x002D4808);
public const int IOCTL_STORAGE_MEDIA_REMOVAL = unchecked((int)0x002D4804);
//Share constants
public const uint FILE_SHARE_READ = 0x00000001;
public const uint FILE_SHARE_WRITE = 0x00000002;
public const uint FILE_SHARE_DELETE = 0x00000004;
//CreationDisposition constants
public const uint CREATE_NEW = 1;
public const uint CREATE_ALWAYS = 2;
public const uint OPEN_EXISTING = 3;
public const uint OPEN_ALWAYS = 4;
public const uint TRUNCATE_EXISTING = 5;
[DllImport("kernel32.dll", EntryPoint = "CreateFileW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern IntPtr CreateFile(
string lpFileName,
int dwDesiredAccess,
int dwShareMode,
IntPtr lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
IntPtr hTemplateFile);
[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
private static extern bool CloseHandle(IntPtr handle);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
IntPtr InBuffer, uint InBufferSize,
[Out] CDROM_TOC OutTOC, uint OutBufferSize,
ref uint BytesReturned,
IntPtr Overlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
[In] PREVENT_MEDIA_REMOVAL InMediaRemoval, uint InBufferSize,
IntPtr OutBuffer, uint OutBufferSize,
ref uint BytesReturned,
IntPtr Overlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
[In] RAW_READ_INFO rri, uint InBufferSize,
[In, Out] byte[] OutBuffer, uint OutBufferSize,
ref uint BytesReturned,
IntPtr Overlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
public extern static int DeviceIoControl(IntPtr hDevice, uint IoControlCode,
IntPtr lpInBuffer, uint InBufferSize,
IntPtr lpOutBuffer, uint nOutBufferSize,
ref uint lpBytesReturned,
IntPtr lpOverlapped);
[StructLayout(LayoutKind.Sequential)]
public struct TRACK_DATA
{
public byte Reserved;
private byte BitMapped;
public byte Control
{
get
{
return (byte)(BitMapped & 0x0F);
}
set
{
BitMapped = (byte)((BitMapped & 0xF0) | (value & (byte)0x0F));
}
}
public byte Adr
{
get
{
return (byte)((BitMapped & (byte)0xF0) >> 4);
}
set
{
BitMapped = (byte)((BitMapped & (byte)0x0F) | (value << 4));
}
}
public byte TrackNumber;
public byte Reserved1;
/// <summary>
/// Don't use array to avoid array creation
/// </summary>
public byte Address_0;
public byte Address_1;
public byte Address_2;
public byte Address_3;
};
public const int MAXIMUM_NUMBER_TRACKS = 100;
[StructLayout(LayoutKind.Sequential)]
public class TrackDataList
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXIMUM_NUMBER_TRACKS * 8)]
private byte[] Data;
public TRACK_DATA this[int Index]
{
get
{
if ((Index < 0) | (Index >= MAXIMUM_NUMBER_TRACKS))
{
throw new IndexOutOfRangeException();
}
TRACK_DATA res;
GCHandle handle = GCHandle.Alloc(Data, GCHandleType.Pinned);
try
{
IntPtr buffer = handle.AddrOfPinnedObject();
buffer = (IntPtr)(buffer.ToInt32() + (Index * Marshal.SizeOf(typeof(TRACK_DATA))));
res = (TRACK_DATA)Marshal.PtrToStructure(buffer, typeof(TRACK_DATA));
}
finally
{
handle.Free();
}
return res;
}
}
public TrackDataList()
{
Data = new byte[MAXIMUM_NUMBER_TRACKS * Marshal.SizeOf(typeof(TRACK_DATA))];
}
}
[StructLayout(LayoutKind.Sequential)]
public class CDROM_TOC
{
public ushort Length;
public byte FirstTrack = 0;
public byte LastTrack = 0;
public TrackDataList TrackData;
public CDROM_TOC()
{
TrackData = new TrackDataList();
Length = (ushort)Marshal.SizeOf(this);
}
}
[StructLayout(LayoutKind.Sequential)]
public class PREVENT_MEDIA_REMOVAL
{
public byte PreventMediaRemoval = 0;
}
public enum TRACK_MODE_TYPE { YellowMode2, XAForm2, CDDA }
[StructLayout(LayoutKind.Sequential)]
public class RAW_READ_INFO
{
public long DiskOffset = 0;
public uint SectorCount = 0;
public TRACK_MODE_TYPE TrackMode = TRACK_MODE_TYPE.CDDA;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IntPtr hDevice = CreateFile(@"\\.\F:", (int)GENERIC_READ, (int)FILE_SHARE_READ | (int)FILE_SHARE_WRITE, IntPtr.Zero, (int)OPEN_EXISTING, 0, IntPtr.Zero);
uint dwBytesReturned = 0;
PREVENT_MEDIA_REMOVAL pmr = new PREVENT_MEDIA_REMOVAL();
pmr.PreventMediaRemoval = 1;
if (DeviceIoControl(hDevice, (uint)IOCTL_STORAGE_MEDIA_REMOVAL, pmr, (uint)128, IntPtr.Zero, (uint)0, ref dwBytesReturned, IntPtr.Zero) == 0)
{
MessageBox.Show("Бла-бла-бла....");
}
CloseHandle(hDevice);
}
private void button2_Click(object sender, EventArgs e)
{
IntPtr hDevice = CreateFile(@"\\.\F:", (int)GENERIC_READ, (int)FILE_SHARE_READ | (int)FILE_SHARE_WRITE, IntPtr.Zero, (int)OPEN_EXISTING, 0, IntPtr.Zero);
uint dwBytesReturned = 0;
PREVENT_MEDIA_REMOVAL pmr = new PREVENT_MEDIA_REMOVAL();
pmr.PreventMediaRemoval = 0;
if (DeviceIoControl(hDevice, (uint)IOCTL_STORAGE_MEDIA_REMOVAL, pmr, (uint)128, IntPtr.Zero, (uint)0,ref dwBytesReturned, IntPtr.Zero) == 0)
{
MessageBox.Show("Бла-бла-бла....");
}
CloseHandle(hDevice);
}
private void button3_Click(object sender, EventArgs e)
{
IntPtr hDevice = CreateFile(@"\\.\H:", (int)GENERIC_READ | (int)GENERIC_WRITE, (int)FILE_SHARE_READ | (int)FILE_SHARE_WRITE, IntPtr.Zero, (int)OPEN_EXISTING, 0, IntPtr.Zero);
uint mlock = 1;
if (DeviceIoControl(hDevice, FSCTL_LOCK_VOLUME, IntPtr.Zero, (uint)0, IntPtr.Zero, 0, ref mlock, IntPtr.Zero) != 0)
{
MessageBox.Show("Done. Close message to unlock device.");
}
CloseHandle(hDevice);
}
}
}
Фсе просто и понятно. Юзайте и наслажнайтесь...
А как к примеру определить подключение нового девайса (флешки например) к компу, чтобы не сработал автозапуск??? Можно на API?
Мда. Полчаса раздумий, и ответ на вопрос получен. Ещё двадцать минут - и готов ответ на второй вопрос. На третий вопрос отвечу: это делается через API, и, кажется, в самом фреймворке было событие, хотя врать не буду.
Я думаю Это винда использует флешку и я не могу её блокирнуть, в следствии четвёртый вопрос: как эту всю систету обойти и заблокировать флешку при подключении.
Чтобы у людей потом не появилось вопросов, объясню, зачем это все: я видел много прог, шифрующих всякое, и все БЕЗ ИСКЛЮЧЕНИЯ мне не понравились. И я пишу свою.
Цитата:
я видел много прог, шифрующих всякое, и все БЕЗ ИСКЛЮЧЕНИЯ мне не понравились. И я пишу свою.
А я видел две проги, шифрующие всякое, и все без исключения мне понравились. Что не понравилолсь вам в пакетах WinGPG или TrueCrypt?
Цитата: Sanila_san
А я видел две проги, шифрующие всякое, и все без исключения мне понравились. Что не понравилолсь вам в пакетах WinGPG или TrueCrypt?
Да и несовсем в том цель. Вы наверно подумали, что надо заблокировать флешку. Я просто хочу ограничить подключение разных носитилей инфы к компу. Флешку свою я и так шифрую своей крайне примитивной прогой, после чего пишу фрейм с прогой на флешку в корень.
Цитата: tva94
Да и несовсем в том цель. Вы наверно подумали, что надо заблокировать флешку. Я просто хочу ограничить подключение разных носитилей инфы к компу. Флешку свою я и так шифрую своей крайне примитивной прогой, после чего пишу фрейм с прогой на флешку в корень.
Препод? :-D
Да нет... В мой комп иногда суют всякий... Флешку маме дали, а там вирусы. Моя мама Каспеского гасит дык лезут. Просит права админа - бо некоторый софт не пашет. Вот Вам проблема. Да я это делаю так ещё чтобы чемуто научиться из этой области.
Кстати, нафига вы шифруете флешку прогой, да ещё и пишете прогу в корень?... Сказано же, TrueCrypt рулит, а вот самописные шифровалки... тут уж извините, я к ним отношусь негативно. Стойких криптосистем не так уж и много, и каждая реализация обязательно тестируется так же внимательно, как новый самолёт. Уж лучше поискать что-то по теме PGP/GPG, и им шифровать. А шифровать как-нибудь, ИМХО, хуже, чем не шифровать вообще.
Ну прога мне эта надо чтобы научиться работать в этой области. С безопасностью компа разобрался. Дык просто чтоб на всякий был пример.