如何从远程计算机获取CommonApplicationData?

时间:2011-09-09 00:56:27

标签: .net windows wmi remote-access

我希望在远程计算机上获得“CommonApplicationData”的路径。

这是本地版

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

但我该怎么做呢?也许有一些WMI?

1 个答案:

答案 0 :(得分:2)

完成了工作

public static string GetCommonAppData(string machineName)
{
    var shellFoldersPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders";
    using (var remoteBaseKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machineName))
    using (var shellFolders = remoteBaseKey.OpenSubKey(shellFoldersPath))
    {
        return (string) shellFolders.GetValue("Common AppData");
    }
}