You are not logged in.

#1 04 Nov 2013 11:13

EagleEye
Member
Registered: 04 Nov 2013
Posts: 8

Problems running command line through batch files

Hi i'm new here, Please tell me if i'm off topic in here.

I have created two batch files, one called them SetProxyServer.bat and ResetProxyServer.bat.

They look like this:

(SetProxyServer.bat)
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f    //Comment - Enable proxy
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d 74.91.18.100:3128 /f    //comment - set proxy settings

TIMEOUT /T 5

ipconfig /flushdns

start "Chrome" chrome --new-windows whatismyipaddress.com

(ResetProxyServer.bat)
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d : /f      // this is to remove the ip and port settings in LAN settings otherwise the old address and port stays in there
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f

TIMEOUT /T 5

ipconfig /flushdns


Both files is writing the settings to the registry and when i check the settings in Internet Options => Connections => LAN Settings everything i set correctly.

The problem is:
I cannot access any sites when i use a proxy, i havetried with several ip/ports
When i reset the proxy through the ResetProxySettings.bat it ONLY works when i manually have been into Internet Options and see if everything is set to the right thing. No matter if i cancel on my way out or if i click ok two times to get out of the settings, then it works and i can go to any website again. It's like i have to manually go to Internet Options for the settings in the registry to be accepted.

I don't have this problem at all if i do this the manual way, it works every time. It only when i run it automatic through the bat files.

Does anyone have any idea of what i'm missing? Is it because i need to run another command for it to works?

Offline

#2 04 Nov 2013 12:39

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Problems running command line through batch files

Does it work if you restart your browser after running the batch files?

Offline

#3 04 Nov 2013 12:45

EagleEye
Member
Registered: 04 Nov 2013
Posts: 8

Re: Problems running command line through batch files

foxidrive wrote:

Does it work if you restart your browser after running the batch files?

No i doesn't

After i found out that i had the problem i have closed all my browsers every time i run the script/bat file, whether it's the set or reset.

Offline

#4 04 Nov 2013 13:13

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Problems running command line through batch files

Does it work when you log out and log back in?  That will test your batch file's operation.

Windows doesn't re-read the registry for various processes until some event occurs - logging off and back on is one of those events, but it's too extreme to be useful, except as a test.

Usually restarting a browser makes things like that get refreshed - you could kill explorer and restart it, but that too is extreme. smile

Try starting windows explorer and close it, see if that works too.  I'm drawing straws here.

Offline

#5 04 Nov 2013 13:41

EagleEye
Member
Registered: 04 Nov 2013
Posts: 8

Re: Problems running command line through batch files

foxidrive wrote:

Does it work when you log out and log back in?  That will test your batch file's operation.

Windows doesn't re-read the registry for various processes until some event occurs - logging off and back on is one of those events, but it's too extreme to be useful, except as a test.

Usually restarting a browser makes things like that get refreshed - you could kill explorer and restart it, but that too is extreme. smile

Try starting windows explorer and close it, see if that works too.  I'm drawing straws here.

I'm sure it will work that way and i will give it a try for sure, but as you say it's too extreme.

Is there a another way of making this 'event' to happen beside restarting the computer?

Offline

#6 04 Nov 2013 16:52

AiroNG
Member
From: Germany
Registered: 26 Nov 2012
Posts: 42

Re: Problems running command line through batch files

 42. Activate registry changes in HKEY_CURRENT_USER without logging off (Windows 2000 and later):

RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

as seen on http://www.robvanderwoude.com/rundll.ph … RegChanges

so insert that command after your "reg add" lines and it _should_ work fine

Hope it helps

Last edited by AiroNG (04 Nov 2013 16:56)


I don't suffer from insanity, I enjoy every minute of it.

Offline

#7 04 Nov 2013 21:11

EagleEye
Member
Registered: 04 Nov 2013
Posts: 8

Re: Problems running command line through batch files

AiroNG wrote:
 42. Activate registry changes in HKEY_CURRENT_USER without logging off (Windows 2000 and later):

RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

as seen on robvanderwoude.com/rundll.php#ActivateRegChanges

so insert that command after your "reg add" lines and it _should_ work fine

Hope it helps

Noap it didn't help

I have this in my reset bat file:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d : /f      // this is to remove the ip and port settings in LAN settings otherwise the old address and port stays in there
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f

RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

ipconfig /flushdns

When i'm trying to reset the proxysetting through the bat file i cannot access the Internet before i manually go into the proxy settings and just press cancel and cancel and that is enough to force the 'reset' of the proxy setting so i can access the internet again. This is very strange, because i can see that the script has removed the proxy settings, but still i cannot access the internet before i have been into the LAN/proxysettings manually.

Offline

#8 05 Nov 2013 00:01

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Problems running command line through batch files

Does just logging off, and back on, make it work?

You need to confirm that it is not another function of entering the lan/proxy settings that affects it.

Offline

#9 05 Nov 2013 00:26

EagleEye
Member
Registered: 04 Nov 2013
Posts: 8

Re: Problems running command line through batch files

Sorry foxidrive, no logging off didn't help.

