如何确定';我的文件';使用VBScript的本地计算机上每个用户的文件夹?

如何确定';我的文件';使用VBScript的本地计算机上每个用户的文件夹?,vbscript,Vbscript,我对此束手无策。要么我做得不对,要么这是不可能的 我需要一个用于以下场景的vb脚本: 该脚本将在多台Windows7计算机上运行(32位和64位相似) 这些是共享工作站,即不同的用户不时登录到这些机器 此脚本的目标是遍历每个用户配置文件文件夹,并获取每个用户配置文件文件夹中“我的文档”文件夹的大小。此信息将写入计算机上C:\Temp目录下的.CSV文件 此脚本将从SCCM推送到所有工作站。它将被配置为使用系统权限执行 我在以下位置尝试了详细的脚本: 脚本中的Wscript.Echo objFo

我对此束手无策。要么我做得不对,要么这是不可能的

我需要一个用于以下场景的vb脚本:

  • 该脚本将在多台Windows7计算机上运行(32位和64位相似)

  • 这些是共享工作站,即不同的用户不时登录到这些机器

  • 此脚本的目标是遍历每个用户配置文件文件夹,并获取每个用户配置文件文件夹中“我的文档”文件夹的大小。此信息将写入计算机上C:\Temp目录下的.CSV文件

  • 此脚本将从SCCM推送到所有工作站。它将被配置为使用系统权限执行

  • 我在以下位置尝试了详细的脚本:

    脚本中的Wscript.Echo objFolder.Size
    命令将当前登录用户的值返回为“0”(零)。虽然实际大小大约为30 MB

    然后我尝试了以下脚本:

    此脚本返回正确的值,但仅针对当前登录的用户

    Const blnShowErrors = False
    
    ' Set up filesystem object for usage
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("WScript.Shell")
    
    ' Display desired folder sizes
    Wscript.Echo "MyDocuments : " & FormatSize(FindFiles(objFSO.GetFolder(objShell.SpecialFolders("MyDocuments"))))
    
    
    ' Recursively tally the size of all files under a folder
    ' Protect against folders or files that are not accessible
    Function FindFiles(objFolder)
       On Error Resume Next
    
       ' List files
       For Each objFile In objFolder.Files
           On Error Resume Next
           If Err.Number <> 0 Then ShowError "FindFiles:01", objFolder.Path
           On Error Resume Next
           FindFiles = FindFiles + objFile.Size
           If Err.Number <> 0 Then ShowError "FindFiles:02", objFile.Path
       Next
    
       If Err.Number = 0 Then
           ' Recursively drill down into subfolder
           For Each objSubFolder In objFolder.SubFolders
               On Error Resume Next
               If Err.Number <> 0 Then ShowError "FindFiles:04", objFolder.Path
               FindFiles = FindFiles + FindFiles(objSubFolder)
               If Err.Number <> 0 Then ShowError "FindFiles:05", objSubFolder.Path
           Next
       Else
           ShowError "FindFiles:03", objFolder.Path
       End If
    End Function
    
    ' Function to format a number into typical size scales
    Function FormatSize(iSize)
       aLabel = Array("bytes", "KB", "MB", "GB", "TB")
       For i = 0 to 4
          If iSize > 1024 Then iSize = iSize / 1024 Else Exit For End If
       Next
       FormatSize = Round(iSize, 2) & " " & aLabel(i)
    End Function
    
    Sub ShowError(strLocation, strMessage)
       If blnShowErrors Then
          WScript.StdErr.WriteLine "==> ERROR at [" & strLocation & "]"
          WScript.StdErr.WriteLine "    Number:[" & Err.Number & "], Source:[" & Err.Source & "], Desc:[" &  Err.Description & "]"
          WScript.StdErr.WriteLine "    " & strMessage
          Err.Clear
       End If
    End Sub
    
    Const blnshowers错误=False
    '设置要使用的文件系统对象
    设置objFSO=CreateObject(“Scripting.FileSystemObject”)
    设置objShell=CreateObject(“WScript.Shell”)
    '显示所需的文件夹大小
    Echo“MyDocuments:”&FormatSize(findFile(objFSO.GetFolder(objShell.SpecialFolders(“MyDocuments”)))
    '递归地统计文件夹下所有文件的大小
    '针对无法访问的文件夹或文件进行保护
    函数FindFiles(objFolder)
    出错时继续下一步
    '列出文件
    对于objFolder.Files中的每个objFile
    出错时继续下一步
    如果错误号为0,则返回错误“FindFiles:01”,objFolder.Path
    出错时继续下一步
    FindFiles=FindFiles+objFile.Size
    如果错误号为0,则返回错误“FindFiles:02”,objFile.Path
    下一个
    如果Err.Number=0,则
    '递归深入到子文件夹中
    对于objFolder.SubFolders中的每个objSubFolder
    出错时继续下一步
    如果错误号为0,则返回错误“FindFiles:04”,objFolder.Path
    FindFiles=FindFiles+FindFiles(objSubFolder)
    如果错误号为0,则返回错误“FindFiles:05”,objSubFolder.Path
    下一个
    其他的
    淋浴ROR“FindFiles:03”,objFolder.Path
    如果结束
    端函数
    '函数将数字格式化为典型尺寸比例
    函数FormatSize(iSize)
    阿拉贝尔=数组(“字节”、“KB”、“MB”、“GB”、“TB”)
    对于i=0到4
    如果iSize>1024,则iSize=iSize/1024 Else为End If退出
    下一个
    FormatSize=圆形(iSize,2)和“阿拉贝尔”(i)
    端函数
    子淋浴ROR(标准位置、标准消息)
    如果是布林豪斯那么
    WScript.StdErr.WriteLine“==>在[”&strLocation&“]处出错
    WScript.StdErr.WriteLine“编号:[“&Err.Number&]”,来源:[“&Err.Source&]”,说明:[“&Err.Description&]”
    WScript.StdErr.WriteLine“”&strMessage
    呃,明白了
    如果结束
    端接头
    
    唯一有待解决的部分是为每个其他用户配置文件文件夹中的“我的文档”文件夹实现这一点

    这可能吗


    请帮助。

    我怀疑问题出在权限上。Windows7就是这样。。。尝试在C:\users中的每个文件夹上执行类似于
    fso.GetFolder(“C:\users\[blah]\Documents”).Size的操作,很可能会在每个文件夹上都出现拒绝访问错误。
    
    Const blnShowErrors = False
    
    ' Set up filesystem object for usage
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("WScript.Shell")
    
    ' Display desired folder sizes
    Wscript.Echo "MyDocuments : " & FormatSize(FindFiles(objFSO.GetFolder(objShell.SpecialFolders("MyDocuments"))))
    
    
    ' Recursively tally the size of all files under a folder
    ' Protect against folders or files that are not accessible
    Function FindFiles(objFolder)
       On Error Resume Next
    
       ' List files
       For Each objFile In objFolder.Files
           On Error Resume Next
           If Err.Number <> 0 Then ShowError "FindFiles:01", objFolder.Path
           On Error Resume Next
           FindFiles = FindFiles + objFile.Size
           If Err.Number <> 0 Then ShowError "FindFiles:02", objFile.Path
       Next
    
       If Err.Number = 0 Then
           ' Recursively drill down into subfolder
           For Each objSubFolder In objFolder.SubFolders
               On Error Resume Next
               If Err.Number <> 0 Then ShowError "FindFiles:04", objFolder.Path
               FindFiles = FindFiles + FindFiles(objSubFolder)
               If Err.Number <> 0 Then ShowError "FindFiles:05", objSubFolder.Path
           Next
       Else
           ShowError "FindFiles:03", objFolder.Path
       End If
    End Function
    
    ' Function to format a number into typical size scales
    Function FormatSize(iSize)
       aLabel = Array("bytes", "KB", "MB", "GB", "TB")
       For i = 0 to 4
          If iSize > 1024 Then iSize = iSize / 1024 Else Exit For End If
       Next
       FormatSize = Round(iSize, 2) & " " & aLabel(i)
    End Function
    
    Sub ShowError(strLocation, strMessage)
       If blnShowErrors Then
          WScript.StdErr.WriteLine "==> ERROR at [" & strLocation & "]"
          WScript.StdErr.WriteLine "    Number:[" & Err.Number & "], Source:[" & Err.Source & "], Desc:[" &  Err.Description & "]"
          WScript.StdErr.WriteLine "    " & strMessage
          Err.Clear
       End If
    End Sub