jes
Posts: 34
Joined: Mon Oct 23, 2017 12:51 pm

Copying file from Documents folder to Program files folder

Tue Mar 13, 2018 6:43 am

Hi,

Could someone please help me to solve the below scenario:

I need to copy a file from My Documents folder to "C:\Program Files (x86)\Folder" at the time of Maintenance/Repair of the application in the advanced installer(First time installation works fine). And that action should take place silently. Since the CopyFile is used in ProgramFiles folder, I need administrative privileges to run the script.
The following is the current script that am using:

dim objFSO, strSource, strTarget,strTarget1
set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
userProfilePath = objShell.ExpandEnvironmentStrings("%UserProfile%")
strSource= userProfilePath & "\Documents\"
strTarget = "C:\Program Files (x86)\Folder\folder1\"
strTarget1 = "C:\Program Files (x86)\Folder\folder2\"


dim strTempSource, strTempTarget,strTempTarget1
set strTempSource = objFSO.GetFolder(strSource)

file=userProfilePath & "\Documents\SQLConnections.xml"

If objFSO.FolderExists(strTarget) Then
set strTempTarget = objFSO.GetFolder(strTarget)
If objFSO.FileExists(userProfilePath & "\Documents\SQLConnections.xml") Then
objFSO.CopyFile file, strTarget,True
End If
End If

If objFSO.FolderExists(strTarget1) Then
set strTempTarget1 = objFSO.GetFolder(strTarget1)
If objFSO.FileExists(userProfilePath & "\Documents\SQLConnections.xml") Then
objFSO.CopyFile file, strTarget1,True
End If
End If


After opening cmd with adminstrative rights, and when running the code on cmd, it works fine. But when I put the code in advancded installer, it doesn't works.

Thanks in advance.

Daniel
Posts: 8237
Joined: Mon Apr 02, 2012 1:11 pm
Contact:  Website

Re: Copying file from Documents folder to Program files folder

Wed Mar 14, 2018 12:28 pm

Hello,

You can try to use our "Launch file" predefined custom action and check its "Run as administrator" flag.

Also, as another possible solution you can try to use our "File Copy Operation" support and see if this helps. Just go to "Files and Folders" page, select your directory under "Program Files" and in the right pane create a new file copy operation.

Let us know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Feature Requests”