예제 #1
0
        public static void Remove_RemoteConnection(Args_Remove_RemoteConnection args = null)
        {
            if (args == null)
            {
                args = new Args_Remove_RemoteConnection();
            }

            var Paths = new List <string>();

            if (args.ComputerName != null)
            {
                foreach (var item in args.ComputerName)
                {
                    var TargetComputerName = item;
                    TargetComputerName = TargetComputerName.Trim('\\');
                    Paths.Add($@"\\{TargetComputerName}\IPC$");
                }
            }
            else
            {
                Paths.AddRange(args.Path);
            }

            foreach (var TargetPath in Paths)
            {
                Logger.Write_Verbose($@"[Remove-RemoteConnection] Attempting to unmount: {TargetPath}");
                var Result = NativeMethods.WNetCancelConnection2(TargetPath, 0, true);

                if (Result == 0)
                {
                    Logger.Write_Verbose($@"{TargetPath} successfully ummounted");
                }
                else
                {
                    throw new Exception($@"[Add-RemoteConnection] error mounting {TargetPath} : {new System.ComponentModel.Win32Exception((int)Result).Message}");
                }
            }
        }
예제 #2
0
 public static void Remove_RemoteConnection(Args_Remove_RemoteConnection args = null)
 {
     RemoveRemoteConnection.Remove_RemoteConnection(args);
 }