神剑山庄资源网 Design By www.hcban.com
许多文件扩展名和一个可执行应用程序绑定。正因为这样你才可以使用Invoke-Item打开一个文档。
要找出一个给定后缀名的文件是由那个默认引用程序打开它,并不麻烦。我们可以使用Windows系统中的注册表,自行编程解决。但是在扫描注册表时,要稍微留意一下32位和64位机器的问题,这不是本文重点,点到为止。
另外一种途径,稍显旁门左道,调用Windows API。下面的例子会演示如何调用。采取这种途径最大的优势是借力于操作系统。而你的付出成本只是用C#代码间接调用Windows API中的函数而已:
$Source = @" using System; using System.Text; using System.Runtime.InteropServices; public class Win32API { [DllImport("shell32.dll", EntryPoint="FindExecutable")] public static extern long FindExecutableA(string lpFile, string lpDirectory, StringBuilder lpResult); public static string FindExecutable(string pv_strFilename) { StringBuilder objResultBuffer = new StringBuilder(1024); long lngResult = 0; lngResult = FindExecutableA(pv_strFilename, string.Empty, objResultBuffer); if(lngResult >= 32) { return objResultBuffer.ToString(); } return string.Format("Error: ({0})", lngResult); } } "@ Add-Type -TypeDefinition $Source -ErrorAction SilentlyContinue $FullName = 'c:\Windows\windowsupdate.log' $Executable = [Win32API]::FindExecutable($FullName) "$FullName will be launched by $Executable"
唯一有个限制,就是FindExecutable()需要检查的文件是存在的,你不能只用文件扩展名去请求。
另外@reidca反馈说该方法不能检测MMC加载项打开的文件,比如cer和pfx证书文件,程序会崩溃。
神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com
暂无PowerShell实现查询打开某个文件的默认应用程序的评论...
更新日志
2024年10月04日
2024年10月04日
- 许景淳.1992-你来自何方【全美唱片】【WAV+CUE】
- 石欣卉.2007-剧欣卉集·完整电视剧主题精丫华纳】【WAV+CUE】
- 群星.2005-LOVE情歌集VOL.5.2CD【正东】【WAV+CUE】
- 孙悦.1996-伙伴【正大国际】【WAV+CUE】
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】