hello ,

you can try the following code to list shared files & folders,

   * class Program
    {
        [DllImport("advapi32.DLL", SetLastError = true)]
        public static extern int LogonUser(string lpszUsername, string
lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref
IntPtr phToken);

        static void Main(string[] args)
        {
            IntPtr admin_token = default(IntPtr);
            WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
            WindowsIdentity wid_admin = null;
            WindowsImpersonationContext wic = null;
            try
            {
                Console.WriteLine("List of files ...");
                if (LogonUser("username", "domain", "p...@ssw0rd!", 9, 0, ref
admin_token) != 0)
                {
                    wid_admin = new WindowsIdentity(admin_token);
                    wic = wid_admin.Impersonate();
                    string[] list =
System.IO.Directory.GetFiles("\\\\IP-Address\\sharedFolderName\\");



                }
                else
                {
                    Console.WriteLine("Copy Failed");
                }
            }
            catch (System.Exception se)
            {
                int ret = Marshal.GetLastWin32Error();
                Console.WriteLine(ret.ToString(), "Error code: " +
ret.ToString());
                Console.WriteLine(se.Message);
            }
            finally
            {
                if (wic != null)
                {
                    wic.Undo();
                }
            }
        }
    }
*



Thanks & Regards,
Shrinivas Mada,




On Tue, Jun 29, 2010 at 1:15 AM, Michael Busch <
[email protected]> wrote:

> HI Guys.
>
> I have a problem.
>
> I want to list all shared network folders in my program. Thats working
> fine, code below.
>
> BUT I would like to show also the UNC name of the share (like
> \\server\folder\)
> This is not working.
>
> Does somebody can help me, and show to get this information.
> Volume Label is showing me the label of the drive volume, but not the share
> name.
>
>
>
> current code (short version)
>
>
> *public* *void* listNetworkFolders(*ref* DataTable dt)
>
> {
>
> dt.Rows.Clear();
>
> System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();
>
> *foreach* (System.IO.DriveInfo d *in* allDrives)
>
> {
>
> *if* (d.DriveType.ToString().Contains("Network"))
>
> {
>
> DataRow row = dt.NewRow();
>
> row[0] = d.Name + " " + d.VolumeLabel.ToString();
>
> dt.Rows.Add(row);
>
> }
>
> }
>
> }
>
>
>
> Thanks in advance.
>
>
>
> Michael
>

Reply via email to