static public string GetUniversalPath(string path) { bool IncludeAdminShares = false; string universalPath = ""; try { GetNetShares gns = new GetNetShares(); // First attempt - ignore administrative shares (eg c$) foreach (GetNetShares.ShareInfo shareInfo in gns.EnumNetShares("127.0.0.1")) { if (((shareInfo.ShareType & (uint)GetNetShares.SHARE_TYPE.Special) == 0)) { if (string.Compare(path.Substring(0, shareInfo.Path.Length), shareInfo.Path, StringComparison.OrdinalIgnoreCase) == 0) { return(Path.Combine(String.Concat(@"\\", Environment.MachineName, @"\", shareInfo.ShareName), path.Replace(shareInfo.Path, "").TrimStart('\\'))); } } } // Second attempt - include administrative shares (eg c$) if enabled if (IncludeAdminShares) { foreach (GetNetShares.ShareInfo shareInfo in gns.EnumNetShares("127.0.0.1")) { if (((shareInfo.ShareType) == 0) || (IncludeAdminShares)) { if (string.Compare(path.Substring(0, shareInfo.Path.Length), shareInfo.Path, StringComparison.OrdinalIgnoreCase) == 0) { return(Path.Combine(String.Concat(@"\\", Environment.MachineName, @"\", shareInfo.ShareName), path.Replace(shareInfo.Path, "").TrimStart('\\'))); } } } } } catch { universalPath = path; } return(universalPath); }
public override CommandResult Execute(CommandResult pipeIn) { string server = _arguments.Get <StringArgument>("Server").Value; server = server.Replace(@"\\", ""); GetNetShares gns = new GetNetShares(); GetNetShares.SHARE_INFO_1[] shares = gns.EnumNetShares(server); foreach (GetNetShares.SHARE_INFO_1 share in shares) { _results.Add( new ResultRecord() { { "Name", share.shi1_netname }, { "Description", share.shi1_remark } //{ "Type", share.shi1_type.ToString() } } ); } return(_results); }
public static string GetUniversalPath(string path) { bool IncludeAdminShares = false; string universalPath = ""; try { GetNetShares gns = new GetNetShares(); // First attempt - ignore administrative shares (eg c$) foreach (GetNetShares.ShareInfo shareInfo in gns.EnumNetShares("127.0.0.1")) { if (((shareInfo.ShareType & (uint)GetNetShares.SHARE_TYPE.Special) == 0)) { if (string.Compare(path.Substring(0, shareInfo.Path.Length), shareInfo.Path, StringComparison.OrdinalIgnoreCase) == 0) { return Path.Combine(String.Concat(@"\\", Environment.MachineName, @"\", shareInfo.ShareName), path.Replace(shareInfo.Path, "").TrimStart('\\')); } } } // Second attempt - include administrative shares (eg c$) if enabled if (IncludeAdminShares) { foreach (GetNetShares.ShareInfo shareInfo in gns.EnumNetShares("127.0.0.1")) { if (((shareInfo.ShareType) == 0) || (IncludeAdminShares)) { if (string.Compare(path.Substring(0, shareInfo.Path.Length), shareInfo.Path, StringComparison.OrdinalIgnoreCase) == 0) { return Path.Combine(String.Concat(@"\\", Environment.MachineName, @"\", shareInfo.ShareName), path.Replace(shareInfo.Path, "").TrimStart('\\')); } } } } } catch { universalPath = path; } return universalPath; }