?
Solved

Vbscript change proxy setting at logon

Posted on 2005-04-07
7
Medium Priority
?
4,032 Views
Last Modified: 2011-04-13
I have a Vbscript that runs different a command depending on your IP Address I need this because I move between a number of different networks, some have a proxy and some don not.

It does things like add printers, maps drives etc. but one thing I can not get to work is enable or disable the proxy.

It works fine if you run the script manually but not at logon. I have striped the code down to just the proxy bit for troubleshooting.

My proxy.vbs file is in c:\proxy.vbs and configured via local computer Group Policy to run at logon. I have local and domain admin rights.

User Configuration\Windows Settings\Scripts (Logon/Logoff)\Logon

'Here is the Proxy code
Set ShellObj = WScript.CreateObject("WScript.Shell")
'Set Proxy
ShellObj.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", "192.168.0.156:8080", "REG_SZ"
ShellObj.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
ShellObj.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride", "192.168.*;<local>", "REG_SZ"
0
Comment
Question by:bwilks99
  • 4
  • 3
7 Comments
 

Expert Comment

by:cloabell
ID: 13735490
Why don't you use the following executable?

http://www.resnet.bristol.ac.uk/config/web.html

0
 
LVL 4

Author Comment

by:bwilks99
ID: 13740638
The setproxy.exe sets it to the uni and reboots the computer!

I need to do it in a vbscript so it can run with the rest of the code. There carn't be too much wrong as it runs perfectly running it manually just not at logon.
0
 

Expert Comment

by:cloabell
ID: 13742651

Might it be that during the logon process, the reference to HKEY_CURRENT_USER is still invalid because, strictly speaking, the user logon procedure has not completed and there is no "current user" logged on?

It sounds strange however. Let me check this out.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Accepted Solution

by:
cloabell earned 750 total points
ID: 13742668
It looks like we've hit the right spot -- there is no HKEY_CURRENT_USER during the logon process.

References:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB10&Number=81597
http://luna.scriptlogic.com/support/kb/displayarticle.asp?UID=66&Str=
0
 
LVL 4

Author Comment

by:bwilks99
ID: 13743551
We are in the right area have a read of this;

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/orderuser.mspx

It says that the local policy login script is run after the user is validated, maybe the profile and HKCU keys are not finished loading when the script runs?

I have added some code to the top of the logon script to wait a while be for running (I am currently testing it)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'"Wait until the user is logged on before we start
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim WSHNetwork, strUserName

Set WSHNetwork = WScript.CreateObject("WScript.Network")
'
' Wait until the user is really logged in...
'
strUserName = ""
While strUserName = ""
WScript.Sleep 10000 ' 100 = 1/10 th of a second
strUserName = WSHNetwork.UserName
Wend
strUserDomain = WSHNetwork.UserDomain

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
0
 

Expert Comment

by:cloabell
ID: 13743696
In case that doesn't work, I suggest that you spawn a different script:

Set SH = CreateObject("WScript.Shell")
Ret = SH.Run("delayedscript.vbs", , False)



and in delayedscript.vbs, I would impose a short delay:

 WScript.sleep 10000



0
 
LVL 4

Author Comment

by:bwilks99
ID: 13780350
Thanks cloabell the delay I put in worked! So I guess the HKCU was not filly loaded.

BW
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Starting up a Project
Loops Section Overview

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question