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
Answers (1)
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
http://myitforum.com/cs2/blogs/rbennett806/pages/vbscript-to-copy-to-a-user-profile-subfolder.aspx - anonymous_9363 11 years ago
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 11 years ago
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 11 years ago