topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 2:56 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Script to edit registry setting all network profiles to private  (Read 11317 times)

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
I know in a general way what I need to do but not exactly how to get there and do it

Code: Text [Select]
  1. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles
  2. if possible locate the wireless profile currently in use
  3. if not check each profile for a key called category
  4. if there is one set the value 1 for Private
  5. if one does not exist create it and set it to 1
  6. If it was possible to find and set only the active WiFi profile then exit now
  7. if that was not possible continue to the next profile until all are set to Private

Unless their is a reason that this could be problematic, it will definitely fix something instantly untili canget to the User to do a better job.

This is a situation that has begun to appear often in Windows 10, usually on older systems that were upgraded but sometimes on new Windows 10 laptops.  When it happens, I need to be able to tell the user to click a .bat or .reg file that would set everything to PRIVATE until I can get to their station to do it right and find out what caused the problem in the first place.  When they are shown using a PUBLIC connection they are blocked from most office networked items like Printers etc.

I won't know the exact profile name to use for their system and if a way can be added to make this change occur only on the WiFi profile currently in use, that would be best.
The wired profiles automatically say Private but on these same systems, connecting their Wired connection does not release the WiFi as it should.  Worse, many new laptops no longer provide for a wired network at all.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #1 on: April 29, 2016, 03:34 PM »
Restarting the Network Location Awareness service (and/or setting its startup type to delayed start) can help with that sort of thing.

...As would that 'D' word thing you're tired of us mentioning. ;)

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #2 on: April 29, 2016, 03:40 PM »
Like "duh"? :)

This is for those times when I get tired of people who cant at least wait 5 minutes for me to get from the 2nd floor to the 5th floor to see what the heck they did to cause it. They just want to Print and don't care that I am not psychic, cannot levitate nor teleport.   They are also the ones who complained the most when I suggested we shift to a Domain network because they are 'afraid' that IT will be 'spying' on them.  :'(

When they have a problem it is "spying' they want though.

x16wda

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 888
  • what am I doing in this handbasket?
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #3 on: April 29, 2016, 07:37 PM »
...As would that 'D' word thing you're tired of us mentioning.
Delete user account?  :huh:
vi vi vi - editor of the beast

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #4 on: April 29, 2016, 10:15 PM »
For the current active connection, in an elevated PowerShell console:

Code: PowerShell [Select]
  1. $net = get-netconnectionprofile;Set-NetConnectionProfile -Name $net.Name -NetworkCategory Private

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #5 on: April 29, 2016, 10:52 PM »
...As would that 'D' word thing you're tired of us mentioning.
Delete user account?  :huh:
Yeah  well.  I figured is was a side-swipe at the copany using a Non-Domain network but.. I kinda like "Delete the User myslef! ;).
OR maybe it is a "hint" 
or  <Donations , Dummy!>    Oops  Double 'D'

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #6 on: April 29, 2016, 11:03 PM »
For the current active connection, in an elevated PowerShell console:

Code: PowerShell [Select]
  1. $net = get-netconnectionprofile;Set-NetConnectionProfile -Name $net.Name -NetworkCategory Private

THanks again 4wd  HOW do You DO it>?  I looked evrywhere.  Posted allover Microsoft as well as every possible forum i could find.  The WORST was Spiceworks where I got nothing but a Hundred and One reasons why it was "Impossible" to do.  Or suggestons on why I needed to do it a way they KNEW how to do (none of which would work in my case anyway and I got tired of explaining that).  I figured I would have to wait for the 12 hour time difference for you to come up with the answer :)
Not Yet TESTED but I am sure it works!  Dont suppose you have the addon to make it run elevatd in the same script.  I need to put this on every system with all the other "For Emergency Click HERE" scripts.  They won't know how to open an elevated PS prompt.

<Side note:  I STILL would love a way to step through a section of registry making multiple changes where needed based on the main key and not the specific reference in it.  All of those profiles could be changed to private whether active or not and in this cae it would not have hurt anything.  If i could have determned the single active one, I would have deleted the rest on a company system and never thought twice about it.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #7 on: April 29, 2016, 11:45 PM »
I looked evrywhere.

