How do I check programatically if 'File and Printer sharing' is enabled for a specific network adapter ?
Asked
Active
Viewed 926 times
0

HIyer
- 283
- 1
- 4
- 10
-
1It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the [FAQ] and [ask]. – Clijsters Feb 14 '18 at 13:11
-
1Get-NetAdapterBinding – Alex K. Feb 14 '18 at 13:14
-
Sure, will keep that in mind. I found a lot of material that only talks about enabling / disabling, File and Printer sharing but none on getting the status. Hence, the query. Coming to writing code, yes, I did check using some COM API's but to no avail e.g. this https://stackoverflow.com/questions/19236639/get-the-properties-of-the-current-network-connection – HIyer Feb 15 '18 at 03:35
2 Answers
3
I guess this is what you are looking for -
Get-NetAdapterBinding | ? {$_.DisplayName -eq 'File and Printer Sharing for Microsoft Networks' -and $_.Name -eq 'ethernet'}
Name DisplayName ComponentID Enabled
---- ----------- ----------- -------
Ethernet File and Printer Sharing for Microsoft Networks ms_server True

Vivek Kumar Singh
- 3,223
- 1
- 14
- 27
0
If you use Windows 10 you can use Get-NetAdapter
to list your adapters. Once you've got the right one "toto" you can use :
Get-NetAdapter "toto" | Set-NetAdapterBinding –ComponentID ms_server –Enabled $False

JPBlanc
- 70,406
- 17
- 130
- 175