VBScript to show current Teamviewer ID and save to text file

Since TeamViewer can be rolled out in an organization with the MSI package and sample vbs scripts from TeamViewer, I was asked if it would be hard to do a small VBScript to fetch the TeamViewer ID from theese machines and save it somewhere for the support staff to look up in.

This script is a very simple example of how to fetch the ID on a machine from registry and save that together with current logged in user and machine name in text files. To change this to save into another system, database, etc. would be quite simple.

But by creating a share with write permissions from everyone and pointing this script to it and placing it during login for all users in a domain, it would be easy to find a given machine or users TeamViewer ID. Since the TeamViewer ID does not change for a machine, it could be just run on machines when the TeamViewer client is installed, but that is entirely up to you.

So without further adue, here is the little script. optimizations could be done to not write to the file if allready done, only run with install, save to database, etc.

You can also download a text file with the vbs script to avoid formatting errors, just right click, select save as and rename to .vbs. teamviewer-id-script.vbs

Const strFolderName = "\\fileserver\share\folder\"
' set this to where you want the files stored, make sure there is permission from clients to this no matter what user they are logged on with!
Const ShowInfoOutput = True
' Set to true/false for writing to console

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Wow6432Node\TeamViewer\Version5"
strValueName = "ClientID"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID

' client ID is placed in more than one place depending on version
' in case we dont get it first, try a second place (add more of theese "if sections" if other versions are used)
If dwTVID = 0 Then
	strKeyPath = "SOFTWARE\Wow6432Node\TeamViewer\Version5.1"
	oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID
End If
Set oReg = Nothing

' Get information about this machine
Set WshNetwork = WScript.CreateObject("WScript.Network") ' used for Networking object control
UserName = UCase(WshNetwork.UserName)
ComputerName = UCase(WshNetwork.ComputerName)
EnvDomainName = UCase( WshNetwork.UserDomain )
Set WshNetwork = Nothing

If ShowInfoOutput Then
	WScript.Echo "User:         " & EnvDomainName & "\" & UserName
	WScript.Echo "Computer:     " & ComputerName
	WScript.Echo "TeamViewerID: " & dwTVID
End If

If Not dwTVID = 0 Then
	' only save if we did get a TeamViewer ID
	' Save to userdomain, computername, username, teamviewerid to a text file with same name
	strFileName = strFolderName & EnvDomainName & "_" & ComputerName & "_" & UserName & "_" & dwTVID & ".txt"
	Set objFSO = CreateObject("Scripting.FileSystemObject") ' used for file operations
	Set objTextFile = objFSO.OpenTextFile (strFileName, ForWriting, True)
	objTextFile.WriteLine EnvDomainName & vbCrLf & ComputerName & vbCrLf & UserName & vbCrLf & dwTVID
	objTextFile.Close
End If

