VB脚本 - 备份Win 7配置文件

时间:2014-03-25 15:26:23

标签: windows vbscript

我正在尝试创建一个VBScript,以便在替换PC时备份Windows 7配置文件。

目前我有:

Option Explicit

Const SHARENAME = "c:\NHSITTemp"

Dim fldr,subfldr
Dim sUser
Dim shl, fso

Set shl = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FilesystemObject")

'this gets 'Documents and Settings'
Set fldr = fso.GetFolder( _
                Replace(shl.ExpandEnvironmentStrings("%USERPROFILE%"), _
                shl.ExpandEnvironmentStrings("%USERNAME%"), _
                ""))
'for each folder in fldr
For Each subfldr In fldr.SubFolders
  If fso.FolderExists(subfldr.Path & "\Desktop") Then
    sUser = subfldr.Name
    if not fso.FolderExists(SHARENAME & "\" & sUser) Then
      Call fso.CreateFolder(SHARENAME & "\" & sUser)
    End If
    Call fso.CopyFolder(subfldr.Path & "\Desktop", _
                        SHARENAME & "\" & sUser & "\Desktop")
  End If
Next

Set fso = Nothing
Set shl = Nothing
WScript.Quit

这是第13行产生的错误,我想不通,有什么想法吗?

1 个答案:

答案 0 :(得分:0)

<强>更新

Option Explicit

Const SHARENAME = "c:\NHSITTemp"

Dim fldr,subfldr
Dim sUser
Dim shl, fso

Set shl = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FilesystemObject")

'this gets 'Documents and Settings'
 Set fldr = fso.GetFolder(Replace(Replace(_
            shl.ExpandEnvironmentStrings("%USERPROFILE%"),_
            shl.ExpandEnvironmentStrings("%USERNAME%"),""), "\\", ""))
'for each folder in fldr
For Each subfldr In fldr.SubFolders
  If fso.FolderExists(subfldr.Path & "\Desktop") Then
    sUser = subfldr.Name
    if not fso.FolderExists(SHARENAME & "\" & sUser) Then
           fso.CreateFolder SHARENAME & "\" & sUser
    End If
    fso.CopyFolder subfldr.Path & "\Desktop", SHARENAME & "\" & sUser & "\Desktop"
  End If
Next

Set fso = Nothing
Set shl = Nothing
WScript.Quit