+ Post New Thread
Results 1 to 5 of 5
Coding Thread, Creating a PAC file in Coding and Web Development; I am trying to create a pack file for teacher's laptops which will set the proxy settings when in school ...
  1. #1
    u8dmtm's Avatar
    Join Date
    Feb 2006
    Posts
    231
    Thank Post
    7
    Thanked 13 Times in 12 Posts
    Rep Power
    20

    Creating a PAC file

    I am trying to create a pack file for teacher's laptops which will set the proxy settings when in school but use direct when at home. Can anyone provide a working example as all the ones I have done so far don't seem to work.

    Thanks.

  2. #2
    Guest

    Re: Creating a PAC file

    Have no idea what a PAC file is, but I use a vb script to achieve the same thing.

    Code:
    Const HKEY_CURRENT_USER = &H80000001
    
    intmsg = msgbox("CHANGE PROXY SETTINGS" & chr(13) & "ARE YOU AT HOME?",vbYesNo+vbQuestion,"WHERE ARE YOU?")
    
    if intmsg = vbyes then dwvalue = 0 else dwvalue = 1
    
    strComputer = "."
    Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
     
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"
    
    strValueName = "ProxyEnable"
    objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
    
    msgtxt = "THE PROXY SERVER HAS BEEN "
    if dwvalue = 0 then msgtxt = msgtxt & "DISABLED"
    if dwvalue = 1 then msgtxt = msgtxt & "ENABLED"
    
    intmsg = msgbox(msgtxt,vbOKOnly+vbInfo,"Done")
    Enables / disables the use proxy setting tick box. Nice and simple.

  3. #3

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,819
    Thank Post
    110
    Thanked 588 Times in 509 Posts
    Blog Entries
    1
    Rep Power
    226

    Re: Creating a PAC file

    Quote Originally Posted by u8dmtm
    I am trying to create a pack file for teacher's laptops which will set the proxy settings when in school but use direct when at home. Can anyone provide a working example as all the ones I have done so far don't seem to work.

    Thanks.

    Code:
    function FindProxyForURL(url,host)
    {
        if (localHostOrDomainIs(host, "carrhill.lancs.ac.uk"))
            return "DIRECT";
    
        if (localHostOrDomainIs(host, "lancsngfl.ac.uk"))
            return "DIRECT";
    
        if (isInNet(host, 10.73.24.0, 255.255.252.0))
          return "DIRECT";
    
        if (url.substring(0, 6) == "https:")
            return "PROXY proxy.lancsngfl.ac.uk:8080; DIRECT";
    
        if (url.substring(0, 5) == "http:" ||
            url.substring(0, 4) == "ftp:")
            return "PROXY proxy.carrhill.lancs.sch.uk:8080; DIRECT";
    
        return "PROXY proxy.carrhill.lancs.sch.uk:8080";
    
    }

  4. #4

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,413
    Thank Post
    642
    Thanked 964 Times in 664 Posts
    Blog Entries
    2
    Rep Power
    327

    Re: Creating a PAC file

    Here's a similar one I made to respond to command-line arguments, ideal for making shortcuts to specify which proxy to use and/or enable/disable it.

    proxy.vbs Off No - Disables access via proxy with no confirmation it has been done.

    proxy.vbs Off Yes - Disables access via proxy but display confirmation it has been done.

    proxy.vbs On Yes - Enable proxy access - set to the server specified in the .VBS file itself and show confirmation.

    proxy.vbs On 172.16.8.254:8080 No - Enable proxy access - set to the server '172.16.8.254:8080' but don't show confirmation.

    proxy.vbs

    Code:
    Set WSHSHell = WScript.CreateObject("WScript.Shell")
    Dim Key,proxyInt,proxyExt,ProxyServer,Args,Num,UseProxy
    
    Key = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
    
    ' Available proxies
    '
    proxyInt = "10.0.0.1:8080"
    proxyExt = "ext.proxy.ip.address:8080"
    
    
    ' Default proxy to set in the Registry if none is passed via arguments
    '
    ProxyServer = proxyInt
    
    
    Set Args = WScript.Arguments
    Num = Args.Count
    
    
    If Num = 0 Then
       MsgBox "Usage: [CScript | WScript] proxy.vbs <On|Off> <server:port> <Yes|No>" & vbCrLf & vbCrLf & "On|Off" & vbTab & vbTab & "-- Toggle access via proxy." & vbCrLf & "server:port" & vbTab & "-- Proxy server & port combo" & vbCrLf & "Yes|No" & vbTab & vbTab & "-- Confirmation of on or off message" & vbCrlf & vbCrLf & "i.e. 'proxy.vbs On 10.0.0.1:8080 Yes' to use proxy and display confirmation ", vbInformation, "Proxy"
       WScript.Quit 1
    End If
    
    
    For i = 0 to Num-1
      Cmd = Args.Item(i)
      Select Case Cmd
        Case "On":
          UseProxy = TRUE
        Case "Off":
          UseProxy = FALSE
        Case "Yes":
          Confirm = TRUE
        Case "No":
          Confirm = FALSE
        Case Else:
          ProxyServer = Cmd
      End Select 
    Next
    
    
    If UseProxy = TRUE Then
      WshShell.RegWrite key & "ProxyEnable", 1, "REG_DWORD"
      WshShell.RegWrite key & "ProxyServer", ProxyServer, "REG_SZ"
      ConfirmText = "Internet access via proxy is enabled through:" & vbCrLf & vbCrLf & ProxyServer
      ConfirmIcon = vbInformation
      ConfirmCapt = "Proxy ON"
    ElseIf UseProxy = FALSE Then
      WshShell.RegWrite key & "ProxyEnable", 0, "REG_DWORD"
      ConfirmText = "Internet access via proxy is turned *OFF*"
      ConfirmIcon = vbCritical
      ConfirmCapt = "Proxy OFF"
    End If
    
    
    If Confirm = TRUE Then
      MsgBox ConfirmText, ConfirmIcon, ConfirmCapt
    End If

  5. #5


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    339

    Re: Creating a PAC file

    proxyconfig.pac
    browser independant OS independant, Here's ours:

    Code:
    function FindProxyForURL(url, host)
    {
    // variable strings to return
    var proxy_yes = "PROXY 172.16.0.3:8080";
    var proxy_no = "DIRECT";
    if (shExpMatch(url, "http://intranet/*")) { return proxy_no; }
    if (shExpMatch(url, "http:/intranet:8080/*")) { return proxy_no; }
    // Proxy anything else
    return proxy_yes;
    }

SHARE:
+ Post New Thread

Similar Threads

  1. Creating SSL certificates.
    By Dos_Box in forum Windows
    Replies: 28
    Last Post: 11th November 2007, 09:22 PM
  2. Creating Ghost CD
    By armadillo in forum How do you do....it?
    Replies: 4
    Last Post: 21st September 2007, 02:44 PM
  3. Creating DST* files...
    By wesleyw in forum How do you do....it?
    Replies: 1
    Last Post: 18th June 2007, 11:04 AM
  4. Replies: 4
    Last Post: 23rd March 2006, 06:27 AM
  5. Creating MSI's
    By adamyoung in forum Wireless Networks
    Replies: 9
    Last Post: 29th November 2005, 12:59 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •