Bat file to enable/disable proxy - windows

Using windows, I'd like to know if there is some way to change proxy configuration by modifying the Windows registry through command line.
As said here, you can always do:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
or
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
This does uncheck the proxy option (see image). However, it does not applies the changes in the system. In other words, you get the option to be checked/unchecked, but it won't be applied unless you don't enter manually in the dialog and press "Accept".
Does anyone know what command makes it work straightforward?

Related

Why are changes to the Winlogon registry being ignored by MDT TaskSequence?

I'm setting up a Task Sequence(TS) in MDT for deploying Win10 IoT Enterprise. As one of the final steps in the TS I'm trying to add AutoLogon of the user account to the registry. But when the TS finishes and I check, the changes have either not been made or they have been reset by some clean-up script.
I create a new "Run Command Line" step in the TS, right after the Install Applications step that MDT generates automatically. This step runs a script I've added to the Deploy/Scripts folder. I get no errors here, but no result either.
I've tried to export the correct registry-settings to a .reg file and use the "Run Command Line" step to import these. Again, no errors and no result.
I've moved both of these steps down in the list, so that they are the last thing the TS does. Again, no errors and no result.
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d <username>/f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d <Domain> /f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d <password> /f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonCount /t REG_DWORD /d 500000 /f
I want the AutoLogon to be set automatically. If not, there has to be a procedure for how to set it up and that not only feels unnecessary, but is also a source of errors if its forgotten.
After more googling I finally found:
https://ccmcache.wordpress.com/2018/02/07/workaround-for-windows-10-1709-autoadminlogon-at-the-end-of-configmgr-osd-task-sequence/
Where there is a solution. An ugly one, but the only way I've found that works. So thank you to the author of this.

edit regedit value using bat file

I am trying to change the value of a reg_dword entry: start in location: Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv
to value 2.
I tried already exacting code from several sites, nothing works and I am launching it as admin:
REG.exe ADD "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv" /t REG_DWORD /v Start /d 2 /f
REG ADD "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv" /t REG_DWORD /v Start /d 2 /f
REG.exe ADD "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv" /v "Start" /t REG_DWORD /d 2 /f
On every site there was information with slight difference, but i don't think order matter, maybe "".
What is the correct syntax for adding a registry value as described above?
Your problem is the Computer.
Indeed, the order of the options does not matter. Also it doesn't matter if you call REG or REG.exe.
Usually, the inbuilt help is also your friend:
reg add /?
Which tells you that Computer is the (network) name of the remote computer and can be omitted to use the current (local) computer as default.
This line works fine (as any other of yours without the Computer\:
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv" /t REG_DWORD /v Start /d 3 /f
Offtopic: Check out the other networks of stackexchange. I'd think this question would be more suitable for https://superuser.com/.

How to change chrome proxy via command line windows?

I have tried to update the settings with:
netsh winhttp set proxy proxy-server="127.0.0.1:8080" bypass-list=""
also tried:
netsh winhttp set proxy proxy-server="http=127.0.0.1:8080" bypass-list=""
But no effect, the traffic just don't go through the proxy.
I have also used this:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d 127.0.0.2:8080 /f
but the problem is I can't override the settings, once I pick one proxy, even though I disable the proxy with:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
the settings stay and I have to go to Internet Explorer > Internet Options > Connection > Lan Settings to change it, and the command doesn't work anymore, just the first time.
I was wrong,
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
does the trick, the thing is, it is necesary to restart the brower to apply the changes.

Edit a GPO with a script

Is it possible to use a batch file to edit a local GPO ?
What I am exactly trying to do:
I want to create a "New Software Restriction Policies".
Change a parameter value in the "Enforcement".
Add a new path rule with a specific path.
I am not looking for you to create the script. I just want to know if this is possible to do it with a batch file & and some idea to help me start with this task.
This procedure is not really complicated and can be done manually. Given that I have to apply these change for a lot of computer, I am looking for a fastest way than doing it from the "gpedit.msc".
Yes, it is possible to edit the local GPO using a Batch script. Simply manipulate the GPO by editing the registry keys. Note: Depending upon the GPO setting changed through the registry, you may need to log the user off before the change takes effect.
Step 1
Download the Microsoft Group Policy Setting Reference (Registry Keys List):
http://www.microsoft.com/en-us/download/details.aspx?id=25250
Step 2
Get the policy registry location from the Spreadsheet
e.g. HKLM\Software\Policies\Microsoft\Windows NT\DNSClient!AppendToMultiLabelName
Step 3
Use the reg add command to edit the values as you need
e.g. #reg add "HKLM\Software\Policies\Microsoft\Windows NT\DNSClient" /v AppendToMultiLabelName /t REG_DWORD /d 1 /f
Note
You may need to edit the GPO registry key in both the Machine and User section of the registry along with the WOW section.
e.g. #reg add "HKLM\Software\Policies\Microsoft\Windows NT\DNSClient" /v AppendToMultiLabelName /t REG_DWORD /d 1 /f & #reg add "HKLM\Software\Wow6432Node\Policies\Microsoft\Windows NT\DNSClient" /v AppendToMultiLabelName /t REG_DWORD /d 1 /f & #for /f "delims=" %A in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects" /k /f "*Machine" ^| find /i "HKEY"') do #reg add "%~A\Software\Policies\Microsoft\Windows NT\DNSClient" /v AppendToMultiLabelName /t REG_DWORD /d 1 /f & #reg add "%~A\Software\Policies\Microsoft\Windows NT\DNSClient" /v AppendToMultiLabelName /t REG_DWORD /d 1 /f
Breakdown of example:
Update the value in the default location
Update the value in the secondary location for 64-bit OS
Loop through the User GPOs
Update the value based on the default location
Update the value based on the secondary location for 64-bit OS
Source

How can I make changes to the Windows Registry persistent?

I want to make changes to the Windows Registry through a Powershell script. I use the old fashioned reg add approach and it works quite well. If I run regedit.exe after my script all changes are made but they are lost after a reboot ...
My code:
# Enable Auto Logon
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v "AutoAdminLogon" /t REG_SZ /d "1" > null
$name = Read-Host 'Username'
# Set username for logon
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v "DefaultUserName" /t REG_SZ /d $name > null
# Set users password
$clearPassword = Read-Host 'Password'
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v "DefaultPassword" /t REG_SZ /d $clearPassword > null
# How many times to auto logon? (0 means infinitive)
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v "AutoLogonCount" /t REG_DWORD /d "0" > null
echo "Autologon enabled"
So, what can I do to make these changes persistent in the Windows Registry?
Best regards
peekaboo777
This behaviour is by design.
On each reboot, Windows will de-crement the AutoLogonCount. When it is at zero, the registry value is removed to disable auto-logon. The values for DefaultUserName and DefaultPassword may also be cleared.
This feature is generally used during automated Windows client builds/deployments.
This is well documented. E.g. http://www.computerperformance.co.uk/windows7/windows7_auto_logon.htm

Resources