我正在製作一個記錄用戶活動的程序,我希望能夠獲得一個Teamviewer ID並將其發送到日誌,我知道如何通過將該信息分配給一個變量來將信息發送到日誌,但是我不確定如何將teamviewer ID傳遞給所述變量,並且希望獲得一些幫助。有沒有辦法在c#中找到Teamviewer ID?
任何和所有幫助將不勝感激:)
我正在製作一個記錄用戶活動的程序,我希望能夠獲得一個Teamviewer ID並將其發送到日誌,我知道如何通過將該信息分配給一個變量來將信息發送到日誌,但是我不確定如何將teamviewer ID傳遞給所述變量,並且希望獲得一些幫助。有沒有辦法在c#中找到Teamviewer ID?
任何和所有幫助將不勝感激:)
有關的TeamViewer 8在Windows 8中的TeamViewer ID存儲在HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \的TeamViewer \版本8 \ ClientID的
從這裏簡直是一個在C#中讀取該註冊表項的問題,然後根據需要做任何你想做的事情,我將提供註冊表讀取代碼:)但http://www.codeproject.com/Articles/3389/Read-write-and-delete-from-registry-with-C已經很好地解釋了它!祝你好運!
這絕對是太棒了!夢幻般的答案非常感謝:D –
非常歡迎:) – Maritim
這就是我正在使用的。
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;
}
這也工作得很好= D謝謝你! –
註冊表項是一次性的,所以應該在使用聲明中 – NiKiZe
版本10在註冊表中有不同的位置。
以下代碼適用於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;
}
}
註冊表項是一次性的,所以應該在使用聲明中 – NiKiZe
我認爲我的方法不會泄漏。但一般來說,是的,應該正確處理IDisposable對象。 –
接受的解決方案可能是正確的在某些情況下,但是ClientID的可位於註冊表的其他位置。
可能的位置:
public static string TvId()
{
return Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\TeamViewer\\Version6", "ClientID", "FAILED").ToString();
}
顯然這些已經過時了,但是一個好起點,'VBSCRIPT' - http://www.sole.dk/vbscript-to-show-current-teamviewer-id-and-save-to-text-file/ 'C#' - http://hintdesk.com/how-to-get-id-and-pass-of-teamviewer-programatically/ – CodeCamper
感謝您的快速響應,但是我在研究這個過程中看到了這些鏈接問題,我是C#初學者,希望得到更清晰的解釋 –