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 :)
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;
}
}
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;
}
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With