/build/static/layout/Breadcrumb_cap_w.png

VB script to get username of machine and copy files to that location from another

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

 "C:test\test1.txt"

"c:\test\test2.txt"

 

to c:\users\USERNAME\test\

 

where USERNAME is the variable i have captured above

any help would be greatly appreciated

regards


4 Comments   [ + ] Show comments
  • Almost there...

    http://myitforum.com/cs2/blogs/rbennett806/pages/vbscript-to-copy-to-a-user-profile-subfolder.aspx - anonymous_9363 10 years ago
  • 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" - keane2012 10 years ago
    • 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.

      http://community.spiceworks.com/scripts/show/732-copy-and-run-a-file-if-doesn-t-exist-in-userprofile
      https://www.google.com/search?q=vb+script+copy+file+to+user+profile&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&channel=fflb - SMal.tmcc 10 years ago
  • doesnt work with sccm as it uses system account :( - keane2012 10 years ago
  • 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. - crispybiscuit 10 years ago

Answers (1)

Posted by: crispybiscuit 10 years ago
Orange Belt
0

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

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