PDA

View Full Version : [VB.NET] Masterizzazione disco avviabile.


Popo95
14-03-2015, 16:47
Salve a tutti!
Dovrei aggiungere ad un mio applicativo una funzionalità che permetta di masterizzare un dvd avviabile. Riesco a masterizzare il disco ma non so come impostare l'immagine di boot. Premetto che il codice non è scritto da me, ma è un progetto trovato su Codeproject che ho adattato alle mie esigenze. So che è possibile fare ciò che chiedo in quanto in "IMAPI2.Interop" ho trovato il codice di un'interfaccia "IBootOptions" che, a quanto ho capito,fa esattamente ciò che chiedo. Questo è il codice:

/// <summary>
/// Boot Options
/// </summary>
[Guid("2C941FD4-975B-59BE-A960-9A2A262853A5")]
[TypeLibType(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FDispatchable | TypeLibTypeFlags.FNonExtensible)]
public interface IBootOptions
{
// Get boot image data stream
[DispId(1)]
IStream BootImage { get; }

// Get boot manufacturer
[DispId(2)]
string Manufacturer { get; set; }

// Get boot platform identifier
[DispId(3)]
PlatformId PlatformId { get; set; }

// Get boot emulation type
[DispId(4)]
EmulationType Emulation { get; set; }

// Get boot image size
[DispId(5)]
uint ImageSize { get; }

// Set the boot image data stream, emulation type, and image size
[DispId(20)]
void AssignBootImage(IStream newVal);
}


Non so come si usino le interfaccie, ma guardando un po' il resto del codice ho capito qualcosina, e ho tentato con qualcosa del genere:


Dim bootFile
bootFile="C:\etfsboot.com"

Dim bootOptions As IBootOptions

bootOptions.Manufacturer = "Microsoft" 'Imposta produttore
bootOptions.PlatformId = PlatformId.PlatformX86 ' Imposta architettura
bootOptions.Emulation = EmulationType.EmulationNone ' Imposta nessuna emulazione

Dim bootStream As System.Runtime.InteropServices.ComTypes.IStream = bootFile

bootOptions.AssignBootImage(bootStream)

Il problema è che eseguendo il codice mi genera un'eccezione "Riferimento ad un oggetto non impostato su un'istanza di oggetto". A quanto pare prima di poter fare qualsiasi cosa con bootOptions, gli devo attribuire un valore. Non ho idea però di cosa.
Su MSDN ho trovato qualche informazione, ma non mi è stata di grande aiuto: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364813%28v=vs.85%29.aspx

Qualcuno può darmi una mano?

Grazie :)

lishi
15-03-2015, 12:22
Salve a tutti!
Dovrei aggiungere ad un mio applicativo una funzionalità che permetta di masterizzare un dvd avviabile. Riesco a masterizzare il disco ma non so come impostare l'immagine di boot. Premetto che il codice non è scritto da me, ma è un progetto trovato su Codeproject che ho adattato alle mie esigenze. So che è possibile fare ciò che chiedo in quanto in "IMAPI2.Interop" ho trovato il codice di un'interfaccia "IBootOptions" che, a quanto ho capito,fa esattamente ciò che chiedo. Questo è il codice:

/// <summary>
/// Boot Options
/// </summary>
[Guid("2C941FD4-975B-59BE-A960-9A2A262853A5")]
[TypeLibType(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FDispatchable | TypeLibTypeFlags.FNonExtensible)]
public interface IBootOptions
{
// Get boot image data stream
[DispId(1)]
IStream BootImage { get; }

// Get boot manufacturer
[DispId(2)]
string Manufacturer { get; set; }

// Get boot platform identifier
[DispId(3)]
PlatformId PlatformId { get; set; }

// Get boot emulation type
[DispId(4)]
EmulationType Emulation { get; set; }

// Get boot image size
[DispId(5)]
uint ImageSize { get; }

// Set the boot image data stream, emulation type, and image size
[DispId(20)]
void AssignBootImage(IStream newVal);
}


Non so come si usino le interfaccie, ma guardando un po' il resto del codice ho capito qualcosina, e ho tentato con qualcosa del genere:


Dim bootFile
bootFile="C:\etfsboot.com"

Dim bootOptions As IBootOptions

bootOptions.Manufacturer = "Microsoft" 'Imposta produttore
bootOptions.PlatformId = PlatformId.PlatformX86 ' Imposta architettura
bootOptions.Emulation = EmulationType.EmulationNone ' Imposta nessuna emulazione

Dim bootStream As System.Runtime.InteropServices.ComTypes.IStream = bootFile

bootOptions.AssignBootImage(bootStream)

Il problema è che eseguendo il codice mi genera un'eccezione "Riferimento ad un oggetto non impostato su un'istanza di oggetto". A quanto pare prima di poter fare qualsiasi cosa con bootOptions, gli devo attribuire un valore. Non ho idea però di cosa.
Su MSDN ho trovato qualche informazione, ma non mi è stata di grande aiuto: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364813%28v=vs.85%29.aspx

Qualcuno può darmi una mano?

Grazie :)

Ovviamente se dichiari una variabile reference questo è messa a null finche non ci assegni un valore.

Se guardi il link da te postato

nel tuo codice manca questa riga.

SET bootOptions = WScript.CreateObject("IMAPI2FS.BootOptions")

Popo95
15-03-2015, 14:39
Si ma quel codice non può essere utilizzato in VB.NET. Non so se abbia senso, ma ho provato a fare così: Dim bootOptions As IBootOptions = New BootOptions

Adesso viene fuori un altro problema con questa parte:

Dim bootStream As System.Runtime.InteropServices.ComTypes.IStream = bootFile

Dice che non è possibile convertire dal tipo String al tipo IStream. Come faccio a passargli il percorso del file allora?

lishi
15-03-2015, 22:14
Allora :

Il codice si aspetta un oggetto che implementi interfaccia ComTypes.IStream

Che ovviamente la stringa non implementa. Implementarlo richiede comunque un po di lavoro, fortunatamente esistono già librerie che lo fanno
Guardando il tuo esempio postato nel link

Set bootStream = CreateObject("ADODB.Stream")
WScript.Echo "Creating IStream for file " + bootFile
bootStream.Open
bootStream.Type = adFileTypeBinary
bootStream.LoadFromFile bootFile
bootOptions.AssignBootImage(bootStream)

Vedi che esempio usa un ADODB.Stream che certamente non centra una fava con la masterizzazione cd, ma evidentemente va bene lo stesso.
Quindi aggiungi un reference ad ADODB.
e fai

Dim bootStream As System.Runtime.InteropServices.ComTypes.IStream = new ADODB.Stream

e prosegui come esempio.

Popo95
23-03-2015, 10:53
Ok,risolto. Anche se adesso all'avvio mi da l'errore "COULDN'T FIND BOOTMGR", forse ho sbagliato qualcosa ma almeno adesso so a regola come proseguire.
Grazie mille!