Just read that 'RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True' doesn't work in Win 7

Last edited by EagleEye (05 Nov 2013 00:27)

Offline

#10 05 Nov 2013 01:24

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Problems running command line through batch files

If logging off didn't work then there's got to be something wrong with your routine in setting the registry items.
Like, another change is needed that you are missing.

Logging on should re-read all operational settings, you'd think.  You can try actually rebooting the box to see if that does work, with your current batch file.

Last edited by foxidrive (05 Nov 2013 01:25)

Offline

#11 05 Nov 2013 04:15

AiroNG
Member
From: Germany
Registered: 26 Nov 2012
Posts: 42

Re: Problems running command line through batch files

Does it work with another Browser or is only with chrome _not_ working?

If only chrome won't work maybe this will help:

On win32 Chrome/Chromium will use the IE proxy settings (i.e. system settings) 
unless you specify a proxy on the command line, for example:
chrome.exe" --proxy-server="socks5://localhost:9090" or -proxy-server=127.0.0.1:8080

found that here: http://stackoverflow.com/questions/4541 … h-bat-file

Last edited by AiroNG (05 Nov 2013 04:15)


I don't suffer from insanity, I enjoy every minute of it.

Offline

#12 05 Nov 2013 06:49

EagleEye
Member
Registered: 04 Nov 2013
Posts: 8

Re: Problems running command line through batch files

AiroNG wrote:

Does it work with another Browser or is only with chrome _not_ working?

If only chrome won't work maybe this will help:

On win32 Chrome/Chromium will use the IE proxy settings (i.e. system settings) 
unless you specify a proxy on the command line, for example:
chrome.exe" --proxy-server="socks5://localhost:9090" or -proxy-server=127.0.0.1:8080

found that here: http://stackoverflow.com/questions/4541 … h-bat-file

No, i have tried Firefox and it does't work

I wonder if it should be like this:
chrome.exe" --proxy-server="127.0.0.1:8080" or
"chrome.exe" --proxy-server="127.0.0.1:8080" or
chrome.exe --proxy-server="127.0.0.1:8080" or

chrome.exe" -proxy-server="127.0.0.1:8080" or
"chrome.exe" -proxy-server="127.0.0.1:8080" or
chrome.exe -proxy-server="127.0.0.1:8080"

None of them is setting the proxysettings though or starting up Chrome

- update -
Start chrome -proxy-server="74.91.18.100:3128" - seems to start up chrome, but it cannot open e.g. Google.com

Then i tried :
Start chrome -proxy-server="68.195.137.213:38899" - same problem

As i see it all that needs to be done is update the registry after setting the proxy settings, but i have googled for hours without any solution. This 'RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True' should do the trick, but as i said before, it doesn't work in Win 7.

Last edited by EagleEye (05 Nov 2013 07:06)

Offline

#13 05 Nov 2013 10:09

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Problems running command line through batch files

EagleEye wrote:

As i see it all that needs to be done is update the registry after setting the proxy settings

That's what logging off and rebooting does.  if neither of those work after running your batch file then you are still missing something.

Offline

#14 05 Nov 2013 10:48

EagleEye
Member
Registered: 04 Nov 2013
Posts: 8

Re: Problems running command line through batch files

foxidrive wrote:
EagleEye wrote:

As i see it all that needs to be done is update the registry after setting the proxy settings

That's what logging off and rebooting does.  if neither of those work after running your batch file then you are still missing something.

Logging of didn't help. Reboot then it works, just like when i get into Internet Options either through the control panel or through Chrome

Last edited by EagleEye (05 Nov 2013 11:40)

Offline

#15 05 Nov 2013 12:17

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Problems running command line through batch files

That's just what I wanted to prove - that it works in a given situation.  I think it is odd that a logoff doesn't fix it...

Have you tried ipconfig /release and /renew?  Or maybe an AutoIt solution - to go into internet options and out - will suit you??

Last edited by foxidrive (05 Nov 2013 12:18)

Offline

#16 05 Nov 2013 15:24

AiroNG
Member
From: Germany
Registered: 26 Nov 2012
Posts: 42

Re: Problems running command line through batch files

From what i've read so far, windows 7 loads new values in the registry without the need of a reboot/logoff. It seems that some programms (like chrome) still need a reboot in order to accept new values.

There is one workaround, but as foxidrive said:

foxidrive wrote:

you could kill explorer and restart it, but that too is extreme

To see if that would do the trick simply type the following in the command prompt (after you've run on of your batch-files):

To kill the explorer:

taskkill /F /IM explorer.exe

And to start it again:

explorer

I don't suffer from insanity, I enjoy every minute of it.

Offline

#17 05 Nov 2013 16:15

EagleEye
Member
Registered: 04 Nov 2013
Posts: 8

Re: Problems running command line through batch files

AiroNG - No that didn't do the trick.

foxidrive - Have tried ipconfig/release and renew and it didn't work as well.

foixdrive - i will try to see if the Internet Options through AutoIt will work.

If anyone have the chance to test it out it would be great to see if you have the problem as me.

Offline

Board footer

Powered by