Jump to content

Recommended Posts

Posted

Hi there,

 

I am looking for a script to copy a folder + subfolders and files to a users profile. I have been looking on the MS website, but as yet have not found one I think is suitable.

 

The closest I have come is the following:

 

Set oFSO = CreateObject("Scripting.FileSystemObject")

 

If oFSO.FileExists("C:\documents and settings\%username%\Application data") Then

oFSO.GetFile("C:\documents and settings\%username%\Application data\Macromedia").Attributes = 0 'In case it is read-only

oFSO.CopyFile "\\server\folder\file.exe", "c:\folder\", True

End If

 

However, it does not seem to work. The UNC path was changed for the real script! Has anyone got an idea of how I could make this work? Or perhaps a script they know will work?

 

Many thanks,

 

Bengaul.

Posted

Just out of interest, what was this to fix?

The only reason I ask is that we had a problem with Flash not loading correctly and I had to write a similar script to correct it.

If I remember correctly I had to copy a folder to the "All Users" profile though.

Posted

Thanks for the reply,

 

GlennT, the script is in a similar vain to your problem. We use a website that uses a plugin for shockwave. This plugin only seems to want to install in a users profile, thus proving a problem as we do not allow kids admin rights to install, and if I install, it only installs in my profile. I have tried the all users, and default users profile, with no success. I thought perhaps this may be a quick way round...

 

jinnantonnix, thanks for your reply. I shall give it a go, and let you know.

 

Bengaul.

Posted
The %username% isn't going to work, that expansion is done by DOS not VBS. However, in VBS you can use:

Dim oShell

Dim UserName

 

Set oShell = Wscript.CreateObject("Wscript.Shell")

UserName = oShell.ExpandEnvironmentStrings("%USERNAME%")

 

WScript.Echo UserName

 

This will get you the username.

 

If you want to get the appdata folder (and the OP does!) then you can use the SpecialFolders:

 

 

Set oShell = CreateObject("WScript.Shell")
sAppDataDir = oShell.SpecialFolders("AppData")
Wscript.Echo sAppDataDir

 

This copes with re-directed app data folders (which we use!) and also copes with the fact that sometimes you get things like c:\docs and settings\username.001\application data.

 

It also works for Vista (which changes the profile location). This may not matter but someone must be using Vista :-)

Posted

The AutoIT route is also quite effective for this - I've used these macros a few times:

 

@AppDataDir path to current user's Application Data

@DesktopDir path to current user's Desktop

@MyDocumentsDir path to My Documents target

@FavoritesDir path to current user's Favorites

@ProgramsDir path to current user's Programs (folder on Start Menu)

@StartMenuDir path to current user's Start Menu

@StartupDir current user's Startup folder

@UserProfileDir Path to current user's Profile folder

Posted
If you want to get the appdata folder (and the OP does!) then you can use the SpecialFolders:

 

 

Set oShell = CreateObject("WScript.Shell")
sAppDataDir = oShell.SpecialFolders("AppData")
Wscript.Echo sAppDataDir

 

This copes with re-directed app data folders (which we use!) and also copes with the fact that sometimes you get things like c:\docs and settings\username.001\application data.

 

It also works for Vista (which changes the profile location). This may not matter but someone must be using Vista :-)

 

So how do I attach this to what I have already?

 

Set oShell = CreateObject("WScript.Shell")
sAppDataDir = oShell.SpecialFolders("AppData")
Set oFSO = CreateObject("Scripting.FileSystemObject")


If oFSO.FileExists(appdata"\macromedia") Then
oFSO.GetFile("C:\documents and settings\%username%\Application data\Macromedia").Attributes = 0 'In case it is read-only
oFSO.CopyFile "\\server\folder\file.exe", "c:\folder\", True
End If 

Posted
So how do I attach this to what I have already?

 

Set oShell = CreateObject("WScript.Shell")
sAppDataDir = oShell.SpecialFolders("AppData")
Set oFSO = CreateObject("Scripting.FileSystemObject")


If oFSO.FileExists(appdata & "\macromedia") Then
oFSO.GetFile("appdata & "\macromedia"").Attributes = 0 'In case it is read-only
oFSO.CopyFile "\\server\folder\file.exe", "c:\folder\", True
End If 

 

Im not sure what you are doing here tho:

 

oFSO.CopyFile "\\server\folder\file.exe", "c:\folder\", True

Posted

 

Im not sure what you are doing here tho:

 

oFSO.CopyFile "\\server\folder\file.exe", "c:\folder\", True

 

Ah, that is the path to the folder on the server where the folder to be copied is kept, the folder where it is meant to go, and overwrite TRUE. Although I am uncertain if this is the correct way to script it. :confused:

Posted
Ah, that is the path to the folder on the server where the folder to be copied is kept, the folder where it is meant to go, and overwrite TRUE. Although I am uncertain if this is the correct way to script it. :confused:

 

So you check to see if the Macromedia folder exist in Appdata and if it does you copy a file from the server to a folder on the c: drive and thats it? Seems odd to me to check for a folder then copy to another folder altogether. Sorry I should have been clearer when i said "Im not sure what you are doing here tho", i meant why are you coping the file to what seems to be a random location on the C: drive.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



  • 46 When would you like EduGeek EDIT 2025 to be held?

    1. 1. Select a time period you can attend


      • I can make it in June\July
      • I can make it in August\Sept
      • Other time period. Comment below
      • Either time

×
×
  • Create New...