public PersistentConnection(string networkName,
                                    NetworkCredential credentials)
        {
            _networkName = networkName;

            var netResource = new NetResource()
            {
                Scope        = ResourceScope.GlobalNetwork,
                ResourceType = ResourceType.Disk,
                DisplayType  = ResourceDisplaytype.Share,
                RemoteName   = networkName
            };

            var userName = string.IsNullOrEmpty(credentials.Domain)
                ? credentials.UserName
                : string.Format(@"{0}\{1}", credentials.Domain, credentials.UserName);

            var result = WNetAddConnection2(
                netResource,
                credentials.Password,
                userName,
                0);

            CleanupLog.WriteLine($"Connection Result: {result}");

            if (result != 0 && result != 1219)
            {
                throw new Win32Exception(result, "Error connecting to remote share");
            }
        }
예제 #2
0
 static void HandleException(Exception e)
 {
     //Handle your Exception here
     CleanupLog.WriteLine($"ERROR! {e}");
 }
        protected override void OnStop()
        {
            CleanupLog.WriteMethod();

            CleanupHelper.StopCleanup();
        }
        public TVShowCleanupService()
        {
            InitializeComponent();

            CleanupLog.WriteMethod();
        }
        protected override void OnStart(string[] args)
        {
            CleanupLog.WriteMethod();

            Task.Run(() => CleanupHelper.StartCleanup());
        }