VBS Script To Return A Specified Machines Share Information And Send To Excel

 

This VBS script will take a machine name from an input dialog box and will write the machines share information to an Excel spreadsheet.

 

The Excel spreadsheet will include the following information: Share name, share description, the share path and the share type such as if it is a print queue or an IPC share.

 

VBS Script:

 

strComputer = InputBox ("Enter Machine Name")

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

objExcel.Cells(1, 1).Value = "Name"

objExcel.Cells(1, 2).Value = "Description"

objExcel.Cells(1, 3).Value = "Path"

objExcel.Cells(1, 4).Value = "Type"

 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")

For each objShare in colShares

 

objExcel.Cells(intRow, 1).Value = objShare.Name

objExcel.Cells(intRow, 2).Value = objShare.Description

objExcel.Cells(intRow, 3).Value = objShare.Path

 

If objShare.Type = 0 Then

objExcel.Cells(intRow, 4).Value = "Disk Drive"

ElseIf objShare.Type = 1 Then

objExcel.Cells(intRow, 4).Value = "Print Queue"

objExcel.Cells(intRow, 4).Value = "Device"

ElseIf objShare.Type = 3 Then

objExcel.Cells(intRow, 4).Value = "IPC"         

ElseIf objShare.Type = -2147483645 Then

objExcel.Cells(intRow, 4).Value = "IPC Admin"

ElseIf objShare.Type = -2147483648 Then

objExcel.Cells(intRow, 4).Value = "Disk Drive Admin"

ElseIf objShare.Type = -2147483649 Then

objExcel.Cells(intRow, 4).Value = "Print Queue Admin"

ElseIf objShare.Type = -2147483650 Then

objExcel.Cells(intRow, 4).Value = "Device Admin"

End If

 

intRow = intRow + 1

Next

 

objExcel.Range("A1:D1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

 

Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

Set objRange = objExcel.Range("A1")

objRange.Sort objRange,1,,,,,,1

 

MsgBox "Done"

 

 

 

Published Sunday, May 18, 2008 7:28 AM by dhite
Filed under:

Comments

No Comments