Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to find a Teamviewer ID in c#?

Tags:

c#

I'm making a program which logs user activity, and I'd like to be able to get a Teamviewer ID and send it to a log, I know how to send the information to the log by assigning that information to a variable, however I'm not sure how to pass a teamviewer ID to said variable and would like some help on this.

Any and all help would be appreciated :)

like image 940
Captain_Custard Avatar asked Jun 18 '13 10:06

Captain_Custard


3 Answers

Version 10 has a bit different position in Registry.

The following code works with ver. 10 and also older versions. It also takes differences between 32 bit and 64 bit OS into account:

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;
    }
}
like image 106
Igor Gorjanc Avatar answered Oct 19 '22 17:10

Igor Gorjanc


This is what I'm using.

    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;
    }
like image 36
Devsoft.vn Avatar answered Oct 19 '22 17:10

Devsoft.vn


For TeamViewer 8 in Windows 8 the TeamViewer ID is stored in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\TeamViewer\Version8\ClientID

From here on it is simply a matter of reading that registry key in C# and then do whatever you want with it, if need be I'll provide code for registry reading :) But http://www.codeproject.com/Articles/3389/Read-write-and-delete-from-registry-with-C explains it really well already! Best of luck!

like image 9
Maritim Avatar answered Oct 19 '22 19:10

Maritim