Announcement

Collapse
No announcement yet.

Turn off proxy via shutdown script?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Turn off proxy via shutdown script?

    I've been banging my head against this for a while. We have implemented a proxy server solution, but when laptop users take their machines home, they have to remember to go in and uncheck the "Use proxy" box in IE -> Tools -> Internet options -> Connections -> Lan settings. We turn the box on (as well as import exclusions) during the logon script.

    I would like to do this as a shutdown script, but so far I have not had any luck. The shutdown script is part of its own GPO. I specified the script as \\domain\netlogon\ProxyOff.bat.

    The batch file is really simple.
    ProxyOff.bat:
    REGEDIT.EXE /s \\domain\netlogon\ProxyOff.REG

    ProxyOff.reg:
    REGEDIT4
    [HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Internet Settings]
    "ProxyEnable"=dword:00000000

    If I run the batch file from that location while logged in, it works. I have also tried copying these two files to C:\Windows and running them from there, but that didn't help either. I'm not getting any errors in the event log, but the check box isn't clearing.

    One thing I did notice was when I made the shutdown script run visible, I got this message:
    '\\domain\SysVol\domain\Policies\{Policy GUID}\Machine\Scripts\Shutdown'
    CMD.EXE was started with the above path as the current directory.
    UNC paths are not supported. Defaulting to the Windows directory.

    Oddly enough, if I run the script as a logoff script, it seems to work; however, even as a logoff script, if I shut down, it doesn't run. I even tried removing the /s from the regedit command, to make it prompt me. It did prompt me, I clicked Yes, then it said the file was successfully imported, but at next logon (with the logon script turned off, so the box wouldn't get checked again), the box was still checked.

    Can anyone see what I might be doing wrong? Is there a better way to accomplish this?


    Thanks,

    -Mike
    Last edited by chupr0kabra; 4th January 2007, 19:36.

  • #2
    Re: Turn off proxy via shutdown script?

    Why not handle it in your logon script? if your LOGONSERVER is the local machine then the PC must be at home?

    Odd that the logoff script doesn't run for a shutdown initiated in a logged on user session.
    Cheers,

    Rick

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    © 2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

    Comment


    • #3
      Re: Turn off proxy via shutdown script?

      Originally posted by rvalstar View Post
      Why not handle it in your logon script? if your LOGONSERVER is the local machine then the PC must be at home?
      I'm not sure I follow. Currently, the process is/should be:

      Login
      Logon script imports reg file that turns on proxy
      User works all day
      User shuts down
      Shutdown script turns off proxy (theoretically)

      We definitely want the proxy enabled while they're in the office. The logon script is not part of a GPO (if that matters). Rather, it is specified in the user properties in AD.

      Odd that the logoff script doesn't run for a shutdown initiated in a logged on user session.
      I thought that odd too. Seems to me that a logoff is a necessary part of a shutdown. In the case of a logoff script, I was able to logoff, disconnect the NIC (doing this in a VM), login with cached credentials, and the box was unchecked. However, if I shutdown, disconnected the NIC, booted up, then logged on with cached credentials, the box never got unchecked. Weird.


      -Mike

      Comment


      • #4
        Re: Turn off proxy via shutdown script?

        So I'm suggesting:

        Login
        Logon script:

        Tests if on the Domain or at Home.
        If on the domain, Logon script imports reg file that turns on proxy
        If at home, Logon script imports reg file that turns off proxy

        User works all day
        ...
        Cheers,

        Rick

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        © 2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

        Comment


        • #5
          Re: Turn off proxy via shutdown script?

          Originally posted by rvalstar View Post
          So I'm suggesting:

          Login
          Logon script:

          Tests if on the Domain or at Home.
          If on the domain, Logon script imports reg file that turns on proxy
          If at home, Logon script imports reg file that turns off proxy

          User works all day
          ...
          Right, but if they're at home, the logon script wouldn't run, since they're not authenticating against a DC, correct?


          -Mike

          Comment


          • #6
            Re: Turn off proxy via shutdown script?

            My wife's laptop runs her company's logon script whether at home or work. I can tell because it keeps complaining in the event log that it can't contact the mother ship (a VBS programming feature).

            Don't know if this required something special GPO or otherwise or if it happens out of the box.
            Cheers,

            Rick

            ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

            © 2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

            Comment


            • #7
              Re: Turn off proxy via shutdown script?

              IIRC GPO's are applied once and stay regardless of whether you are in the domain. If you step out the GPO will not update but will still be in force. (using cached cred's) As such I think the proper logic for a script would be to

              A) clear any proxy setting.
              B) check to see if computer is oin domain
              C) if yes then flip on proxy
              D) else stay off

              that way the default is off but when you are inside, it uses the proxy.
              I am not a script guy, but there are some people here that are.
              "...if I turn out to be particularly clear, you've probably misunderstood what I've said” - Alan Greenspan

              Comment


              • #8
                Re: Turn off proxy via shutdown script?

                There you have it. Lior_S confirms your logon script should run even when away from the domain. It looks like you have enough scripting savy to make the fix. As I said earlier, your %LOGONSERVER% should equal your %COMPUTERNAME% (plus "\\") when at home so it shouldn't be too difficult to test whether or not you are home or at work.
                Cheers,

                Rick

                ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                © 2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

                Comment


                • #9
                  Re: Turn off proxy via shutdown script?

                  something like this user logonscript?:

                  FindProxySrv.vbs
                  Code:
                  strPrnSRV = "proxyservername"
                  sRegPath = "HKCU\Software\Microsoft\Windows\CurrentVersion\" _
                             & "Internet Settings\ProxyEnable"
                  
                  Set objShell = CreateObject("WScript.Shell")
                  
                  iErrorCode = objShell.Run("ping -n 2 -w 1000 " & strPrnSRV,0 ,True)
                  
                  If iErrorCode = 0 Then
                    objShell.RegWrite sRegPath, "1", "REG_DWORD"
                   End If
                  If iErrorCode <> 0 Then
                    objShell.RegWrite sRegPath, "0", "REG_DWORD"
                   end if
                  
                  Set objShell = Nothing
                  Wscript.quit(0)
                  Change "proxyservername" in the name of the server in the office.

                  Store the script localy, and run it through an local autorun-path
                  (%AllUsersProfile%\Menu Start\Programs\startup\*.*)

                  I dont know if just disabling proxyserver in IE is enough, but you can give it a try.

                  \RemS
                  Last edited by Rems; 9th January 2007, 13:15.

                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  __________________

                  ** Remember to give credit where credit's due **
                  and leave Reputation Points for meaningful posts

                  Comment


                  • #10
                    Re: Turn off proxy via shutdown script?

                    This is a shutdown script you can try if you need it m8, works great for me using a GPOs : (disableproxy.vbs)

                    Code:
                    strComputer = "."
                    Const HKEY_CURRENT_USER = &H80000001
                    
                        
                        Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
                         strComputer & "\root\default:StdRegProv")
                     
                        strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
                        strEntryName = "ProxyEnable"
                        dwValue = 0
                        objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strEntryName, dwValue
                    
                        Err.Clear
                    If you need a startup script to enable it again, use the same code but change the dwValue to 1
                    Last edited by Mouse; 10th January 2007, 11:38. Reason: My naff spelling

                    Comment

                    Working...
                    X