Bengaul Posted January 31, 2008 Report Posted January 31, 2008 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.
GlennT Posted January 31, 2008 Report Posted January 31, 2008 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.
Bengaul Posted January 31, 2008 Author Report Posted January 31, 2008 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.
srochford Posted January 31, 2008 Report Posted January 31, 2008 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 :-)
mattx Posted January 31, 2008 Report Posted January 31, 2008 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
Bengaul Posted February 1, 2008 Author Report Posted February 1, 2008 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
apeo Posted February 1, 2008 Report Posted February 1, 2008 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
Bengaul Posted February 1, 2008 Author Report Posted February 1, 2008 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.
apeo Posted February 4, 2008 Report Posted February 4, 2008 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. 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now