Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a little assistance with file copy command

Status
Not open for further replies.

Count430

Programmer
Apr 26, 2002
127
US
Hello Forum

I've been assigned the tasks of creating code to copy files from one folder to another.

To start I call a value from the enviro settings "Username"

This allows me to target the current user and profile.

Next, I'm looking for the Userprofile path, from there I'm trying to copy the files from the old profile to the new username profile.

Please take a look at the following code and feel free to provide any feeback or direction i shoudl take this.

Thank to all on the furom for past solutions.

script to locate current user profile and locate older profile to copy files into target folder.

Dim Username
Dim UserProfile
Dim Source1
Dim Source2

Dim Shell
Dim CompName



Set Shell = WScript.CreateObject("WScript.Shell")

CompName = Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")

Username = shell.ExpandEnvironmentStrings("%Username%")

UserProfile = shell.ExpandEnvironmentStrings("%UserProfile%")

set fso = Wscript.CreateObject("Scripting.FilesystemObject")

Source1 = "C:\"

Source2 = "C:\documents and settings\"

if not Fso.FolderExists(Source1 & Username) then

fso.CreateFolder(Source1 & Username)

end if

if fso.FolderExists(source2 & Userprofile) then

fso.CopyFolder source2 & Userprofile, Source1 & Username


end if

 
It looks like it should work. Just as a general note, I'd place the line
Option Explicit
at the top of your code. It will enforce explicit variable naming and potentially save you trouble down the line if you become acustom to using it now.

Does the script work, or are you having troubles?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Well this script will only create the administrator folder and it places it in the source1 location.

I was wondering if there was a way to search the environment variables for the "Username" and set a temporary location where a folder with this name is created.

Next, I wanted to have the user login and create a new defualt domain profile.

I would then logon as administrator and copy the original profile settings into the default domain profiles folder.
 
Well this script will only create the administrator folder and it places it in the source1 location.
That should be true if you are logged on as Administrator when you run it. If you are logged on as a user, then it should create a folder at the root of C: with the users name as the folder name. Is this not what happens?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
yes this is what happens, but I'm looking to do a little more with the script.

I'm working on using the echo command to produce the name of the current user and then create a tempoary folder with that name.

Next, I want to allow the user to logon where DLU dynamic local user utility creates a new default profile.

Last I want the user to logoff and I will have a second script locate the two folder "Old profile" "New profile" and copy the contents from one to the next.

This will get me around the manual copy process.
 
How will the script know the old users name?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Thanks for responding, good question. When the DLU (Dynamic Local User) utility kicks in it will create a new local profile and serialize the old profile by adding a .000
to the end.

Kcouncil and Kcouncil.000

I'm looking to use the SID from the new profile and drop in the contents from the old profile location.

I'm taking classes for the first time next week with VBscript.

I know this can be accomplished, I just have a problem with the logic and the commands involved.

Thanks for your responses, they allow me to kinda pseudo walk through what I need.
 
OK, so if I log in and create a new profile, then there will be two profiles, one named tomthumbkop and another named tomthumbkop.000 and you want to move all of the content from the .000 profile into the new one? Do I understand?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
That's correct, and I'm hoping the ACL and other properties will follow, thus allowing the new profile to use the old settings.
 
I don't know about the ACL and other settings, but a simple file transfer I can work through with you if you'd like.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
That would be fine, however I do have a few utilities to use when I want to transfer the files.

Here's one example of code I use to copy the files from one folder to another.

I also welcome your walk through...

Thanks...

Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "C:\depot" , "C:\depot1" , OverWriteFiles
 
The code you posted should work for the copy, you just need to know who the current user is. You can get this from several places. try something like this:
Code:
Set oWSH = CreateObject("WScript.Shell")
strUserProfilePath = oWSH.ExpandEnvironmentStrings("%UserProfile%")
Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder strUserProfilePath & ".000" , strUserProfilePath , OverWriteFiles

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Thanks for the assistance, this code you provided is more then enough.

I created the folders in order to test this and it worked fine. Now I'll have to wrestle with weather this will be two step process and run it as a startup script.

Thanks again now I have momentum building again...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top