search file extension

Author Message
butcha33

  • Total Posts : 6
  • Scores: 0
  • Reward points : 0
  • Joined: 8/15/2008
  • Status: offline
search file extension Friday, August 15, 2008 1:38 AM (permalink)
0
Hi, i am having problem with this script. It works perfect on my local machine and all remote machines but only on the C drive! If i try to search for a *.mp3 on any other partition other than C it fails with this error message. New to scripting so your help will be appreciated
 
cheers
 
Butcha
 
Line 45
Char 1
The Remote Procedure Call Failed
800706BE
Source (null)
 
'on error resume next

servername = InputBox ("Enter Machine Name" & (Chr(13) & Chr(10)) & "Example: dc-live-it028 ", "My Audit by Shieraz B")
If servername = "" then
WScript.quit
end if
drive = InputBox ("Enter Drive Letter" & (Chr(13) & Chr(10)) & "Example: C / D  (Case sensitive)", "My Audit by Shieraz B")
If drive = "" then
WScript.quit
end if
strExtension = InputBox ("Enter File Extension" & (Chr(13) & Chr(10)) & "Example: mp3", "My Audit by Shieraz B")
If strExtension = "" then
WScript.quit
end if
strDrive = drive & ":"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
x = 2
objExcel.Cells(1, 1).Value = "File Name"
objExcel.Cells(1, 2).Value = "File Size"
objExcel.Cells(1, 3).Value = "Path (" & servername & " " & strDrive & ")"
objExcel.Cells(1, 4).Value = "Creation Date"
objExcel.Cells(1, 5).Value = "Last Accessed"

objExcel.Range("A1:E1").Select
objExcel.Selection.Interior.ColorIndex = 15
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

Set objWMIService = GetObject("winmgmts:\\" & servername & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile Where Drive = '" & strDrive & "' And Extension = '" & strExtension & "'")
For Each objItem in colFiles
objExcel.Cells(x, 1).Value = objItem.FileName
objExcel.Cells(x, 2).Value = FormatNumber(objItem.FileSize/1024/1024,1) & " MB"
objExcel.Cells(x, 3).Value = objItem.Path
objExcel.Cells(x, 4).Value = ConvWbemTime(objItem.CreationDate)
objExcel.Cells(x, 5).Value = ConvWbemTime(objItem.LastAccessed)
x = x + 1
Next
Function ConvWbemTime(IntervalFormat)
sMonth = mid(IntervalFormat,5,2)
sDay = mid(IntervalFormat,7,2)
sYear = mid(IntervalFormat,1,4)
sHour = mid(IntervalFormat,9,2)
sMinutes = mid(IntervalFormat,11,2)
sSeconds = mid(IntervalFormat,13,2)
ConvWbemTime = sMonth & "-" & sDay & "-" & sYear & " " & sHour & ":" & sMinutes & ":" & sSeconds
End Function

objExcel.Range("A1:E1").Select
objExcel.Selection.Interior.ColorIndex = 15
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
Set objRange = objExcel.Range("A2")
objRange.Sort objRange,1,,,,,,1

objExcel.Cells(x, 1).Font.Bold = TRUE
objExcel.Cells(x, 1).Font.Size = 10
objExcel.Cells(x, 1).Value = "Search Completed, Save the spreadsheet!"
 
'MsgBox "Done"

 
#1
    turranx

    • Total Posts : 59
    • Scores: 0
    • Reward points : 0
    • Joined: 2/7/2006
    • Location: Cincinnati, OH
    • Status: offline
    RE: search file extension Friday, August 15, 2008 5:15 AM (permalink)
    0
    This is not a Powershell Script.  Please re-post in the 'WSH & Client Side VBScript" section of this forum.

    Which line is 45?  When I look for 45, I get "sYear = mid(IntervalFormat,1,4)".  The error your reporting doesn't make sense for this line of code.  I'm thinking your line 45 is different from mine.

    I tried it on my own workstation.  It worked fine for every drive letter I chose; including those that didn't exist (B:\).  My suggestion to you is to start using MSE7.exe and start stepping through your code line by line.  The error might occur on line 45 but be caused by something a few lines earlier.

    <message edited by turranx on Friday, August 15, 2008 5:42 AM>
    Microsoft Windows 2000 Scripting Guide - The best book for newbie scripters
    http://www.myspace.com/Evil__Overlord
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9