Hi,
I am trying to copy file from current folder to %appdata%. Problem is when I used objShell.ExpandEnvironmentStrings method it gives me error path not found. Can someone look at my script let me know what I am doing wrong.
Thanks
Script is
Option Explicit
Dim oWSH, oFSO, strAppData, objShell
Set oWSH = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
oWSH.CurrentDirectory = oFSO.GetParentFolderName(WScript.ScriptFullName)
Set objShell = CreateObject("WScript.Shell")
strAppData=objShell.ExpandEnvironmentStrings("%APPDATA%")
oFSO.CopyFile "config.xml", "strAppData\", True
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Try this:


Option Explicit
Dim oWSH, oFSO, strAppData, objShell
Set oWSH = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oUserEnv = oWSH.Environment("User")
oWSH.CurrentDirectory = oFSO.GetParentFolderName(WScript.ScriptFullName)
Set objShell = CreateObject("WScript.Shell")
strAppData=oUserEnv("%APPDATA%")
oFSO.CopyFile "config.xml", "strAppData\", True
Answered 07/21/2011 by: Teitan
Senior Purple Belt

Please log in to comment
0
1. To be honest, taking a quick look it seems messy. To make it work, it should probably be this:

Option Explicit
Dim oFSO, strAppData, objShell
Set objShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
objShell.CurrentDirectory = oFSO.GetParentFolderName(WScript.ScriptFullName)
strAppData=objShell.ExpandEnvironmentStrings("%APPDATA%")
oFSO.CopyFile "config.xml", strAppData, True
Set objShell = Nothing
Set oFSO = Nothing


3. But do you really want to copy the script to your source file location in order to perform the copy?
4. If you're doing this from a windows installer, you can use the MoveFile table for this, by setting the Options flag to 0.
Answered 07/22/2011 by: captain_planet
Second Degree Brown Belt

Please log in to comment
0
Thanks Teitan & Captain_Planet. I tried both of your script & getting the following error

When I tried Captain_Planet
Error: Line 7
Char 1
Permission denied ( although I am running as a admin)

When I tried Teitan's script
Error: Line 9
Char 1
Path not found

Thanks
Answered 07/22/2011 by: fiqa
Senior Yellow Belt

Please log in to comment
0
You probably need a backslash at the end of your appdata folder:
Option Explicit
Dim oFSO, strAppData, objShell
Set objShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
objShell.CurrentDirectory = oFSO.GetParentFolderName(WScript.ScriptFullName)
strAppData=objShell.ExpandEnvironmentStrings("%APPDATA%") & "\"
oFSO.CopyFile "config.xml", strAppData, True
Set objShell = Nothing
Set oFSO = Nothing


But like I said, I'm still not convinced you're doing this the right way. What exactly are you trying to do? Is this meant to happen during an MSI installation?
Answered 07/22/2011 by: captain_planet
Second Degree Brown Belt

Please log in to comment
0
It works. Thanks a lot Captain_Planet for prompt reply. Really appreciate it
Answered 07/22/2011 by: fiqa
Senior Yellow Belt

Please log in to comment
0
could someone help me on this one:
I need to copy an ini file to %appdata% the msi will be instaled on the system accound.
Im try for 3 days to do it :( whitout an reboot.
Answered 07/26/2011 by: roni86
Blue Belt

Please log in to comment
0
Forget script. That's the "using hammer to drive in a screw" solution.

Do the job properly. Search AppDeploy for "self-healing". There are many, many posts which will help you.
Answered 07/26/2011 by: VBScab
Red Belt

Please log in to comment
0
my my shorcut points to an no exe file. will self-healing work then ?
Answered 07/26/2011 by: roni86
Blue Belt

Please log in to comment
0
EXEs aren't the only entry-points for advertising. I'm sure you can Google the rest but, if you're app doesn't feature any of them, you can use Active Setup as an alternative.
Answered 07/26/2011 by: VBScab
Red Belt

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