6 Responses to “VBScript to show current Teamviewer ID and save to text file”

  • Giorgio:

    Compliments.. it’s a great script..

  • Sebas:

    Great script, still rocking!

  • this works fine for the 64bit platform, but i’ve some problems with the 32bit no windows 7 32bit write the values
    i’ve inserted this if cycle
    “If dwTVID = 0 Then
    strKeyPath = “SOFTWARE\TeamViewer\Version7”
    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID
    End If
    If dwTVID = 0 Then
    strKeyPath = “SOFTWARE\TeamViewer\Version8”
    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID
    End If
    If dwTVID = 0 Then
    strKeyPath = “SOFTWARE\TeamViewer\Version9”
    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID
    End If
    If dwTVID = 0 Then
    strKeyPath = “SOFTWARE\TeamViewer\Version10”
    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID
    End If
    If dwTVID = 0 Then
    strKeyPath = “SOFTWARE\Wow6432Node\TeamViewer\Version8”
    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID
    End If
    If dwTVID = 0 Then
    strKeyPath = “SOFTWARE\Wow6432Node\TeamViewer\Version9”
    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID
    End If
    If dwTVID = 0 Then
    strKeyPath = “SOFTWARE\Wow6432Node\TeamViewer\Version10″
    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID
    End If”

    but with no effects

    thank you in ADV

  • i’ve resolved
    Const strFolderName = “\\10.39.1.2\inventory$\”
    ‘ set this to where you want the files stored, make sure there is permission from clients to this no matter what user they are logged on with!
    Const ShowInfoOutput = False
    ‘ Set to true/false for writing to console

    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const HKEY_CURRENT_USER = &H80000001
    Const HKEY_LOCAL_MACHINE = &H80000002

    strComputer = “.”

    Set WshShell = WScript.CreateObject(“WScript.Shell”)
    OSArchCheck = WshShell.RegRead(“HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE”)

    If OSArchCheck = “x86” Then
    Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & _
    strComputer & “\root\default:StdRegProv”)
    strKeyPath = “SOFTWARE\TeamViewer\Version7”
    strValueName = “ClientID”
    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID

    Else
    Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & _
    strComputer & “\root\default:StdRegProv”)
    strKeyPath = “SOFTWARE\Wow6432Node\TeamViewer\Version7”
    strValueName = “ClientID”
    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwTVID
    End If

    ‘ client ID is placed in more than one place depending on version
    ‘ in case we dont get it first, try a second place (add more of theese “if sections” if other versions are used)

    Set oReg = Nothing

    ‘ Get information about this machine
    Set WshNetwork = WScript.CreateObject(“WScript.Network”) ‘ used for Networking object control
    UserName = UCase(WshNetwork.UserName)
    ComputerName = UCase(WshNetwork.ComputerName)
    EnvDomainName = UCase( WshNetwork.UserDomain )
    Set WshNetwork = Nothing

    If ShowInfoOutput Then
    WScript.Echo “User: ” & EnvDomainName & “\” & UserName
    WScript.Echo “Computer: ” & ComputerName
    WScript.Echo “TeamViewerID: ” & dwTVID
    End If

    If Not dwTVID = 0 Then
    ‘ only save if we did get a TeamViewer ID
    ‘ Save to userdomain, computername, username, teamviewerid to a text file with same name
    strFileName = strFolderName & “_” & EnvDomainName & “_” & ComputerName & “_” & UserName & “_” & dwTVID & “.txt”
    Set objFSO = CreateObject(“Scripting.FileSystemObject”) ‘ used for file operations
    Set objTextFile = objFSO.OpenTextFile (strFileName, ForWriting, True)
    objTextFile.WriteLine EnvDomainName & “;” & ComputerName & “;” & UserName & “;” & dwTVID
    objTextFile.Close
    End If

  • This is complete and helps in version 11, too

    Public Function GetTeamViewerPath() As String

    Const KeyName As String = “InstallationDirectory”

    Dim retStr As String
    Dim regKeys As Collection
    Dim element As Variant
    Dim RegPath(1 To 2) As String
    Dim i As Integer

    RegPath(1) = “HKLM\Software\Wow6432Node\TeamViewer\”
    RegPath(2) = “HKLM\Software\TeamViewer\”

    For i = LBound(RegPath) To UBound(RegPath)
    If retStr = “” Then
    RegistryRead RegPath(i), KeyName, retStr, “” ‘ Der Key kann ab version 11 ohen Unterverzeichnis stehen
    If retStr = “” Then
    Set regKeys = Me.RegistryEnumKeys(RegPath(i)) ‘ Der Key kann in einem Versionsunterverzeichnis stehen
    For Each element In regKeys
    Me.RegistryRead RegPath(i) & CStr(element), KeyName, retStr, “”
    If retStr “” Then
    Exit For
    End If
    Next
    End If
    End If
    Next i

    GetTeamViewerPath = retStr

    End Function

  • Sole:

    Nice Share 🙂

Leave a Reply