Announcement

Collapse
No announcement yet.

Script unable to extract data.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script unable to extract data.

    I have this script run perfectly fine in windows 2008. But its show nothing in Windows 2003. Was there anything wrong?

    Code:
    Const xlSaveChanges = 1
    
    On Error Resume Next
    YearNo = Right(year(date),2)
    If month(date) <= 10 then MonthNo = "0" & month(date) else MonthNo = month(date) end if
    If Day(date) <= 10 then DayNo = "0" & Day(date) else DayNo = Day(date) end if
    
        Dim nSvr() 
        p = 0 
        Set objnFSO = CreateObject("Scripting.FileSystemObject") 
        Set objnFile = objnFSO.OpenTextFile(".\ListSvr.txt", 1) 
                
        Do Until objnFile.AtEndOfStream 
            Redim Preserve nSvr(p) 
            nSvr(p) = objnFile.ReadLine 
            p = p + 1 
        Loop 
        objnFile.Close 
            
                Dim arrFileLines() 
                i = 0 
                Set objFSO = CreateObject("Scripting.FileSystemObject") 
                Set objFile = objFSO.OpenTextFile(".\ListSvc.txt", 1) 
                
                Do Until objFile.AtEndOfStream 
                    Redim Preserve arrFileLines(i) 
                    arrFileLines(i) = objFile.ReadLine 
                    i = i + 1 
                Loop 
                objFile.Close 
                
        For q = 0 to Ubound(nSvr) 
            strComputer = nSvr(q)
            Set objWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
            Set colRunningServices = objWMIService.ExecQuery _
                ("Select * from Win32_Service")
            
            Set objExcel = CreateObject("Excel.Application")
            objExcel.Visible = False
            objExcel.Workbooks.Add        
                                      
                    nrow = 1
                    ncol = 1
                                
                            For l = 0 to Ubound(arrFileLines) 
                                For Each objService in colRunningServices 
                                  If objService.DisplayName = arrFileLines(l) Then
                                   If objService.StartMode <> "Disabled" Then
                                    objExcel.Cells(nrow, ncol).Value = objService.DisplayName
                                    ncol = ncol + 1
                                    objExcel.Cells(nrow, ncol).Value = objService.State
                                    If objService.State = "Stopped" and objService.StartMode = "Auto" Then
                                     objExcel.Cells(nrow, ncol).Font.ColorIndex = 3
                                    End If
                                    ncol = ncol + 1
                                    objExcel.Cells(nrow, ncol).Value = objService.StartMode
                                    nrow = nrow + 1
                                    ncol = 1
                                   End If
                                  End If
                                Next
                            Next
                    
                        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
                        Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
                        For Each objItem in colItems
                            nrow = nrow + 1
                             objExcel.Cells(nrow, ncol).Value = "Name:"
                            ncol = ncol + 1
                             objExcel.Cells(nrow, ncol).Value = objItem.Name
                            nrow = nrow + 1
                            ncol = 1
                             objExcel.Cells(nrow, ncol).Value = "FreeSpace:"
                            ncol = ncol + 1
                             objExcel.Cells(nrow, ncol).Value = objItem.FreeSpace/1024\1024+1 & " MB"
                             If objItem.FreeSpace/1024\1024+1 < 1000 Then
                              objExcel.Cells(nrow, ncol).Font.ColorIndex = 3
                             End If
                            nrow = nrow + 1
                            ncol = 1
                             objExcel.Cells(nrow, ncol).Value = "Size:"
                            ncol = ncol + 1
                             objExcel.Cells(nrow, ncol).Value = objItem.Size/1024\1024+1 & " MB"
                            nrow = nrow + 1
                            ncol = 1
                        Next
                    
            objExcel.ActiveWorkbook.SaveAs ("C:\Users\khchan\Desktop\Daily Check\" & YearNo & MonthNo & DayNo & "_" & strComputer & ".xls")
            objExcel.Workbooks.Close
            objExcel.Quit
                
    
        Next
    
    Msgbox "Done!"
    Last edited by Rems; 26th April 2012, 07:49. Reason: [code]-tags

  • #2
    Re: Script unable to extract data.

    make sure that the path "C:\Users\khchan\Desktop\Daily Check\" is created on the windows server 2003 computers before running the script.


    /Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Script unable to extract data.

      Server 2003 uses "C:\Documents & Settings" rather than "C:\Users" for user profiles so that might affect it - use a system variable instead (%userprofile% IIRC)

      When you say "it shows nothing", does it create a file?
      Tom Jones
      MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
      PhD, MSc, FIAP, MIITT
      IT Trainer / Consultant
      Ossian Ltd
      Scotland

      ** Remember to give credit where credit is due and leave reputation points where appropriate **

      Comment


      • #4
        Re: Script unable to extract data.

        Thanks Rems and Ossian for prompt reply.

        Problem solved

        Comment

        Working...
        X