Except your emails for 15 December 2015 ;)

Already answered for you way back then :P

Bit shorter:

Code: PowerShell [Select]
  1. Set-NetConnectionProfile -Name (get-netconnectionprofile).Name -NetworkCategory Private

Create a shortcut, set the Target to:

Code: Text [Select]
  1. %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy bypass -Command "Set-NetConnectionProfile -Name (Get-NetConnectionProfile).Name -NetworkCategory Private | Out-Null"

Open Properties on it, set Run as administrator under Shortcut->Advanced

Shortcut attached but Windows will probably complain about it being untrusted, still you can create your own using the info in it.
« Last Edit: November 09, 2016, 07:26 PM by 4wd »

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #8 on: April 30, 2016, 02:30 AM »
4 WD, I sent you a few emails with attached zips withthe setup as needed to run elevated PS1 from normal batch  file. 

That was about my only contribution.  Your Original script worked and was plain to see this once i slowed it down a little  :(  I am not so "fleet of mind"
This is exactly the thing that the people on that "other forum" spent so much time telling me could not be done at all.
Thanks for the help.  If you look at what i sent, i only need the added means to input a choice of types to be used for the command and Powershell is not something i know much at all.

With that added, i ahve the perfect "portable" utility that could be used on any system for the same reasons. :Thmbsup: :Thmbsup: :Thmbsup: :Thmbsup: :Thmbsup:

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #9 on: April 30, 2016, 02:43 AM »
4WD: ;D

That is what they call "Old Timers Disease" :)  Us Old Timers get to "FORget" , it is one of the benefits of age.

It also allows us to make new friends from old friends every day and even old enemies are forgotten and get a new chance.

Some become new enemies. (but only unil they are forgotten again) 
Some, though, become New friends.

Life gets to be fun again as you get to learn everything "for the first time" every every new is the First Day of the Rest of the Rest of your Life.

I have always felt that this was a good outlook to have on aging as there isn't much you can do about it and it beats the only alternative~!

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #10 on: April 30, 2016, 07:46 AM »
This is for those times when I get tired of people who cant at least wait 5 minutes for me to get from the 2nd floor to the 5th floor to see what the heck they did to cause it.


Understood, but I was getting the feeling from your description that there was a bit of a repeat offender aspect to this. In which case it's not always valid to blame the user - fun yes - but there is a good bit of - I suspect - misdirected culpability going on there. Because the NLA Service is actually notorious for doing exactly that if it happens to 'wake-up-cranky'

if it's set to delayed start, it won't be tying to play guess the network (usually wrong) when it fires off a tad early and the network connection isn't quite ready for its "interview".

So my suggestion was more (repeat offender) prevention, than first failure remediation.


They just want to Print and don't care that I am not psychic, cannot levitate nor teleport.

Ah! End Users... They're so cute when they're angry ... Not!


They are also the ones who complained the most when I suggested we shift to a Domain network because they are 'afraid' that IT will be 'spying' on them.  :'(

Actually, from what I've seen even on a domain - when the Network Location Awareness service shits the bed - you're still screwed. But the domain does make it easier to push out service startup and firewall settings and other configurations to prevent that sort of thing ... in addition to it's other more typical benefits.


Note: I've actually seen a Domain Controller seal itself up like a clam because of the NLA service jumping to early. Console logon showed unidentified network, and a NLA service restart made it go "Oh! Lookie! There I am!!".

Delayed start is now part of my base configuration.

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Re: Script to edit registry setting all network profiles to private
« Reply #11 on: April 30, 2016, 06:52 PM »
ok count this one DONE!  Put a Fork in it.  (hmm I never considered the possibilites of that phrase when used in writing computer code) :huh:

Thanks to 4wd I have a nifty one liner ps1 scipt and another friend provided the equivalent VBS option so that makes two solutions for one problem.
 Not so bad  :-\

Thanks for the input from all.