![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Enable/Disable Network Connection Can I write a Powershell Script that will toggle (Enable/Disable) a Network Connection? Can I also toggle the Firewall on a Network Connection? Thank you, Fred Jacobowitz |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Enable/Disable Network Connection Hi Fred > Can I write a Powershell Script that will toggle (Enable/Disable) a > Network Connection? Can I also toggle the Firewall on a Network > Connection? There are currently no CmdLets available for these tasks. However, as for disabling the firewall you can still use netsh: Enable/disable firewall PS> netsh firewall set opmode mode=disable PS> netsh firewall set opmode mode=enable Enable/disable firewall for a particular interface PS> netsh firewall set opmode mode=enable interface=Interface-Name PS> netsh firewall set opmode mode=disable interface=Interface-Name As for disabling an interface I guess you need devcon (I have never used this tool): http://support.microsoft.com/?scid=k...1272&x=17&y=10 hth Max |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Enable/Disable Network Connection I was hoping there would be something in the .NET library that could enable/disable a named network connection. I located The Win32_NetworkConnection WMI class but the ConnectionState is readonly. It is common to toggle the status of a wireless card in the manufacture'' supplied app that usually sits in the system tray. So, there must be a way to programmatically do it. |
My System Specs![]() |
| | #4 (permalink) |
| Vista32 and Vista64 Ultimate | Re: Enable/Disable Network Connection You Can use powershell to enable/disable a network connection. I have done it on Vista32 I would imagine you can do the same on Vista64, when I get time I'll try it. First get your adaptor information. PS C:\Users\James> get-wmiobject win32_networkadapter | format-table ServiceName MACAddress AdapterType DeviceID Name NetworkAdd Speed Verify you have selected the correct devide ID Get-WmiObject win32_networkadapter | where {$_.DeviceId -eq 4} ServiceName : RTL8023xp MACAddress : xx:xx:xx:xx:xx:xx AdapterType : Ethernet 802.3 DeviceID : 4 Name : Realtek RTL8139/810x Family Fast Ethernet NIC NetworkAddresses : Speed : 100000000 next set a PS variable in my case I called it $realtek PS C:\Users\James> $realtek = Get-WmiObject win32_networkadapter | where {$_.DeviceId -eq 4} remember that variables are only active for your current PS session so you cannot close PS and expect these commands to work. since I used $realtek as my variable I can run use these commands to turn on and off My network adaptor $realtek.disable() $realtek.enable() If you want to create a script you have to allow for the execution of them. PS C:\Users\James> Get-ExecutionPolicy if they are not allowed you'll have to run this command PS C:\Users\James> Set-ExecutionPolicy RemoteSigned this will allow local scripts to run but should ask permission before running downloaded scripts. you can set it for unrestricted But I would not recommend it, IF your running firefox, Check before you change this setting, I am not absolutely sure but I think FireFox is different and it does not set the alternate data stream to indicate a script was downloaded from the internet. this may allow them to run. Now you would need to create a powershell profile Microsoft say's it best here Windows PowerShell Profiles Now once you have your profile created open it with notepad PS C:\Users\James> notepad $profile add your variable to your profile $realtek = Get-WmiObject win32_networkadapter | where {$_.DeviceId -eq 4} this will make the variable available everytime you launch PS I went the extra mile and created Quick launch shortcuts so all I have to do is click on enable or disable to turn my network connection on and off. create a shortcut and call it "disable net" in the target option place this line C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe $realtek.disable() change the variable to the one you created create another and call it "Enable Net" the target would be C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe $realtek.enable() A few things you should be aware of. becareful running scripts without specifying the exact directory, if you have more then one named the same it will run the first one it encounters in your windows path parameter. if your running a script manually specify the path EVEN if you are in the same directory by using .\script.ps1 otherwise you will get an error, using the pathname tells PS its a script and not a CmdLet. Now I also know this thread is old but I figured there are probably people still finding it looking for ways to do this so I answered. Hope this helps if I wasn't clear enough yell at me I'm not a professional writer. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Creating a desktop icons to enable/disable ethernet connection | Vista General | |||
| Is there any way to maintain a network connection but disable the | Vista networking & sharing | |||
| Enable or Disable Optimal Performance in Local Area Connection Pro | Vista networking & sharing | |||
| Easy way tio disable/enable internet connection in Vista? | Vista General | |||
| Enable/Disable Network Interfaces | Vista networking & sharing | |||