/build/static/layout/Breadcrumb_cap_w.png

VB Script to Copy File from Current Folder to %Appdata%

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

Answers (9)

Posted by: Teitan 12 years ago
Senior Purple Belt
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
Posted by: captain_planet 12 years ago
Black Belt
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.
Posted by: fiqa 12 years ago
Senior Yellow Belt
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
Posted by: captain_planet 12 years ago
Black Belt
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?
Posted by: fiqa 12 years ago
Senior Yellow Belt
0
It works. Thanks a lot Captain_Planet for prompt reply. Really appreciate it
Posted by: roni86 12 years ago
Blue Belt
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.
Posted by: anonymous_9363 12 years ago
Red Belt
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.
Posted by: roni86 12 years ago
Blue Belt
0
my my shorcut points to an no exe file. will self-healing work then ?
Posted by: anonymous_9363 12 years ago
Red Belt
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.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
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