【问题标题】:Path to Program-Files on remote computer远程计算机上程序文件的路径
【发布时间】:2008-09-02 21:53:21
【问题描述】:

如何确定远程计算机上“程序文件”目录的(本地)路径?似乎没有任何版本的 SHGetFolderPath(或相关函数)将远程计算机的名称作为参数。

我想我可以尝试使用远程注册表查询 HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir,但我希望有一种“记录在案”的方式。

【问题讨论】:

    标签: winapi


    【解决方案1】:

    许多标准路径都需要用户登录,尤其是 SH* 功能,因为这些功能由“shell”(即资源管理器)提供。我怀疑您获得正确路径的唯一方法是通过您已经提到的注册表。

    【讨论】:

      【解决方案2】:

      这就是我最终做的事情:(pszComputer 必须采用“\\name”形式。nPath 是 pszPath 的大小(以 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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-12
        • 2012-07-09
        • 2013-12-07
        • 1970-01-01
        • 2017-07-11
        相关资源
        最近更新 更多