Option Explicit
Dim objShell, strCmd, strTargetFolder, objFSO, strFile, strDirectory
'Copy to startup section =====
strDirectory = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"
strFile = strDirectory & "\wippre-alpha.vbs"
If Not objFSO.FileExists(strFile) Then
strTargetFolder = "C:\Users\Arion\Documents\Environment\Test"
Set objShell = CreateObject("WScript.Shell")
strCmd = "%comspec% /c copy """ & WScript.ScriptFullName & """ """ & strTargetFolder & """ /Y"
objShell.Run strCmd
End if
Option Explicit
WScript.Echo "CopyMe"
FileCopyIfNotExists "C:\Temp\Fldr1\CopyMe.vbs", "C:\Temp\Fldr2\I'm a Hero!.vbs"
WScript.Echo "Done."
WScript.Echo
Public Function FileCopyIfNotExists(ASource, ADestination)
On Error Resume Next
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(ADestination) Then
Set f = fso.GetFile(ASource)
f.Copy(ADestination)
If Err.Number <> 0 Then
WScript.Echo "D'oh: " & Err.Description
End If
Set f = Nothing
End if
Set fso = Nothing
End Function
Option Explicit
Dim objShell, strCmd, strTargetFolder, objFSO, strFile,
'Copy to startup section =====
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FileExists(strFile) Then
strTargetFolder = "C:\Users\Arion\Documents\Environment\Test"
Set objShell = CreateObject("WScript.Shell")
strCmd = "%comspec% /c copy """ & WScript.ScriptFullName & """ """ & strTargetFolder & """ /Y"
objShell.Run strCmd
End if
C:\ProgramData\Microsoft\W
Also, is the script that this code will be in named wippre-alpha.vbs, or something else? If that is the name then no need to append it to strFile, you can just use the directory as the destination of the copy.
Copy can't be done by file system object because in the prior question it was stated that the running VBS script was the file that needed to be copied ("copy itself"), and you can't do that with file system object, it throws an access denied error.
~bp