using windows service to copy file through network(LAN)
-
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
-
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
-
Run the service using a domain account that has the proper permissions on both computers.
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 -
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, 2006You 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 --------------------