1

I've asked this question before, but I'm trying to get a Teamviewer ID from the registry and display it in a messagebox when a button has been clicked, However when I click said button, a blank message box pops up and I would like some help resolving this issue.

my code for retrieving the Teamviewer ID is below;

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;
                            }
                        }
                    }
                }
            }

and for the button;

private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(LogDataFactory.CollectTeamviewerId());
        }
4

1 回答 1

1

将您的代码更改clientID as stringclientID.ToString()注册表clientID中的DWORD 类型,并且 clientID as string始终为null

if (clientID != null)
{
      return clientID.ToString();
}

编辑:您可以在 MSDN 上查看as关键字

如果无法进行转换,则 as 返回 null 而不是引发异常

于 2013-07-01T15:54:26.460 回答