Hi,
I am trying to find out live shares on our PCs, and I am using a VBScript to accomplish this. There are two problems I am facing.
I would like to create a batch file that would execute this VBScript with a parameter that would be read from a text file.
This is how I run the script now:
And I would like a text file with all the COMPUTERNAMEs and the batch would execute the VBScript on those Computers.
Secondly, this VBScript runs rather slow, as some hosts are not live currently. Can I do something to first ping the hosts and only if they respond run the rest of the script?
Thanks, any help, idea would be appreciated.
Ben
p.s.
This is the VBScript I am calling:
I am trying to find out live shares on our PCs, and I am using a VBScript to accomplish this. There are two problems I am facing.
I would like to create a batch file that would execute this VBScript with a parameter that would be read from a text file.
This is how I run the script now:
Code:
cscript CheckShare-Local.vbs /computer:COMPUTERNAME
And I would like a text file with all the COMPUTERNAMEs and the batch would execute the VBScript on those Computers.
Secondly, this VBScript runs rather slow, as some hosts are not live currently. Can I do something to first ping the hosts and only if they respond run the rest of the script?
Thanks, any help, idea would be appreciated.
Ben
p.s.
This is the VBScript I am calling:
Code:
'*************************************************************
' Script Witten by Larry Heintz
' March 2006 [URL unfurl="true"]www.windowsadminscripts.com[/URL]
' This script will reveal all user and hidden shares on a
' computer. It will show you the share name, share comment
' and share path. You will also have the option to run the
' script against a AD Domain or Work Group name. The script
' also saves the shares information into a comma delimited
' file.
'
' Script Usages:
' List Shares on Single PC: cscript shares.vbs /computer:[computername]
' List Shares on AD Domain/Work Group: cscript shares.vbs /adwg:[ad domain or workgroup name]
'*************************************************************
Dim objStdOut,args
Dim computername,adwg
Set args = Wscript.Arguments.Named
computername = args.Item("computer")
adwg = args.Item("adwg")
logpath = getLogPath()
if wscript.arguments.count = 0 then
wscript.echo "Script Usages:"
wscript.echo "List Shares on Single PC: cscript shares.vbs /computer:[computername]"
wscript.echo "List Shares on AD Domain/Work Group: cscript shares.vbs /adwg:[ad domain or workgroup name]"
elseif args.exists("computer") then
Call listShares(computername)
elseif args.exists("adwg") then
Call listSharesADWG(adwg)
end if
Function listShares(computername)
On Error Resume Next
Dim objshares,share
set objshares = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & computername & "\root\cimv2").ExecQuery("SELECT * FROM Win32_Share")
wscript.echo "Shares for " & ucase(computername) & vbcrlf
wscript.echo "Name" & space(11) & "Comment" & space(13) & "Path"
wscript.echo "=====" & space(10) & "========" & space(12) & "====="
for each share in objshares
Call writeLog(computername,share.name,share.caption,share.path)
wscript.echo share.name & space(15-(len(share.name))) & share.caption & space(20-len(share.caption)) & share.path
next
set objshares = nothing
wscript.echo ""
End Function
Function listSharesADWG(adwg)
set container = getobject("WinNT://" & adwg)
container.filter = array("computer")
for each computer in container
listShares(computer.name)
next
set container = nothing
End Function
Function getLogPath()
Dim temp,temp2
temp = split(wscript.scriptfullname,"\")
for i = 0 to ubound(temp) - 1
temp2 = temp2 & temp(i) & "\"
next
getLogPath = temp2
End Function
Function writeLog(computername,sharename,sharecomment,sharepath)
Dim FSO,objFSOwriteline
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFSOwriteline = FSO.OpenTextFile(getLogPath() & "\shares.csv", 8,True)
objFSOwriteline.WriteLine(computername & "," & sharename & "," & sharecomment & "," & sharepath)
objFSOwriteline.close
Set objFSOwriteline = nothing
Set FSO = nothing
End Function