• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to disable and enable my Local Area Connection using scripts

M

M Shafaat

#1
Hi,
I wish to disable and enable my Local Area Connection using scripts. Can
anyone suggest a very simple script or command line using netsh etc for
doing this?



My main objective is to prevent virus attacks from the Internet when the
machine is idle by disconnetcting my PC from the home network.



Best regards,
M Shafaat
 
M

Mayayana

#2
| My main objective is to prevent virus attacks from the Internet when the
| machine is idle by disconnetcting my PC from the home network.
|

This doesn't exactly answer your question, but there
are some other options:

1) Most firewalls have an option to block all traffic.
Usually there's a popup menu in the systray. (If you're
using the Windows firewall then you really should
replace it. Like most things from Microsoft, it's
designed to be too confusing to use except in the way
that MS wants you to use it. And that means allowing
outbound traffic.)

2) I run my connection through a UPS, which I have on
my desk. I just physically pull the plug when I'm not
going online for a period of time. I used to do the same
when I used a phone modem. The UPS has sockets
to route the wire through it, so it's easy to access.
(Of course that won't help if you're using a wireless
connection.)
I like the idea of fully blocking inbound connections,
but I do it even more for outbound connections. It's
amazing how sleazy corporate software has become.
It just can't be trusted not to call home. Even Firefox,
if allowed, will go to its "first run" page to log your
IP if you don't block it. A few years ago I was installing
Norton SW 2003 for a friend and it started calling home,
so I pulled the plug on the network. After that the install
worked OK, but it stalled for a couple of minutes while it
tried in vain to get online. What was really irksome was
that the installer never said it was trying to get online. It
was designed to be dishonest.
 
M

M Shafaat

#3
Hi,
Thank you for your reply and good points of view. But as you say I still
don't get the answer to my question. So I ask you or others to give your
advice.



Regards
M Shafaat


"M Shafaat" <poppy2@newsgroup> wrote in message
news:u1HZ2JN0KHA.2196@newsgroup

> Hi,
> I wish to disable and enable my Local Area Connection using scripts. Can
> anyone suggest a very simple script or command line using netsh etc for
> doing this?
>
>
>
> My main objective is to prevent virus attacks from the Internet when the
> machine is idle by disconnetcting my PC from the home network.
>
>
>
> Best regards,
> M Shafaat
>
>
>
 
T

The Pinky

#4
maybe you have success with the DOS Command:
ipconfig /release
and
ipconfig /renew
if you retrieve your IP Adresse by DHCP this should disconnect you and after
that reconnect...
you could execute that Dos Command in a vbs script...

"M Shafaat" <poppy2@newsgroup> schrieb im Newsbeitrag
news:u1HZ2JN0KHA.2196@newsgroup

> Hi,
> I wish to disable and enable my Local Area Connection using scripts. Can
> anyone suggest a very simple script or command line using netsh etc for
> doing this?
>
>
>
> My main objective is to prevent virus attacks from the Internet when the
> machine is idle by disconnetcting my PC from the home network.
>
>
>
> Best regards,
> M Shafaat
>
>
>
 
B

BigDaddyJim

#5
On Mar 31, 5:23 pm, "The Pinky" <Edi...@newsgroup-websys.de> wrote:

> maybe you have success with the DOS Command:
> ipconfig /release
> and
> ipconfig /renew
> if you retrieve your IP Adresse by DHCP this should disconnect you and after
> that reconnect...
> you could execute that Dos Command in a vbs script...
>
> "M Shafaat" <pop...@newsgroup> schrieb im Newsbeitragnews:u1HZ2JN0KHA.2196@newsgroup
>
>
>

> > Hi,
> > I wish to disable and enable my Local Area Connection using scripts. Can
> > anyone suggest a very simple script or command line using netsh etc for
> > doing this?
>

> > My main objective is to prevent virus attacks from the Internet when the
> > machine is idle by disconnetcting my PC from the home network.
>

> > Best regards,
> > M Shafaat- Hide quoted text -
>
> - Show quoted text -
You might try a script with the DEVCON command-line exe.

http://support.microsoft.com/kb/311272

It'll allow you to enable/disable hardware of a specific ID in a
script.

Jim
 
B

BNSGuy

#6
On Mar 31, 9:02 am, "M Shafaat" <pop...@newsgroup> wrote:

> Hi,
> I wish to disable and enable my Local Area Connection using scripts. Can
> anyone suggest a very simple script or command line using netsh etc for
> doing this?
>
> My main objective is to prevent virus attacks from the Internet when the
> machine is idle by disconnetcting my PC from the home network.
>
> Best regards,
> M Shafaat
Which is most important? dis- and re-enabling your connection? or
doing so only when the computer is "idle"? The former is relatively
simple and can be done using a variety of scripting techniques, or
even batch files. I imagine the latter would not be terribly
difficult (to some) either.

