Reputation: 1390
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 :)
Upvotes: 11
Views: 13793
Reputation: 555
Method updated to work also with TeamViewer ver. 15.
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:
public static string GetTeamViewerId() {
try {
string[] regPath = { @"SOFTWARE\Wow6432Node\TeamViewer", @"SOFTWARE\TeamViewer" }; // newer versions
RegistryKey key = Registry.LocalMachine.OpenSubKey(regPath[0]);
if (key == null)
key = Registry.LocalMachine.OpenSubKey(regPath[1]);
if (key == null)
return "0";
object clientId = key.GetValue("ClientID");
if (clientId != null) //ver. 10
return clientId.ToStringIgnoreCulture();
foreach (string subKeyName in key.GetSubKeyNames().Reverse()) //older versions
{
RegistryKey openSubKey = key.OpenSubKey(subKeyName);
if (openSubKey != null)
clientId = openSubKey.GetValue("ClientID");
if (clientId != null)
return clientId.ToStringIgnoreCulture();
}
return "0";
} catch {
return string.Empty;
}
}
Upvotes: 13
Reputation: 9
public static string TvId()
{
return Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\TeamViewer\\Version6", "ClientID", "FAILED").ToString();
}
Upvotes: -1
Reputation: 1256
The accepted solution might be correct in some cases, however the ClientID can be located in other locations in the Registry.
Possible locations:
Upvotes: 4
Reputation: 101
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;
}
Upvotes: 10
Reputation: 2159
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!
Upvotes: 9