You're accessing the machine using the default admin share for the drive (d$), it's unlikely you amended the permissions for that as you need to be admin to access it. Access the folder via a proper network share so you can control the rights, don't use "d$" - that's a "hack" share.
\\computername\sharedfoldername
to remove the sharename from the output (call the function as normal)
static void DirSearch(string dir, string rootDir = null)
{
if (rootDir == null)
{
rootDir = dir;
}
try
{
foreach (string f in Directory.GetFiles(dir))
{
string filename = f.Substring(rootDir.Length);
Console.WriteLine(filename);
}
foreach (string d in Directory.GetDirectories(dir))
{
Console.WriteLine(d);
DirSearch(d, rootDir);
}
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
}