I would think the most straight forward way would be to script an
event sink that is triggered by the screen saver. (not personally sure
exactly how to do that, but I've seen event triggered actions
before). when the screen saver fires, the event sink would trigger
the function to disable/re-enable the internet connection. A caveat
would be that this would require the/a screen saver to be used. This
would also allow the screen saver timeout to 'control' the actions of
the connection dis-/re-enabler.

If you are not running/able to run a screen saver, or want to define
conditions other than what would trigger the screen saver... I'm sure
it's possible, but currently out of my skill set.
 
M

M Shafaat

#7
Hi again,
I am really thankfull to all nice people who reply to my question.



I mostly prefer to write a script that "programmatically" performs exactly
the same actions that you can do manually as follows:
From the "Network Connections" window, choose a specific connection e.g.
"Local Area Connection 1", choose the menue "Disable this network device".



Another script shall do the reverse, i.e. perform the menue "Enable this
network device" on "Local Area Connection 1".



I am sure that this is possible but I don't know how to do it. It seems
likely to me that this is done easily by a command within "netsh".



Best regards
M Shafaat


"BNSGuy" <daniel.a.murray@newsgroup> wrote in message
news:c6cbd581-57ff-428f-87f8-16c7cf7ec006@newsgroup
On Mar 31, 9:02 am, "M Shafaat" <pop...@newsgroup> wrote:

> Hi,
> I wish to disable and enable my Local Area Connection using scripts. Can
> anyone suggest a very simple script or command line using netsh etc for
> doing this?
>
> My main objective is to prevent virus attacks from the Internet when the
> machine is idle by disconnetcting my PC from the home network.
>
> Best regards,
> M Shafaat
Which is most important? dis- and re-enabling your connection? or
doing so only when the computer is "idle"? The former is relatively
simple and can be done using a variety of scripting techniques, or
even batch files. I imagine the latter would not be terribly
difficult (to some) either.

I would think the most straight forward way would be to script an
event sink that is triggered by the screen saver. (not personally sure
exactly how to do that, but I've seen event triggered actions
before). when the screen saver fires, the event sink would trigger
the function to disable/re-enable the internet connection. A caveat
would be that this would require the/a screen saver to be used. This
would also allow the screen saver timeout to 'control' the actions of
the connection dis-/re-enabler.

If you are not running/able to run a screen saver, or want to define
conditions other than what would trigger the screen saver... I'm sure
it's possible, but currently out of my skill set.
 
P

Pegasus [MVP]

#8
"M Shafaat" <poppy2@newsgroup> wrote in message
news:eXUyiam0KHA.840@newsgroup

> Hi again,
> I am really thankfull to all nice people who reply to my question.
>
>
>
> I mostly prefer to write a script that "programmatically" performs exactly
> the same actions that you can do manually as follows:
> From the "Network Connections" window, choose a specific connection e.g.
> "Local Area Connection 1", choose the menue "Disable this network device".
>
>
>
> Another script shall do the reverse, i.e. perform the menue "Enable this
> network device" on "Local Area Connection 1".
>
>
>
> I am sure that this is possible but I don't know how to do it. It seems
> likely to me that this is done easily by a command within "netsh".
>
>
>
> Best regards
> M Shafaat
>
Since you haven't received many scripting solutions, here is a batch file
solution. With a small amount of effort you could translate it to a more
robust VB Script although you would still need to shell out to the Console
in order to execute devcon.exe. Note that different versions of devcon.exe
are required for Intel or AMD CPUs.

Device.bat
=======
@echo off
goto Start
---------------------------------------------------
Enable or disable a device.

Prerequisite: devcon.exe
(http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe)
16.4.2006 FNL
---------------------------------------------------
:Start
SetLocal EnableDelayedExpansion
set Adapter=Atheros AR5B93 Wireless Network Adapter

echo.
if /i "%1"=="enable" goto go
if /i "%1"=="disable" goto go
echo Syntax: Device enable / disable
goto :eof

:go
set HWID=x
set count=0
set found=no

devcon hwids "PCI\*" > "%temp%\device.txt"
for /F "tokens=*" %%* in ('type "%temp%\device.txt"') do (
set /a count=!count! + 1
if /i "%%*"=="Name: %Adapter%" set found=yes& set count=1
if !found!==yes if !count!==3 set HWID=%%*
)
if %found%==yes (
echo HWID=!HWID!
devcon %1 "!HWID!"
) else (
echo Device "%Adapter%" not found.
)
endlocal
del "%temp%\device.txt"
 
T

The Pinky

#9
Thx, cool tool...
i am sure with that its possible to realise interesting scripts :)

in the case here i am sure it should be possible to read out from WMI
the networkcards and mix the Info with registry
HKLM\System\currentControlSet\enum\PCI
and get so the Hardware ID you want to disable with the Devcon Tool :)

nice nice


"BigDaddyJim" <hungerfordj@newsgroup> schrieb im Newsbeitrag
news:95a10dc8-7fa3-4712-a834-45d23c7f87f8@newsgroup
On Mar 31, 5:23 pm, "The Pinky" <Edi...@newsgroup-websys.de> wrote:

