option explicit
dim icssc_default, connection_public, connection_private, connection_all
dim netsharingmanager
dim publicconnection, privateconnection
dim everyconnectioncollection
dim objargs
dim con
icssc_default = 0
connection_public = 0
connection_private = 1
connection_all = 2
main( )
sub main( )
if initialize() = true then
getconnectionobjects()
firewalltestbyname(con)
end if
end sub
sub firewalltestbyname(conname)
on error resume next
dim item
dim everyconnection
dim objncprops
dim szmsg
dim bfound
bfound = false
for each item in everyconnectioncollection
set everyconnection = netsharingmanager.inetsharingconfigurationforinetconnection(item)
set objncprops = netsharingmanager.netconnectionprops(item)
bfound = true
everyconnection.enableinternetfirewall
next
end sub
function initialize()
dim breturn
breturn = false
set netsharingmanager = wscript.createobject("hnetcfg.hnetshare.1")
if (isobject(netsharingmanager)) = false then
wscript.echo("unable to get the hnetcfg.hnetshare.1 object")
else
if (isnull(netsharingmanager.sharinginstalled) = true) then
wscript.echo("sharing isn't available on this platform.")
else
breturn = true
end if
end if
initialize = breturn
end function
function getconnectionobjects()
dim breturn
dim item
breturn = true
if getconnection(connection_public) = false then
breturn = false
end if
if getconnection(connection_private) = false then
breturn = false
end if
if getconnection(connection_all) = false then
breturn = false
end if
getconnectionobjects = breturn
end function
function getconnection(connection_type)
dim breturn
dim connection
dim item
breturn = true
if (connection_public = connection_type) then
set connection = netsharingmanager.enumpublicconnections(icssc_default)
if (connection.count > 0) and (connection.count < 2) then
for each item in connection
set publicconnection = netsharingmanager.inetsharingconfigurationforinetconnection(item)
next
else
breturn = false
end if
elseif (connection_private = connection_type) then
set connection = netsharingmanager.enumprivateconnections(icssc_default)
if (connection.count > 0) and (connection.count < 2) then
for each item in connection
set privateconnection = netsharingmanager.inetsharingconfigurationforinetconnection(item)
next
else
breturn = false
end if
elseif (connection_all = connection_type) then
set connection = netsharingmanager.enumeveryconnection
if (connection.count > 0) then
set everyconnectioncollection = connection
else
breturn = false
end if
else
breturn = false
end if
if (true = breturn) then
if (connection.count = 0) then
wscript.echo("no " + cstr(convertconnectiontypetostring(connection_type)) + " connections exist (connection.count gave us 0)")
breturn = false
elseif (connection.count > 1) and (connection_all <> connection_type) then
wscript.echo("error: there was more than one " + convertconnectiontypetostring(connection_type) + " connection (" + cstr(connection.count) + ")")
breturn = false
end if
end if
getconnection = breturn
end function
function convertconnectiontypetostring(connectionid)
dim connectionstring
if (connectionid = connection_public) then
connectionstring = "public"
elseif (connectionid = connection_private) then
connectionstring = "private"
elseif (connectionid = connection_all) then
connectionstring = "all"
else
connectionstring = "unknown: " + cstr(connectionid)
end if
convertconnectiontypetostring = connectionstring
end function