Reputation: 848
In my application people can connect to a remote computer with the use of teamviewer. People can select there name and click connect, the teamviewer app will start with the correct parameters and a teamviewer session is started.
There is only one issue, how can i get the path where teamviewer is installed.
I thought i could use the registry to get the path, so i wrote this code.
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\TeamViewer\Version7", True)
TeamViewerPath = regKey.GetValue("InstallationDirectory", AccessibleDescription)
It works perfect, it will get the correct path where teamviewer is installed, but this is only working for 64 bit Windows 7. How could i make this work for Windows XP 32 Bit and Windows 7 32 Bit.
EDIT : Wrote the following code and it works, it is probably not the best or cleanest way but it does the trick.
Dim regKeyW7 As RegistryKey
Dim regKeyWXP As RegistryKey
Dim TeamViewerPath As String
regKeyW7 = Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\TeamViewer\Version7", True)
If regKeyW7 Is Nothing Then
regKeyWXP = Registry.LocalMachine.OpenSubKey("SOFTWARE\TeamViewer\Version7", True)
TeamViewerPath = regKeyWXP.GetValue("InstallationDirectory", AccessibleDescription)
Label21.Text = "Windows XP"
Else
TeamViewerPath = regKeyW7.GetValue("InstallationDirectory", AccessibleDescription)
Label21.Text = "Windows 7"
End If
Upvotes: 0
Views: 2367
Reputation: 3970
The key you are using (Wow6432Node) is a reflector; it is a view of the registry for 32bit applications that run on a 64bit OS. This key will not exist on 32bit systems and your OpenSubKey("SOFTWARE\Wow6432Node\TeamViewer\Version7", True) may throw an exception.
See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724072(v=vs.85).aspx
If you feel you must take this approach to reading the InstallationDirectory out, I would recommend setting your executable's build platform to x86 and accessing the key via SOFTWARE\TeamViewer\Version7 removing the need for your check. When the platform is set to x86, the application will ALWAYS read from the 32bit hive of the registry, even if it is running on an x64 system. Windows will take care of doing the lookup for you under the Wow6432Node automatically.
My guess is that your target platform is set to 'Any CPU' which basically means that the application will use the executing platform (at runtime) to determine where the location for SOFTWARE\TeamViewer\Version7 really comes from. In this scenario, when your application runs on a 64 bit system, the OpenSubKey("SOFTWARE\TeamViewer\Version7") will look in the 64bit version of the registry (thus not finding the key, and falling into your else condition). When the application is run on a 32bit system using OpenSubKey("SOFTWARE\TeamViewer\Version7") it will indeed find the value because there is no 64bit version of the registry.
For a good discussion of 'Any CPU' and x86 see:
Upvotes: 1
Reputation:
what happend if teamviewer gets a new version that is not 7?
is isnt better to detect first the windows version so you can decide what to check?
if i click the button to launch teamviewer from the application and i dont have teamviewer installed? have you tested that?
i have teamviewer installed and in the registry doesnt have installdirectory
Upvotes: 0