+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, File copying at logon. in Coding and Web Development; Hi there, I am looking for a script to copy a folder + subfolders and files to a users profile. ...
  1. #1

    Join Date
    Nov 2007
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    File copying at logon.

    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.

  2. #2
    GlennT's Avatar
    Join Date
    Sep 2006
    Location
    Zummmerzet!
    Posts
    249
    Thank Post
    19
    Thanked 17 Times in 16 Posts
    Rep Power
    20
    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.

  3. #3

    Join Date
    Nov 2007
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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.

  4. #4

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    Quote Originally Posted by jinnantonnix View Post
    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:


    Code:
    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 :-)

  5. #5

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,240
    Thank Post
    1,058
    Thanked 1,068 Times in 625 Posts
    Rep Power
    740
    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

  6. #6

    Join Date
    Nov 2007
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by srochford View Post
    If you want to get the appdata folder (and the OP does!) then you can use the SpecialFolders:


    Code:
    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?

    Code:
    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

  7. #7
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    Quote Originally Posted by Bengaul View Post
    So how do I attach this to what I have already?
    Code:
    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

  8. #8

    Join Date
    Nov 2007
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by apeo View Post

    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.

  9. #9
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    Quote Originally Posted by Bengaul View Post
    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.

SHARE:
+ Post New Thread

Similar Threads

  1. copying a file without admin
    By strawberry in forum Windows
    Replies: 2
    Last Post: 20th September 2007, 09:23 AM
  2. File Copying
    By Kwyjibo in forum Scripts
    Replies: 15
    Last Post: 9th May 2007, 03:30 PM
  3. Copying videos to DVD
    By witch in forum General Chat
    Replies: 7
    Last Post: 29th December 2006, 05:43 PM
  4. Replies: 4
    Last Post: 23rd March 2006, 06:27 AM
  5. copying a file at logon
    By browolf in forum Windows
    Replies: 1
    Last Post: 18th October 2005, 04:26 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •