Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please I would like to know how I can copy files in windows using windows variable path with vbscript under elevated privillege.

What I have tried:

dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("%AppData%\file.exe") Then
filesys.CopyFile "%AppData%\file.exe", "%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\"
End If 


Dim objFso, strSourcePath, strDestPath
strSourcePath = "%AppData%\file.exe"
strDestPath = "%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\"
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(strSourcePath) then
    objFso.CopyFile strSourcePath, strDestPath, True
End If
Set objFso = Nothing


Thanks
Posted
Updated 9-Feb-20 5:07am
Comments
[no name] 9-Feb-20 11:07am    
Even if I knew, I wouldn't tell you. I disable all crud in the "Start up" and I wish everyone else knew how to also.

1 solution

The Copy method doesn't work with environment variables. You have to resolve the variables to their values first, build the paths you need using those values, then you feed those paths to the Copy method.

Return an Environment Variable - VBScript - SS64.com[^]

The FileSystemObject has a BuildPath method[^] to make building file/folder paths easier.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900