Search code examples
.netwindowsvb.netregistry

Access %appdata% on distant computer .NET openremotebasekey


I am trying to access the "AppData" of a user on a remote computer. I have all the rights needed. I tried this:

r = RegistryKey.OpenRemoteBaseKey(RegistryHive.Users, MachineName)
r.OpenSubKey(SIDValue & "\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders")
AppData = r.GetValue("AppData")

The fact is that it retrieves my own appdata folder...Actually the SID Value of the account on the distant computer and on mine is the same (I am under a domain). I don't know if it is the reason why I get my own appdata folder.

How should I proceed?

When I browse the HKEY_Local_Machine, I manage to have information about the remote computer..But not when browsing HKEY_USERS.


Solution

  • I found the answer myself, thanks... For those who are interested into how to do this, here is how I did:

    As browsing through HKLM did give me the good datas (the ones on the remote computer), I just searched for the systemroot value which is in HKLM\Software\Microsoft\Windows NT\CurrentVersion. Retrieving the appdata is done that way after:

    systemdrive = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, _
                                                               MachineName).OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion").GetValue("SystemRoot").ToString.Substring(0, 3)
    

    Then, For Windows XP:

    appdata = systemdrive & "Documents and Settings\" & username & "\Application Data"
    

    For Windows 7:

    appdata = systemdrive & "Users\" & username & "\AppData\Roaming"