Question : Batch or VBS file to turn on ICS in XP

Hello, I would like to create a batch file or something that I can run to turn on Internet Connection Sharing for a connection when run.

 I have been looking for the command that will control ICS but have not been able to find anything yet.

Thank you for your help,
Jacob

Answer : Batch or VBS file to turn on ICS in XP

Hello Friends, thank to John Fenske I finally have a solution!

Here is a VB script that will change the connection. I had to pass the parameters of the connections names into the script.

See code snippit....

I saved the script to my C: as network.vbs and then made a batch file to call this script:

cscript network.vbs "NAME_OF_LAN" "NAME_OF_WAN

And it worked like a charm!
Thanks again to John Fenske!

Jacob Bushnell
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
' VBScript source code
OPTION EXPLICIT
 
DIM ICSSC_DEFAULT, CONNECTION_PUBLIC, CONNECTION_PRIVATE, CONNECTION_ALL
DIM NetSharingManager
DIM PublicConnection, PrivateConnection
DIM EveryConnectionCollection
 
DIM objArgs
DIM priv_con, publ_con
 
ICSSC_DEFAULT         = 0
CONNECTION_PUBLIC     = 0
CONNECTION_PRIVATE    = 1
CONNECTION_ALL        = 2
 
Main( )
 
sub Main( )
    Set objArgs = WScript.Arguments
 
    if objArgs.Count = 2 then
        priv_con = objArgs(0)
        publ_con = objArgs(1)
      
        if Initialize() = TRUE then    
            GetConnectionObjects()
 
            FirewallTestByName priv_con,publ_con
        end if
    else
        DIM szMsg
 
        if Initialize() = TRUE then    
            GetConnectionObjects()
 
            FirewallTestByName "list","list"
        end if
        
        szMsg = "To share your internet connection, please provide the name of the private and public connections as the argument." & vbCRLF & vbCRLF & _
                "Usage:" & vbCRLF & _ 
                "       " & WScript.scriptname & " " & chr(34) & "Private Connection Name" & chr(34) & " " & chr(34) & "Public Connection Name" & chr(34) 
        WScript.Echo( szMsg & vbCRLF & vbCRLF)                
    end if
 
end sub
 
 
sub FirewallTestByName(con1,con2)
on error resume next
    DIM Item
    DIM EveryConnection
    DIM objNCProps
    DIM szMsg
    DIM bFound1,bFound2
    
    WScript.echo(vbCRLF & vbCRLF)
    bFound1 = false
    bFound2 = false        
    for each Item in EveryConnectionCollection
        set EveryConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
        set objNCProps = NetSharingManager.NetConnectionProps(Item)
        szMsg = "Name: "       & objNCProps.Name & vbCRLF & _
                "Guid: "       & objNCProps.Guid & vbCRLF & _
                "DeviceName: " & objNCProps.DeviceName & vbCRLF & _
                "Status: "     & objNCProps.Status & vbCRLF & _
                "MediaType: "  & objNCProps.MediaType
        if EveryConnection.SharingEnabled then
            szMsg = szMsg & vbCRLF & _
                    "SharingEnabled" & vbCRLF & _
                    "SharingType: " & ConvertConnectionTypeToString(EveryConnection.SharingConnectionType)
        end if
        
        if objNCProps.Name = con1 then
            bFound1 = true
            if EveryConnection.SharingEnabled = False then
                szMsg = szMsg & vbCRLF & "Not Shared... Enabling private connection share..."
                WScript.Echo(szMsg)
                EveryConnection.EnableSharing CONNECTION_PRIVATE
                szMsg = " Shared!"
            end if
        end if
        
        if objNCProps.Name = con2 then
            bFound2 = true
            if EveryConnection.SharingEnabled = False then
                szMsg = szMsg & vbCRLF & "Not Shared... Enabling public connection share..."
                WScript.Echo(szMsg)
                EveryConnection.EnableSharing CONNECTION_PUBLIC
                szMsg = " Shared!"
            end if
        end if           
        WScript.Echo(szMsg & vbCRLF & vbCRLF)
    next
    
    if( con1 <> "list" ) then
        if( bFound1 = false ) then
            WScript.Echo( "Connection " & chr(34) & con1 & chr(34) & " was not found" )
        end if
        if( bFound2 = false ) then
            WScript.Echo( "Connection " & chr(34) & con2 & chr(34) & " was not found" )
        end if
    end if
    
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
        'valid to have more than 1 connection returned from EnumEveryConnection
        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
    Wscript.Echo(CStr(Connection.Count) + " objects for connection type " + ConvertConnectionTypeToString(CONNECTION_TYPE))
    
    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
Random Solutions  
 
programming4us programming4us