如何检测在C#中安装了UWP应用程序(Skype)?
我有一个C#程序,可以通过skype拨打给定的电话号码或skype ID如何检测在C#中安装了UWP应用程序(Skype)?,c#,skype,C#,Skype,我有一个C#程序,可以通过skype拨打给定的电话号码或skype ID string input; //... string uriSkype = $"Skype:{input}?call"; Process p = Process.Start(uriSkype); if (p != null) { p.WaitForExit(); p.Close(); } 该代码对UWP Skype或桌面Skype都有效。 但如果Skype(windows应用商店版本或桌面版本)未安装,我
string input;
//...
string uriSkype = $"Skype:{input}?call";
Process p = Process.Start(uriSkype);
if (p != null)
{
p.WaitForExit();
p.Close();
}
该代码对UWP Skype或桌面Skype都有效。
但如果Skype(windows应用商店版本或桌面版本)未安装,我想向用户发送一条消息
我可以通过查看注册表来检测桌面版本:
RegistryKey SoftwareKey = Registry.CurrentUser.OpenSubKey("Software");
if (SoftwareKey != null)
{
RegistryKey SkypeKey = SoftwareKey.OpenSubKey("Skype");
if (SkypeKey != null)
{
RegistryKey PhoneKey = SkypeKey.OpenSubKey("Phone");
if (PhoneKey != null)
{
object objSkypePath = PhoneKey.GetValue("SkypePath");
if (objSkypePath != null)
{
// here I know the path of skype.exe is installed.
}
}
}
}
以上方法可以找到是否安装了skype.exe
我想知道的是:如何正确检测是否安装了UWP版本的Skype?我在和中使用powershell命令找到了一个不太清晰的答案 我需要安装powershell 2.0,并从windows sdk添加对
System.Management.Automation.dll
的引用
using (PowerShell PowerShellInstance = PowerShell.Create())
{
// get the installed apps list
PowerShellInstance.AddScript("Get-AppxPackage | ft Name, PackageFullName -AutoSize");
// format output to a string
PowerShellInstance.AddCommand("Out-String");
// invoke execution on the pipeline (collecting output)
Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
// loop through each output object item
foreach (PSObject outputItem in PSOutput)
{
string strOut = outputItem.ToString();
if (strOut.Contains("Microsoft.SkypeApp"))
{
// do stuff...
}
}
}
使用(PowerShell PowerShellInstance=PowerShell.Create())
{
//获取已安装的应用程序列表
AddScript(“获取AppxPackage | ft Name,PackageFullName-AutoSize”);
//将输出格式化为字符串
PowerShellInstance.AddCommand(“输出字符串”);
//在管道上调用执行(收集输出)
集合PSOutput=PowerShellInstance.Invoke();
//循环遍历每个输出对象项
foreach(PSOutput中的PSObject输出项)
{
string strOut=outputItem.ToString();
if(strOut.Contains(“Microsoft.SkypeApp”))
{
//做些事情。。。
}
}
}
您可以查看注册表中是否安装了Skype协议,即HKEY\U CLASSES\U ROOT\Skype
包含URL协议
条目。您的问题是什么?在一句话中,你说“代码对UWP Skype或桌面Skype都有效。”而在另一句话中,你说“我如何才能正确地检测到是否没有安装任何版本的Skype?”。它起作用了吗?你只想为用户显示一个弹出窗口“Skype没有安装”吗?考虑使用Skype API而不是注册表的方式,如果没有安装UWP/桌面Skype,我想显示一个消息框并直接指向Skype的主页。