> maybe you have success with the DOS Command:
> ipconfig /release
> and
> ipconfig /renew
> if you retrieve your IP Adresse by DHCP this should disconnect you and
> after
> that reconnect...
> you could execute that Dos Command in a vbs script...
>
> "M Shafaat" <pop...@newsgroup> schrieb im
> Newsbeitragnews:u1HZ2JN0KHA.2196@newsgroup
>
>
>

> > Hi,
> > I wish to disable and enable my Local Area Connection using scripts. Can
> > anyone suggest a very simple script or command line using netsh etc for
> > doing this?
>

> > My main objective is to prevent virus attacks from the Internet when the
> > machine is idle by disconnetcting my PC from the home network.
>

> > Best regards,
> > M Shafaat- Hide quoted text -
>
> - Show quoted text -
You might try a script with the DEVCON command-line exe.

http://support.microsoft.com/kb/311272

It'll allow you to enable/disable hardware of a specific ID in a
script.

Jim
 
M

M Shafaat

#10
Hi again,
The solution from Pegasus seems interesting to test, I would try it, thank a
lot to all.



Regards
M Shafaat
 
R

Ruediger Roesler

#11
M Shafaat <poppy2@newsgroup> typed:

> I wish to disable and enable my Local Area Connection using scripts.
> Can anyone suggest a very simple script or command line using netsh
> etc for doing this?
This script toggles all of your named network connections:

'######################### SwitchNetConn.vbs ##########################
Option Explicit
Const AUTOR = " from h.r.roesler"
' Toggles the status of a named network connection.
' For exemple:
' SwitchNetConn LAN-Connection
' If the name contains spaces, surround it with double quotes:
' SwitchNetConn "Local Area Connection"
'
Const TYP = 1, STATUS = 2, ADAPTER = 3

If WScript.Arguments.Count > 0 Then
'Switch GetCtrlFolder("Netzwerkverbindungen"), WScript.Arguments(0)
Switch GetCtrlFolder("Network Connections"), WScript.Arguments(0)
End If

Function GetCtrlFolder(strFolder)
Const ssfCONTROLS = 3
Dim xpShell, xpCtrl

Set xpShell = CreateObject("Shell.Application")
For Each xpCtrl In xpShell.NameSpace(ssfCONTROLS).Items
If xpCtrl.IsFolder Then
If StrComp(xpCtrl.Name, strFolder, vbTextCompare) = 0 Then
Set GetCtrlFolder = xpCtrl.GetFolder
Exit Function
End If
End If
Next

Err.Number = 53
Err.Description = "Virtual Folder '" & strFolder & _
"' was not found!"
Err.Raise Err.Number
End Function

Function SelConnect(ByRef xpFolder, strConn)
Dim xpItem, str

For Each xpItem In xpFolder.Items
If StrComp(xpItem.Name, strConn, vbTextCompare) = 0 Then
Set SelConnect = xpItem
Exit Function
End If
Next

Err.Number = 448
Err.Description = "Network Connection '" & strConn & _
"' was not found!"
Err.Raise Err.Number
End Function

Sub Switch(ByRef xpFolder, strConnName)
'Const ENABLE = "&Aktivieren", DISABLE = "&Deaktivieren"
Const ENABLE = "En&able", DISABLE = "Disa&ble"
Dim xpVerb, str, xpConnect

Set xpConnect = SelConnect(xpFolder, strConnName)
For Each xpVerb In xpConnect.Verbs
If xpVerb.Name = ENABLE Xor xpVerb.Name = DISABLE Then
str = xpFolder.GetDetailsOf(xpConnect, STATUS)
xpVerb.DoIt
Do
WScript.Sleep 1000
Set xpConnect = SelConnect(xpFolder, xpConnect.Name)
Loop Until str <> xpFolder.GetDetailsOf(xpConnect, STATUS)
WScript.Echo GetDetailsOf(xpConnect, xpFolder)
Exit Sub
End If
Next
End Sub

Function GetDetailsOf(ByRef xpItem, ByRef xpFolder)
Dim str

str = xpFolder.GetDetailsOf(xpItem, TYP) & " on " & vbCRLF
str = str & xpFolder.GetDetailsOf(xpItem, ADAPTER)
str = str & vbCRLF & String(79, "*") & vbCRLF
str = WScript.ScriptName&AUTOR& vbCRLF & vbCRLF & str
str = str & "Status of '" & xpItem.Name & "' at "
str = str & FormatDateTime(Date, vbLongDate) & ":" & vbCRLF

GetDetailsOf = str & vbCRLF & xpFolder.GetDetailsOf(xpItem, STATUS)
End Function

--
ЯR
 
P

Pegasus [MVP]

#13
"sonta soeung" <soeung_sonta@newsgroup> wrote in message
news:uOeZNSN7KHA.2240@newsgroup

> if i write scrip already. where the path i can put it?
>
> *** Sent via Developersdex http://www.developersdex.com ***
You can put it anywhere you like, e.g. into c:\Windows. Make sure to put
devcon.exe into c:\Windows too.