Esempio n. 1
0
 static void Main()
 {
     try
     {
         //const String path = @"d:\";
         //using (var diskShadow = new DiskShadow(path))
         //{
         //    diskShadow.DoSnapshot();
         //    foreach (var snapshot in diskShadow.GetSnapshotList())
         //    {
         //        String fullPath = Path.Combine(snapshot, "test.txt");
         //        Console.WriteLine(fullPath);
         //        Console.WriteLine(PathIsUNCW(fullPath));
         //        int pbCancel = 0;
         //        try
         //        {
         //            CopyFileEx(fullPath, @"d:\test1.txt", null, IntPtr.Zero, ref pbCancel, CopyFileFlags.None);
         //            uint errorCode = checked((uint)Marshal.GetLastWin32Error());
         //            Console.WriteLine(errorCode);
         //            if ((int)errorCode == 80)
         //                Console.WriteLine("Skipped.");
         //            else
         //            {
         //                Console.WriteLine("Unknown.");
         //            }
         //            Console.WriteLine("Copy finished.");
         //        }
         //        catch (Exception e)
         //        {
         //            Console.WriteLine(e);
         //        }
         //    }
         //    Console.ReadKey(true);
         //    diskShadow.DeleteSnapshotSet();
         //}
         //int pbCancel = 0;
         //try
         //{
         //    //Console.WriteLine(PathIsUNCW(@"\\10.2.5.41\d$\test.txt"));
         //    Console.WriteLine(CopyFileEx(@"D:\test.txt", @"D:\test1.txt", null, IntPtr.Zero, ref pbCancel, CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS));
         //    Console.WriteLine(Marshal.GetLastWin32Error());
         //}
         //catch (Exception e)
         //{
         //    Console.WriteLine(e);
         //}
         String path = @"\\10.2.54.59\NETSHARE@{7D073DBF-188F-448F-A303-493E5C7516B5}";
         NETRESOURCEW[] n = new NETRESOURCEW[1];
         n[0] = new NETRESOURCEW();
         n[0].dwType = 1;
         n[0].lpLocalName = null;
         n[0].lpRemoteName = path;
         n[0].lpProvider = null;
         WNetCancelConnection2(path, 0, true);
         n[0].lpRemoteName = path;
         Console.WriteLine(WNetAddConnection2W(n, "1qaz2wsx!", @"base\gaoqiang", 1));
         path = @"\\VM6110SQL31\NETSHARE\C2";
         WNetCancelConnection2(path, 0, true);
         n[0].lpRemoteName = path;
         Console.WriteLine(WNetAddConnection2W(n, "1qaz2wsx!", @"base\gaoqiang", 1));
         Console.ReadLine();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Esempio n. 2
0
 private static extern int WNetAddConnection3(IntPtr hWndOwner,
     ref NETRESOURCEW lpNetResource, string lpPassword,
     string lpUserName, int dwFlags);