在登录脚本 (vbs) 中使用 File.CopyHere 覆盖文件而不提示

在登录脚本 (vbs) 中使用 File.CopyHere 覆盖文件而不提示

我正在尝试创建一个登录脚本 (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

答案1

我认为您已正确设置了标志,但请尝试针对 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\"

相关内容