Hi all

i have a need to use a vb script to copy some files to c:\users\USERNAME\test"

so i know i can run the following to get the username

Set objNetwork = CreateObject("Wscript.Network")

but how can i then incorporate that so it copies files from say




to c:\users\USERNAME\test\


where USERNAME is the variable i have captured above

any help would be greatly appreciated


4 Comments   [ + ] Show Comments


  • Almost there...

  • thanks for this, but i have no idea what to edit in all that script to achieve what i need.
    is there no simpler way of just getting the username adding the variable found in?

    so for example
    Set objNetwork = CreateObject("Wscript.Network")
    then something to copy "c:\test.test.txt" to "c:\users\USERNAME\Test"
    • you are better off copying the file to the users profile instead of the username
      there is a lot of help for that type of script out there.

  • doesnt work with sccm as it uses system account :(
  • Can you please explain the main purpose of this request? If you are backing up a user profile then use USMT. There are some odd things about your question. Do you want to run this as the user whose name you are capturing? I think the easiest way for me to assist would be for you to explain the actual scenario that this would be applied to.
Please log in to comment



I'm not sure if this will completely satisfy your needs, but as you have written your request this will suffice:

strFile = "c:\test\test.txt"

Set objNetwork = CreateObject("WScript.Network")
strUsername = objNetwork.UserName

strCopyPath = "C:\USERS\" & strUsername & "\TEST\"

set objFSO=CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile strFile, strCopyPath, true

Change the value of strFile to the path and file you want to copy.

If the destination path of C:\USERS\%USERNAME%\TEST does not exist there will be an error.

Veritas Amor Pax

Answered 09/25/2013 by: crispybiscuit
Orange Belt

Please log in to comment
Answer this question or Comment on this question for clarity