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
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)
Please log in to answer
Posted by:
Teitan
13 years ago
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
13 years ago
1. To be honest, taking a quick look it seems messy. To make it work, it should probably be this:
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.
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
13 years ago
Posted by:
captain_planet
13 years ago
You probably need a backslash at the end of your appdata folder:
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?
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
13 years ago
Posted by:
roni86
13 years ago
Posted by:
anonymous_9363
13 years ago
Posted by:
roni86
13 years ago
Posted by:
anonymous_9363
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.