none
VBScript Moving OR Copying a file from a specific path to Startup folder. RRS feed

  • Question

  • I've come across this problem, which has caused plenty of syntax fiddling and head scratching with no success, In other words, I have tried everything but yet I don't seem to be able to achieve the result I want. I want to move or copy (It doesn't really matter) the file named "Engine.vbs" from a specific path to my Startup folder. As of now, I can't copy the file and move it the startup folder, simply because no matter if I convert the .vbs file to .exe and run it as an administrator the same error pops up "Permission Denied" (Second Failure). However, if I try to move the file (First Failure) it says "File already Exists" which to me sounds wrong because in order to move a file it has to exist, also if I remove the file it says "File not found". Help would be much appreciated and please keep in mind that I'm not an experienced VBScript user.

    Thanks in advance!

    First Failure - Moving File

    Dim sCurPath 
    sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
    
    Set objShell = CreateObject("WScript.Shell")
    startupFolder = objShell.SpecialFolders("Startup")
    
    With CreateObject("Scripting.FileSystemObject")
    .MoveFile sCurPath & "\Dots_Data\Managed\Engine.vbs", startupFolder
    End With

    Second Failure - Copying File

    Dim sCurPath 
    sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
    
    Set objShell = CreateObject("WScript.Shell")
    startupFolder = objShell.SpecialFolders("Startup")
    
    With CreateObject("Scripting.FileSystemObject")
    .CopyFile sCurPath & "\Dots_Data\Managed\Engine.vbs", startupFolder
    End With
    
    set file = createobject("scripting.filesystemobject")
    
    set objshell = createobject("wscript.shell")
    
    startupfolder = objshell.specialfolders("Startup")
    
    if file.fileexists(sCurPath & "\Dots_Data\Managed\Engine.vbs") then
    file.copyfile sCurPath & "\Dots_Data\Managed\Engine.vbs",startupfolder &"\"
    end if

    Sunday, March 4, 2018 10:53 AM

Answers

  • This would probably work better:

    Set shell = CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    startupFolder = shell.SpecialFolders("Startup") & "\"
    sFilePath = fso.GetAbsolutePathName(".") & "\Dots_Data\Managed\Engine.vbs"
    fso.CopyFile sFilePath, startupFolder 
    


    \_(ツ)_/

    • Marked as answer by Zixtron Sunday, March 4, 2018 11:32 AM
    • Unmarked as answer by Zixtron Sunday, March 4, 2018 12:03 PM
    • Marked as answer by Zixtron Sunday, March 4, 2018 12:50 PM
    Sunday, March 4, 2018 11:15 AM

All replies

  • Post the complete exact error.


    \_(ツ)_/

    Sunday, March 4, 2018 10:58 AM
  • This would probably work better:

    Set shell = CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    startupFolder = shell.SpecialFolders("Startup") & "\"
    sFilePath = fso.GetAbsolutePathName(".") & "\Dots_Data\Managed\Engine.vbs"
    fso.CopyFile sFilePath, startupFolder 
    


    \_(ツ)_/

    • Marked as answer by Zixtron Sunday, March 4, 2018 11:32 AM
    • Unmarked as answer by Zixtron Sunday, March 4, 2018 12:03 PM
    • Marked as answer by Zixtron Sunday, March 4, 2018 12:50 PM
    Sunday, March 4, 2018 11:15 AM
  • Here is how to do this in PowerShell:

    Copy-Item $pwd\Dots_Data\Managed\Engine.vbs  ([environment]::GetFolderPath('Startup')) -Verbose


    \_(ツ)_/

    Sunday, March 4, 2018 11:24 AM
  • This might be easier to understand:

    $filePath = "$pwd\Dots_Data\Managed\Engine.vbs"
    $targetPath = [environment]::GetFolderPath('Startup')
    Copy-Item $filePath $targetPath -Verbose
    


    \_(ツ)_/

    Sunday, March 4, 2018 11:27 AM
  • Thank you very much, It works!!!!
    Sunday, March 4, 2018 11:32 AM