Thank you for getting me started down the path of the
creating a service to accomplish this. I created the
service with the code you provided me. However, I do have
few more challenges which I could use some more help.
The first challenge, is that I need a way to debug the
service before I deploy it, if this is possible.
The second challenge is that I need to copy the entire
directory underneath "Documents and Settings\rtaranti" for
example to my back up drive (Ex. h:\profiles) I hace
attempted to use the following code:
'************************************************* *
FSO = CreateObject("Scripting.FileSystemObject")
If (FSO.FolderExists(sDestinationFolderPath)) Then
FSO.CopyFolder(sSourceFolderPath, sDestinationFolderPath)
End If
'************************************************* **
My problem here is that some files in the subfolders, such
as the user.dat is locaked and cannot be copied. This
prevents the FileScripting object fomr continuing it's
job.
I noticed on my windows 2000 server machine, I have the
ability to perform the "CopyTo" method through
the "UserProfiles" tab under "My Computer/properites" to
copy the profile that I am logged in as to another
profile. This action seems to able to copy all the files
even though they are in session. Is there a way to re-use
code or objects like that?...Or someway to copy all the
files without having the process fail?
Thanks for all your help!
-Robert
-----Original Message-----
Hi Robert,
Here I write a sample for you. Hope this will help you.
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
private static bool flag;
protected override void OnStart(string[]
args) {
Thread wd = new Thread(new
ThreadStart(RunThread)); flag=true;
wd.Start();
}
/// Stop this service.
protected override void OnStop()
{
flag = false;
allDone.WaitOne();
}
private static void RunThread()
{
while(flag)
{
try
{
File.Copy
(@"c:\a.txt",@"\\fileserver\fsaf\b.txt",true); // thefileserver is where your network drive lies
}
catch(Exception e)
{ // to log the
exception. StreamWriter sr =
File.AppendText(@"C:\service.log"); sr.WriteLine
(e.StackTrace.ToString()); sr.Flush();
sr.Close();
}
finally
{
}
}
allDone.Set();
}
Here is a link about how to write a windows service.
Please have a try and let me if this does the job for you.
Cheers!
--------------------Content-Class: urn:content-classes:message
From: "Robert Tarantino" <rt******@promega.com>
Sender: "Robert Tarantino" <rt******@promega.com>
Subject: Copying Local Profile to network drive in .NET
Date: Mon, 18 Aug 2003 14:52:14 -0700
Lines: 10
Message-ID: <0b****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNl0vxGha0FcRubQmyplraTC0riuw==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.general:104941NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.general
Hello,
I am trying to find a way to create a scheduled task or
service that will copy my local profile folders
under "Documents and settings" to a network drive. This
would allow me to restore my settings if my profile
becametampered with or corrupt. Is there any sample code
available out there?
-Robert
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and
confers no rights.
.