如何在C#中获取Teamviewer ID
本文关键字:获取 Teamviewer ID | 更新日期: 2023-09-27 18:20:31
我以前问过这个问题,但我正试图从注册表中获取Teamviewer ID,并在单击按钮时将其显示在消息框中。但是,当我单击所述按钮时,会弹出一个空白消息框,我希望得到一些帮助来解决这个问题。
我检索Teamviewer ID的代码如下;
public static string CollectTeamviewerId()
{
var versions = new[] { "4", "5", "5.1", "6", "7", "8" }.Reverse().ToList();
foreach (var path in new[] { "SOFTWARE''TeamViewer", "SOFTWARE''Wow6432Node''TeamViewer" })
{
if (Registry.LocalMachine.OpenSubKey(path) != null)
{
foreach (var version in versions)
{
var subKey = string.Format("{0}''Version{1}", path, version);
if (Registry.LocalMachine.OpenSubKey(subKey) != null)
{
var clientID = Registry.LocalMachine.OpenSubKey(subKey).GetValue("ClientID");
if (clientID != null)
{
return clientID as string;
}
}
}
}
}
以及用于按钮;
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show(LogDataFactory.CollectTeamviewerId());
}
将代码clientID as string
更改为clientID.ToString()
,因为注册表中的clientID
是DWORD类型,clientID as string
将始终是null
:
if (clientID != null)
{
return clientID.ToString();
}
编辑:您可以在MSDN 上查看as
关键字
如果转换不可能,as将返回null,而不是引发异常