我有一个.NET 4.0库,它使用Shell32和Folder.GetDetailsOf()从WTV文件中获取元数据.我已成功使用它与控制台和Windows窗体应用程序没有问题.但由于某种原因,从.NET 4.0 Windows服务调用组件时,启动Shell类的调用会导致COM错误.
库中失败的代码:
Shell32.Shell shell = new Shell();
错误:
无法将"System .__ ComObject"类型的COM对象强制转换为接口类型"Shell32.Shell".此操作失败,因为对IID为"{286E6F1B-7113-4355-9562-96B7E9D64C54}"的接口的COM组件的QueryInterface调用由于以下错误而失败:不支持此类接口(HRESULT异常:0x80004002(E_NOINTERFACE)) .
我阅读了我的公寓线程,COM Interops,动态,PIA等等,但是我找到的解决方案没有解决问题.它必须是来自另一个无法看到Interop的线程的调用.请帮忙 :)
How could i translate this in c#?
Set WshShell = WScript.CreateObject( "WScript.Shell" )
Run Code Online (Sandbox Code Playgroud)
Thx. At what is this used? And also what is the library i have to include in c# in order to work?
我试图使用Shell从文件中获取元数据.我正在使用MVC5和Windows 8操作系统.这是下面的代码.
码
public JsonResult Ind(string file)
{
List<string> arrHeaders = new List<string>();
string filename = Path.GetFileName(file);
Shell shell = new ShellClass();
Folder rFolder = shell.NameSpace(file);
FolderItem rFiles = rFolder.ParseName(filename);
for (int i = 0; i < short.MaxValue; i++)
{
string value = rFolder.GetDetailsOf(rFiles, i).Trim();
arrHeaders.Add(value);
}
return Json(arrHeaders, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行上面的代码时,我收到错误无法将"Shell32.ShellClass"类型的COM对象强制转换为接口类型"Shell32.IShellDispatch6".此操作失败,因为对IID为"{286E6F1B-7113-4355-9562-96B7E9D64C54}"的接口的COM组件的QueryInterface调用由于以下错误而失败:不支持此类接口(HRESULT异常:0x80004002(E_NOINTERFACE)) .
还有其他更好的解决方案来读取不同文件格式的元数据吗?请给我一些建议.我会感激你的.
谢谢