Showing posts with label VB Script. Show all posts
Showing posts with label VB Script. Show all posts

Wednesday, 10 July 2013

VBScrip - List a Perticular Service of All WMI Enabled Computers

On Error Resume Next

InputFile = ("c:\computers.txt")
OutputFile = ("c:\result.txt")
Service = ("netlogon")

Set oFS = CreateObject("Scripting.FileSystemObject")
Set f = oFS.OpenTextFile(InputFile)
Set fr = oFS.CreateTextFile(OutputFile, True)

Computers = f.ReadAll
f.Close
arrComputers = Split(Computers,  vbCrLf)

fr.WriteLine("Server" & vbTab & "Services" & vbTab & "State")

For Each strComputer in arrComputers
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\cimv2")
    Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")

    For Each objService in colRunningServices 
        If objService.DisplayName = Service Then
            fr.WriteLine(strComputer & vbTab & objService.DisplayName & vbTab & objService.State)
        End If
    Next
Next
MsgBox "Service gathering complete", 0, "Info"

Batch File: List a Perticular Service of All WMI Enabled Computers

@echo off
for /F %%s in (d:\Servers.txt) do (
  echo Processing %%s
  echo Processing %%s >> d:\Services.txt
  sc.exe \\%%s query netlogon >> d:\Services.txt
  echo. >> d:\Services.txt
)

Friday, 22 February 2013

VB Script: Retrieving Extended Files Properties of all files in folder, and import all attributes to Excel file.

To list extended Properties of files inside folder, use below script.

Save script in any localtion, i;e C:\Script.vbs, run below command

C:\>cscript //nologo script.vbs > report.csv

In addition, depending on the OS version, the properties are in different order and there may be many more.  Win XP has 33 standard items, but Win 7 has 286 and the order of some of them differ between the two OSs.

Script,...

--------------------------------------------------------------------------------------
Dim arrHeaders()
  
Set objShell = CreateObject("Shell.Application")Set objFolder = objShell.Namespace("D:\Database")
  
On error resume nextFor i = 0 to 287
  redim preserve arrHeaders(i)
  arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
  if err.number <> 0 then exit forNextOn error goto 0
wsh.echo "File Name" & "," & Join(arrHeaders, ",")
   
For Each strFileName in objFolder.Items
  wsh.stdout.write strFileName 
  For j = 0 to i - 1
    wsh.stdout.write "," & objFolder.GetDetailsOf(strFileName, j) 
  Next
  wsh.echo
Next