Hello:
I would like to copy a file from a location to %SystemRoot%. I am able to locate the variable %SystemRoot% but I am unsure how to make the file copy.
Here's what I have:
'Option Explicit 'On Error Resume Next
Const OverwriteExisting = True Dim strDC, strComputer, strUser, objNetwork, objGroup, objDomain, objFSO, objUser
Set objNetwork = CreateObject("Wscript.Network") strComputer = objNetwork.ComputerName Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")Set WshSysEnv = WshShell.Environment("SYSTEM")
WScript.Echo WshSysEnv("WINDIR")
objFSO.CopyFile "C:test.txt" , "WshSysEnv("WINDIR")", OverwriteExisting
The last line is what I am not sure about.
Any suggestions would be appreciated.
File Copy Script
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- mmacdonald
- Posts: 44
- Last visit: Thu Apr 07, 2016 7:53 am
File Copy Script
Hello:
I would like to copy a file from a location to %SystemRoot%. I am able to locate the variable %SystemRoot% but I am unsure how to make the file copy.
Here's what I have:
'Option Explicit 'On Error Resume Next
Const OverwriteExisting = True Dim strDC, strComputer, strUser, objNetwork, objGroup, objDomain, objFSO, objUser
Set objNetwork = CreateObject("Wscript.Network") strComputer = objNetwork.ComputerName Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")Set WshSysEnv = WshShell.Environment("SYSTEM")
WScript.Echo WshSysEnv("WINDIR")
objFSO.CopyFile "C:test.txt" , "WshSysEnv("WINDIR")", OverwriteExisting
The last line is what I am not sure about.
Any suggestions would be appreciated.
I would like to copy a file from a location to %SystemRoot%. I am able to locate the variable %SystemRoot% but I am unsure how to make the file copy.
Here's what I have:
'Option Explicit 'On Error Resume Next
Const OverwriteExisting = True Dim strDC, strComputer, strUser, objNetwork, objGroup, objDomain, objFSO, objUser
Set objNetwork = CreateObject("Wscript.Network") strComputer = objNetwork.ComputerName Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")Set WshSysEnv = WshShell.Environment("SYSTEM")
WScript.Echo WshSysEnv("WINDIR")
objFSO.CopyFile "C:test.txt" , "WshSysEnv("WINDIR")", OverwriteExisting
The last line is what I am not sure about.
Any suggestions would be appreciated.
File Copy Script
Very close. Try this:
Set WshShell = WScript.CreateObject("WScript.Shell")sSysRoot = WshShell.ExpandEnvironmentStrings("%WinDir%")
objFSO.CopyFile "C:test.txt" , sSysRoot, OverwriteExisting
Set WshShell = WScript.CreateObject("WScript.Shell")sSysRoot = WshShell.ExpandEnvironmentStrings("%WinDir%")
objFSO.CopyFile "C:test.txt" , sSysRoot, OverwriteExisting
- mmacdonald
- Posts: 44
- Last visit: Thu Apr 07, 2016 7:53 am
File Copy Script
These did not work or more to the point, I am not sure how to make them work. I was not able to get the value of sSysRoot to echo to to the screen.
File Copy Script
This exact script works on every machine I have tried it on:
Set WshShell = WScript.CreateObject("WScript.Shell")sSysRoot = WshShell.ExpandEnvironmentStrings("%WinDir%")WScript.Echo sSysRoot
What OS are you using?
What error message are you getting?
YOur original script had many errors in it.
This:
objFSO.CopyFile "C:test.txt" , "WshSysEnv("WINDIR")", OverwriteExisting
won't work. It has too many quotes. It will also only return unreplaced values.
If you are on Windows 2000 then you probably need to upgrade teh script subsystem.
jvierra2008-03-15 23:08:05
- mmacdonald
- Posts: 44
- Last visit: Thu Apr 07, 2016 7:53 am
File Copy Script
I tried again and it did echo to the screen and showed the correct value. My apologies. I get the error 'access denied' when I execute:
objFSO.CopyFile "C:test.txt" , sSysRoot, OverwriteExisting
objFSO.CopyFile "C:test.txt" , sSysRoot, OverwriteExisting