简体   繁体   English

VBScript挂在CopyFile操作上

[英]VBScript hanging on CopyFile operation

I'm trying to write a function to compare date modified on the server file to the client's and overwrite the client file if it is older. 我正在尝试编写一个函数,将服务器文件上的修改日期与客户端的日期进行比较,如果客户端文件较旧,则将其覆盖。 This runs as part of a Group Policy startup script. 这作为组策略启动脚本的一部分运行。 The tmp flies are created as a debugging step to see where the code is getting stuck. 创建tmp苍蝇是作为调试步骤,以查看代码在哪里卡住。 copyfile.tmp is created but copydone.tmp is not. 创建了copyfile.tmp,但没有创建copydone.tmp。 None of the files are read-only, and this runs under the local SYSTEM context, which has all the access it needs. 这些文件都不是只读的,并且在本地SYSTEM上下文中运行,该上下文具有所需的所有访问权限。

The files all exist. 文件全部存在。 I've successfully copied the server file to the client earlier in the script if the client didn't have one. 如果客户端没有该文件,我已经在脚本的前面部分成功地将服务器文件复制到了客户端。 ( oFSO is a file system object, strWinTemp is the system's temp directory in Windows; defined earlier) oFSO是文件系统对象, strWinTemp是Windows中系统的临时目录;前面已定义)

'Replace clientfile if older than servfile
Sub GetNewerFile(clientfile,servfile)
    Dim dtmLocalDate
    Dim dtmServerDate
    Dim oLocalFile
    Dim oServerFile
    Set oLocalFile = oFSO.GetFile(clientfile)
    dtmLocalDate = oLocalFile.DateLastModified
    Set oServerFile = oFSO.GetFile(servfile)
    dtmServerDate = oServerFile.DateLastModified

    If Not oFSO.FileExists(strWinTemp & "\" & "getnewerfile.tmp") Then oFSO.CreateTextFile(strWinTemp & "\" & "getnewerfile.tmp")
    If DateDiff("d", dtmServerDate, dtmLocalDate) > 0 Then
        'dtmServerDate is more recent than dtmLocalDate, comparison by "day"
        If Not oFSO.FileExists(strWinTemp & "\" & "copyfile.tmp") Then oFSO.CreateTextFile(strWinTemp & "\" & "copyfile.tmp")
        oFSO.CopyFile oServerFile, oLocalFile, 1
        If Not oFSO.FileExists(strWinTemp & "\" & "copydone.tmp") Then oFSO.CreateTextFile(strWinTemp & "\" & "copydone.tmp")
    End If
End Sub

I replaced the lines between the DateDiff check and End Sub with this: 我用以下代码替换了DateDiff检查和End Sub之间的行:

If oFSO.FileExists(clientfile) then oFSO.DeleteFile(clientfile)
oFSO.CopyFile servfile, clientfile, TRUE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM