Question

Comment déterminer le chemin (local) du répertoire « Program Files » sur un ordinateur distant ?Aucune version de SHGetFolderPath (ou fonction associée) n'apparaît qui prend le nom d'un ordinateur distant comme paramètre.

Je suppose que je pourrais essayer d'interroger HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir en utilisant un registre distant, mais j'espérais qu'il y aurait une manière "documentée" de le faire.

Était-ce utile?

La solution

De nombreux chemins standards nécessitent qu'un utilisateur soit connecté, en particulier les fonctions SH* car celles-ci sont fournies par le "shell", c'est-à-dire l'Explorateur.Je soupçonne que la seule façon d'obtenir le bon chemin est de passer par le registre, comme vous l'avez déjà mentionné.

Autres conseils

Voilà ce que j'ai fini par faire :(pszComputer doit être sous la forme "\ ame".nPath est la taille de pszPath (en TCHAR))

DWORD GetProgramFilesDir(PCTSTR pszComputer, PTSTR pszPath, DWORD& nPath) 
{
    DWORD n;
    HKEY hHKLM;
    if ((n = RegConnectRegistry(pszComputer, HKEY_LOCAL_MACHINE, &hHKLM)) == ERROR_SUCCESS)
    {
        HKEY hWin;
        if ((n = RegOpenKeyEx(hHKLM, _T("Software\\Microsoft\\Windows\\CurrentVersion"), 0, KEY_READ, &hWin)) == ERROR_SUCCESS)
        {
            DWORD nType, cbPath = nPath * sizeof(TCHAR);
            n = RegQueryValueEx(hWin, _T("ProgramFilesDir"), NULL, &nType, reinterpret_cast<PBYTE>(pszPath), &cbPath);
            nPath = cbPath / sizeof(TCHAR);
            RegCloseKey(hWin);
        }
        RegCloseKey(hHKLM);
    }
    return n;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top