Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. using windows service to copy file through network(LAN)

using windows service to copy file through network(LAN)

Scheduled Pinned Locked Moved C#
sysadminquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ctlqt12
    wrote on last edited by
    #1

    How could i do to copy a file to a shared folder ( that shared folder is on server ) by using Windows service? when I ran code : File.Copy("c:\\tempFile.txt","\\\\192.168.0.1\\SharedFile\\tempFile.txt",True) in windows application, it worked well. But when i used windows service, that code didn't work. It seems that shared folder is not found when you use path:"\\\\192.168.0.1\\SharedFile\\tempFile.txt". It seems that Windows Service will run under another desktop which is different from the logoned interactive desktop. So how could i access shared folder by using windows service? Please give me some advice. Any ideas will be welcomed

    K 1 Reply Last reply
    0
    • C ctlqt12

      How could i do to copy a file to a shared folder ( that shared folder is on server ) by using Windows service? when I ran code : File.Copy("c:\\tempFile.txt","\\\\192.168.0.1\\SharedFile\\tempFile.txt",True) in windows application, it worked well. But when i used windows service, that code didn't work. It seems that shared folder is not found when you use path:"\\\\192.168.0.1\\SharedFile\\tempFile.txt". It seems that Windows Service will run under another desktop which is different from the logoned interactive desktop. So how could i access shared folder by using windows service? Please give me some advice. Any ideas will be welcomed

      K Offline
      K Offline
      KevinMac
      wrote on last edited by
      #2

      Run the service using a domain account that has the proper permissions on both computers.

      C 1 Reply Last reply
      0
      • K KevinMac

        Run the service using a domain account that has the proper permissions on both computers.

        C Offline
        C Offline
        ctlqt12
        wrote on last edited by
        #3

        Thanks for your reply. Yes, i have permission on both computers. I run following code : 'Domain account String user = "UserName"; String p = "PassWord"; SecureString pass = new SecureString(); 'Create pass for(i=0; i< p.Length; i++) pass.AppendChar(p[i]); 'Copy file Process.start("cmd","/c copy c:\\temp.txt \\\\ServerName\\SharedFolder",user,pass, "DomainName"); That code run well on winform application but when running in windows service, it alerts "Access denies". It means it couldn't find the correct path to SharedFolder when using windows service. So please tell me what correct path to access that SharedFolder by using Windows Service? -- modified at 9:57 Sunday 26th November, 2006

        W 1 Reply Last reply
        0
        • C ctlqt12

          Thanks for your reply. Yes, i have permission on both computers. I run following code : 'Domain account String user = "UserName"; String p = "PassWord"; SecureString pass = new SecureString(); 'Create pass for(i=0; i< p.Length; i++) pass.AppendChar(p[i]); 'Copy file Process.start("cmd","/c copy c:\\temp.txt \\\\ServerName\\SharedFolder",user,pass, "DomainName"); That code run well on winform application but when running in windows service, it alerts "Access denies". It means it couldn't find the correct path to SharedFolder when using windows service. So please tell me what correct path to access that SharedFolder by using Windows Service? -- modified at 9:57 Sunday 26th November, 2006

          W Offline
          W Offline
          Weckmann
          wrote on last edited by
          #4

          You need to install your service itself under a domain user account. This is done in the ServiceProcessInstaller, search for something like: this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User; this.serviceProcessInstaller1.Username = "abcd@mydomain.com"; this.serviceProcessInstaller1.Password = "mypassword"; This would already be the working version. You probably have a ServiceAccount.System or something else. And null values as username and password. Try it this way.

          -------------------- Bertram Weckmann www.svizzer.com --------------------

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups