none
Query on Copying a software from one share folder to servers local path ( C:\windows\system32) RRS feed

  • Question

  • Hi,

    I have a script ready to copy the file from source to destination.But the problem is , in few machine it says " Could not find file C:\WINDOWS\System32\Portqry.exe" and in other  machines it works fine .

    Does anyone have any idea how to fix that ?

    Const DestinationFile = "C:\windows\system32"
    Const SourceFile = "\\server\xxxx\portqry.exe"

    Set fso = CreateObject("Scripting.FileSystemObject")
    'Check to see if the file already exists in the destination folder
    '------------------------------------------------------------------
        If fso.FileExists(DestinationFile) Then
    'Check to see if the file is read-only
    '--------------------------------------
            If Not fso.GetFile(DestinationFile).Attributes And 1 Then 
    'The file exists and is not read-only.  Safe to replace the file.
    '-------------------------------------------------------------------
                fso.CopyFile SourceFile, "C:\windows\system32\", True
            Else 
                'The file exists and is read-only.
                'Remove the read-only attribute
                fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes - 1
                'Replace the file
                fso.CopyFile SourceFile, "C:\windows\system32\", True
                'Reapply the read-only attribute
                fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes + 1
            End If
        Else
            'The file does not exist in the destination folder.  Safe to copy file to this folder.
            fso.CopyFile SourceFile, "C:\windows\system32\", True
        End If
    Set fso = Nothing


    • Edited by Mcteer Sunday, February 28, 2016 11:01 AM
    Sunday, February 28, 2016 9:57 AM

Answers

  • I was running this script locally on Windows 10 machine there I got Permission Denied error.

    Is there any fix for this ?

    Note : I was able to access all the folder locally and remotely.Not sure why the issue trigering

    In Vista and later this folder is protected.  You cannot copy or replace files without special permission.


    \_(ツ)_/

    • Marked as answer by Mcteer Monday, February 29, 2016 9:56 AM
    Sunday, February 28, 2016 6:04 PM

All replies

  • Bad logic?

    If you look for a file that doesn't exist then you will fail. You  need to account for your failure.


    \_(ツ)_/

    Sunday, February 28, 2016 11:26 AM
  • This is all you need.  'ReadOnly' is not important.  You must be an admin to do this which trumps the readonly bit.

    You are not aprogrammer.  Trying to look like one (and  doing a bad job of it) willonly defeat you.

    This is all you need:

    Const SourceFile = "\\server\xxxx\portqry.exe"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    fso.CopyFile SourceFile, "C:\windows\system32\", True

    Look at it and try to understand why I removed most lines.

    This would be the same in a batch file:

    copy \\server\xxxx\portqry.exe C:\windows\system32 /Y

    Notice the "/Y"

    VBScript is no different from Windows.

    In PowerShell we would do this:

    copy \\server\xxxx\portqry.exe C:\windows\system32 -Force

    Don't waste your time learning VBScript,  It is a dead system.


    \_(ツ)_/


    • Edited by jrv Sunday, February 28, 2016 11:41 AM
    Sunday, February 28, 2016 11:39 AM
  • Thanks Jrv.

    But even in two of my machines the above script is not working. but its working in other machine.The error I am getting is " Microsoft VBScript runtime error: Permission denied"

    Sunday, February 28, 2016 11:51 AM
  • In Windows 8 and later you cannot remotely alter the contents of that folder without making changes.

    \_(ツ)_/

    Sunday, February 28, 2016 12:16 PM
  • I was running this script locally on Windows 10 machine there I got Permission Denied error.

    Is there any fix for this ?

    Note : I was able to access all the folder locally and remotely.Not sure why the issue trigering

    Sunday, February 28, 2016 4:28 PM
  • I was running this script locally on Windows 10 machine there I got Permission Denied error.

    Is there any fix for this ?

    Note : I was able to access all the folder locally and remotely.Not sure why the issue trigering

    In Vista and later this folder is protected.  You cannot copy or replace files without special permission.


    \_(ツ)_/

    • Marked as answer by Mcteer Monday, February 29, 2016 9:56 AM
    Sunday, February 28, 2016 6:04 PM