1: Have a look at the open source SharpZipLib. It mainly extracts Zip, GZip, Tar files, but I believe it can easily extract or create the image files for you. There's a wide range of settings you can apply during extraction and packaging. Here's the link to download libraries and source code:
SharpZipLib
2: Sounds like you don't have good intentions. I would never hide an application. Truly hiding the application is beyond the scope of your knowledge as I see. Windows service can be an alternative but it has limitations, so you don't have significant freedom.
3: Following is the MSDN standard code for enumerating and ejecting all or a particular USB storage device:
[highlight=vbnet]Private Const CM_DRP_DEVICEDESC As Integer = &H1
Private Const CM_DRP_DEVTYPE As Integer = &H1A
Private Const CM_DRP_HARDWAREID As Integer = &H2
Public DevType As Integer
Public HARDWAREID As String
Public DEVICEDESC As String
Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" ( _
ByRef ClassGuid As Guid, _
ByVal Enumerator As Integer, _
ByVal HwndParent As IntPtr, _
ByVal flags As Integer) As IntPtr
Private Declare Function SetupDiEnumDeviceInfo Lib "setupapi.dll" (ByVal DeviceInfoSet As IntPtr, ByVal MemberIndex As Integer, ByRef DeviceInfoData As SP_DEVINFO_DATA) As Integer
Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As IntPtr) As Integer
'returns proprities of a device by his DevInstance
Private Declare Function CM_Get_DevNode_Registry_Property Lib "cfgmgr32.dll" Alias "CM_Get_DevNode_Registry_PropertyA" ( _
ByVal dnDevInst As IntPtr, _
ByVal ulProperty As Integer, _
ByRef pulRegDataType As Integer, _
ByRef Buffer As Integer, _
ByRef pulLength As Integer, _
ByVal ulFlags As Integer) As Integer
Private Declare Function CM_Get_DevNode_Registry_Property Lib "cfgmgr32.dll" Alias "CM_Get_DevNode_Registry_PropertyA" ( _
ByVal dnDevInst As IntPtr, _
ByVal ulProperty As Integer, _
ByRef pulRegDataType As Integer, _
ByVal Buffer As StringBuilder, _
ByRef pulLength As Integer, _
ByVal ulFlags As Integer) As Integer
Public Structure SP_DEVINFO_DATA
Dim cbSize As Integer
Dim ClassGuid As Guid
Dim DevInst As IntPtr
Dim Reserved As Integer
End Structure
Public Enum PNP_VETO_TYPE
PNP_VetoTypeUnknown
PNP_VetoLegacyDevice
PNP_VetoPendingClose
PNP_VetoWindowsApp
PNP_VetoWindowsService
PNP_VetoOutstandingOpen
PNP_VetoDevice
PNP_VetoDriver
PNP_VetoIllegalDeviceRequest
PNP_VetoInsufficientPower
PNP_VetoNonDisableable
PNP_VetoLegacyDriver
End Enum
Private Declare Function CM_Request_Device_Eject Lib "setupapi.dll" Alias "CM_Request_Device_EjectW" (ByVal dnDevInst As IntPtr, _
ByRef pVetoType As PNP_VETO_TYPE, _
ByVal pszVetoName As IntPtr, _
ByVal ulNameLength As Integer, _
ByVal ulFlags As Integer) As Integer
<Flags()> _
Public Enum DeviceFlags As Integer
DigCFDefault = 1
DigCFPresent = 2 ' return only devices that are currently present
DigCFAllClasses = 4 ' gets all classes, ignores the guid...
DigCFProfile = 8 ' gets only classes that are part of the current hardware profile
DigCDDeviceInterface = 16 ' Return devices that expose interfaces of the interface class that are specified by ClassGuid.
End Enum
Public Sub EnumDevices()
Dim dwInstance As Integer
Dim hDevInfo As IntPtr 'pointer on a Device Information Set
Dim DevInfo As New SP_DEVINFO_DATA 'contains inforations on a Device
'We ask for a Device Information Set
hDevInfo = SetupDiGetClassDevs(Guid.Empty, 0, IntPtr.Zero, DeviceFlags.DigCFPresent Or DeviceFlags.DigCFAllClasses)
DevInfo.cbSize = Marshal.SizeOf(DevInfo)
If hDevInfo = New IntPtr(-1) Then Return
dwInstance = 0
Do
If SetupDiEnumDeviceInfo(hDevInfo, dwInstance, DevInfo) = 0 Then
SetupDiDestroyDeviceInfoList(hDevInfo)
Exit Do
End If
Me.DevType = CM_ReadDevicePropertyInteger(DevInfo.DevInst, CM_DRP_DEVTYPE)
Me.HARDWAREID = CM_ReadDevicePropertiyString(DevInfo.DevInst, CM_DRP_HARDWAREID)
Me.DEVICEDESC = CM_ReadDevicePropertiyString(DevInfo.DevInst, CM_DRP_DEVICEDESC)
If DEVICEDESC = "USB Mass Storage Device" Then
CM_Request_Device_Eject(DevInfo.DevInst, 0, IntPtr.Zero, 0, 0)
End If
dwInstance += 1
Loop
End Sub
Private Function CM_ReadDevicePropertyInteger(ByVal DevInst As IntPtr, ByVal iCustomPropertyName As Integer) As Integer
Dim ret As Integer, dwReqLen As Integer = 4, regDataType As Integer
CM_Get_DevNode_Registry_Property(DevInst, iCustomPropertyName, regDataType, ret, dwReqLen, 0)
Return ret
End Function
Private Function CM_ReadDevicePropertiyString(ByVal DevInst As IntPtr, ByVal iCustomPropertyName As Integer) As String
Dim sbBuff As StringBuilder, dwReqLen As Integer, regDataType As Integer
dwReqLen = 0
CM_Get_DevNode_Registry_Property(DevInst, iCustomPropertyName, regDataType, 0, dwReqLen, 0)
sbBuff = New StringBuilder(dwReqLen)
CM_Get_DevNode_Registry_Property(DevInst, iCustomPropertyName, regDataType, sbBuff, dwReqLen, 0)
Return sbBuff.ToString()
End Function[/highlight]
What you just need to do is that when you enumerate through devices in the EnumDevices Function, check the particular device by matching your criteria and then eject it. In this case, you need to modify the following code:
[highlight=vbnet]If DEVICEDESC = "USB Mass Storage Device" Then
CM_Request_Device_Eject(DevInfo.DevInst, 0, IntPtr.Zero, 0, 0)
End If[/highlight]
All the code is there for you. If you are unable to modify 2 lines, I can't see you achieving that.