Windows-Server-2008

在登錄腳本 (vbs) 中使用 File.CopyHere 覆蓋沒有提示的文件

  • February 22, 2017

我正在嘗試創建一個登錄腳本(vbs)來安裝一些字型。如果安裝了字型,我會收到提示“此位置已存在同名文件”。

如何在沒有提示的情況下強制替換文件?

我的腳本如下所示:

Const FONTS = &H14&


Const FOF_SILENT = &H4&
Const FOF_RENAMEONCOLLISION = &H8&
Const FOF_NOCONFIRMATION = &H10&
Const FOF_ALLOWUNDO = &H40&
Const FOF_FILESONLY = &H80&
Const FOF_SIMPLEPROGRESS = &H100&
Const FOF_NOCONFIRMMKDIR = &H200&
Const FOF_NOERRORUI = &H400&
Const FOF_NOCOPYSECURITYATTRIBS = &H800&
Const FOF_NORECURSION = &H1000&
Const FOF_NO_CONNECTED_ELEMENTS = &H2000&


cFlags = FOF_SILENT + FOF_NOCONFIRMATION + FOF_NOERRORUI

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FONTS)
objFolder.CopyHere "\\SERVER01\Fonts\*", cFlags

MSDN 建議(16) Respond with "Yes to All" for any dialog box that is displayed.但不會阻止提示。

(我使用的是 Windows Server 2008)

http://msdn.microsoft.com/en-us/library/windows/desktop/bb787866(v=vs.85).aspx

我認為您的標誌是正確的,但請嘗試針對 Filesystem 對象呼叫 CopyFolder。

強烈推薦以下 VBscript 參考。

http://www.microsoft.com/download/en/details.aspx?id=2764

object.CopyFolder ( source, destination[, overwrite] );
Arguments
object 
Required. Always the name of a FileSystemObject. 
source 
Required. Character string folder specification, which can include wildcard characters, for one or more folders to be copied. 
destination 
Required. Character string destination where the folder and subfolders from source are to be copied. Wildcard characters are not allowed. 
overwrite 
Optional. Boolean value that indicates if existing folders are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. 
Remarks
Wildcard characters can only be used in the last path component of the source argument. For example, you can use: 

[VBScript]
FileSystemObject.CopyFolder "c:\mydocuments\letters\*", "c:\tempfolder\"

引用自:https://serverfault.com/questions/362203