有没有办法在c#中找到Teamviewer ID?

Cap*_*ard 10 c#

我正在制作一个记录用户活动的程序,我希望能够获得一个Teamviewer ID并将其发送到日志,我知道如何通过将该信息分配给变量来将信息发送到日志中,我不确定如何将teamviewer ID传递给所述变量,并希望得到一些帮助.

任何和所有的帮助将不胜感激:)

小智 10

这就是我正在使用的.

    public static string GetTeamviewerID()
    {
        var versions = new[] {"4", "5", "5.1", "6", "7", "8"}.Reverse().ToList(); //Reverse to get ClientID of newer version if possible

        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) //found it?
                        {
                            return Convert.ToInt32(clientID).ToString();
                        }
                    }
                }
            }
        }
        //Not found, return an empty string
        return string.Empty;
    }
Run Code Online (Sandbox Code Playgroud)


小智 10

版本10在Registry中的位置略有不同.

以下代码适用于ver.10和旧版本.它还考虑了32位和64位操作系统之间的差异:

long GetTeamViewerId()
{
    try
    {
        string regPath = Environment.Is64BitOperatingSystem ? @"SOFTWARE\Wow6432Node\TeamViewer" : @"SOFTWARE\TeamViewer";
        RegistryKey key = Registry.LocalMachine.OpenSubKey(regPath);
        if (key == null)
            return 0;
        object clientId = key.GetValue("ClientID");
        if (clientId != null) //ver. 10
            return Convert.ToInt64(clientId);
        foreach (string subKeyName in key.GetSubKeyNames().Reverse()) //older versions
        {
            clientId = key.OpenSubKey(subKeyName).GetValue("ClientID");
            if (clientId != null)
                return Convert.ToInt64(clientId);
        }
        return 0;
    }
    catch (Exception e)
    {
        return 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 注册表项是一次性的,因此应在using语句中 (2认同)

Mar*_*tim 8

对于Windows 8中的TeamViewer 8,TeamViewer ID存储在HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\TeamViewer\Version8\ClientID中

从这里开始,只需要在C#中读取该注册表项,然后随意执行任何操作,如果需要,我将提供注册表读取的代码:)但是http://www.codeproject.com/Articles/ 3389 /来自注册表的读写 - 删除 -已经很好地解释了它!祝你好运!