首先,对术语进行一些澄清.通过敲定,我并不是指关闭会话; 我的意思是写一个CD或DVD的引出方式,以便不再通过常用手段(Roxio,Nero,Windows资源管理器等)添加信息.
我对此做了大量的研究.有一些开源程序,如InfraRecorder,我们可以从中吸取一些灵感,但它们似乎都涉及使用IMAPI相当精细的C++代码,这似乎是一种非常低级的做事方式.我们都没有C++或IMAPI专业知识来支持这样的代码库.
互联网上最有前途的资源似乎就是这个,但似乎并没有包含最终化功能.这是"编写图像"的代码:
public void WriteImage(BurnVerificationLevel verification, bool finalize, bool eject)
{
if (!_recorderLoaded)
throw new InvalidOperationException("LoadMedia must be called first.");
MsftDiscRecorder2 recorder = null;
MsftDiscFormat2Data discFormatData = null;
try
{
recorder = new MsftDiscRecorder2();
recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);
discFormatData = new MsftDiscFormat2Data
{
Recorder = recorder,
ClientName = ClientName,
ForceMediaToBeClosed = finalize
};
//
// Set the verification level
//
var burnVerification = (IBurnVerification)discFormatData;
burnVerification.BurnVerificationLevel = IMAPI_BURN_VERIFICATION_LEVEL.IMAPI_BURN_VERIFICATION_NONE;
//
// Check if media is blank, (for …Run Code Online (Sandbox Code Playgroud) 我想在Windows上创建一个ISO映像,即.iso文件.这可以使用COM组件IMAPI2FS.MsftFileSystemImage,我在MSDN博客文章"在PowerShell中使用IMAPI 2编写光盘"中找到了如何使用PowerShell执行此操作的说明.
在第3步之后,这些指令说"在这一步你可以停止并将结果图像保存到本地硬盘,这将是一个纯粹的ISO图像."
我的问题:如何在PowerShell中获取$ resultStream,即检索ImageStream的COM对象,并将其内容保存到文件中?
由于我原来的问题有点过于模糊,让我澄清一下.
我的目标是:
我想知道的是什么:
我是C#的新手,必须在C#中开发Windows Form应用程序.此应用程序应跟踪以下内容.
我可以RegisterNotification通过跟踪方法中的WM_DEVICECHANGE消息来获取CD/DVD驱动器插入的系统通知WndProc.
以上实现让我知道何时将新设备连接到PC.
我面临的问题是如何跟踪CD/DVD上发生的文件更改(写入/修改).一种选择是将CD/DVD中的文件轮询为后台作业.但是,这将是最后一个选择.
我发现IMAPI我们可以通过它写入CD/DVD但我只需要监视文件更改以进行审计.
请指点我如何在我的程序中接收CD/DVD通知上的文件更改?
我试过FileSystemWatcher但它似乎不适用于CD/DVD驱动器.
更新于2018年2月7日:
我能找到的另一种方法是通过WMI附加的查询WMI Events.我找到了一个Best way to detect dvd insertion in drive c#也可以得到答案的问题.我想知道在WMI中是否可以检测到DVD文件系统修改,以及是否有任何专家可以共享查询.我希望阿尔沙德能够在这方面提供帮助.
I have an XBAP that needs to be able to burn cd's. When running from inside Visual Studio, everything works okay. However when running from a browser, the IMAPI dll reports that the environment is not supported as soon as it tries to access the drive.
I am assuming this is coming down to permissioning. I have a signed certificate which I have installed and the xbap is set to run as a full trust application (although I'm guessing that …
我已经使用Interop.cs成功地将IMAPI2集成到我的应用程序中.我可以毫无问题地刻录CD/DVD.但是,MsftDiscFormat2Data更新的事件处理程序不起作用,因此我无法使我的进度条移动.
这是我在codeproject网站上找到的代码:
private void backgroundBurnWorker_DoWork(object sender,DoWorkEventArgs e){MsftDiscRecorder2 discRecorder = null; MsftDiscFormat2Data discFormatData = null;
try
{
//
// Create and initialize the IDiscRecorder2 object
//
discRecorder = new MsftDiscRecorder2();
var burnData = (BurnData)e.Argument;
discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId);
//
// Create and initialize the IDiscFormat2Data
//
discFormatData = new MsftDiscFormat2Data
{
Recorder = discRecorder,
ClientName = ClientName,
ForceMediaToBeClosed = _closeMedia
};
//
// Set the verification level
//
var burnVerification = (IBurnVerification)discFormatData;
burnVerification.BurnVerificationLevel = _verificationLevel;
//
// Check if media is blank, (for RW …Run Code Online (Sandbox Code Playgroud) 如我的问题中所述使用PowerShell创建ISO映像:如何将IStream保存到文件?,在PowerShell中我创建一个IStream对象如下:
$is = (New-Object -ComObject IMAPI2FS.MsftFileSystemImage).CreateResultImage().ImageStream
Run Code Online (Sandbox Code Playgroud)
此对象是(PowerShell)类型System.__ComObject.不知怎的,PowerShell知道它是IStream:
PS C:\> $is -is [System.Runtime.InteropServices.ComTypes.IConnectionPoint]
False
PS C:\> $is -is [System.Runtime.InteropServices.ComTypes.IStream]
True
Run Code Online (Sandbox Code Playgroud)
但是,此类型的强制转换失败:
PS C:\> [System.Runtime.InteropServices.ComTypes.IStream] $is
Cannot convert the "System.__ComObject" value of type "System.__ComObject" to type "System.Runtime.InteropServices.ComT
ypes.IStream".
At line:1 char:54
+ [System.Runtime.InteropServices.ComTypes.IStream] $is <<<<
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
Run Code Online (Sandbox Code Playgroud)
如何在不使用C#代码的情况下进行此转换?
更新:显然这种转换无法正常工作,正如x0n的回答所说的那样.
现在,我的目标是将此IStreamCOM对象传递给某些C#代码(使用相同的PowerShell脚本的一部分Add-Type),它将成为类型的.NET对象System.Runtime.InteropServices.ComTypes.IStream.那可能吗?如果没有,我有什么替代品?
我需要在C#应用程序中从我的网络摄像头刻录视频DVD吗?做正确的方法是什么?需要什么步骤?
我想我必须使用正确的文件夹结构和MPEG2视频创建图像,然后将其刻录到DVD?IMAPI2?
我成功地创建了iso映像,但是在调用此Create方法返回后,我尝试删除rootFolderPath中的文件时出现'文件正在使用'IO错误.我错过了Marshal.ReleaseComObject调用吗?
谢谢,
/// <summary>
/// Create iso image from rootFolderPath and write to isoImageFilePath. Does not include the actual rootFolder itself
/// </summary>
public void Create()
{
IFileSystemImage ifsi = new MsftFileSystemImage();
try
{
ifsi.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK);
ifsi.FileSystemsToCreate =
FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660;
ifsi.VolumeName = this.volumeName;
ifsi.Root.AddTree(rootFolderPath, false);//use a valid folder
//this will implement the Write method for the formatter
IStream imagestream = ifsi.CreateResultImage().ImageStream;
if (imagestream != null)
{
System.Runtime.InteropServices.ComTypes.STATSTG stat;
imagestream.Stat(out stat, 0x01);
IStream newStream;
if (0 == SHCreateStreamOnFile(isoImageFilepath, 0x00001001, out …Run Code Online (Sandbox Code Playgroud) imapi ×9
c# ×7
powershell ×3
com ×2
.net ×1
com-interop ×1
dvd ×1
dvd-burning ×1
interop ×1
iso-image ×1
video ×1
wmi ×1
wmi-query ×1
wpd ×1
xbap ×1