MightyR1
(MM club member)
2002-11-14 10:32 AM
Run IE and enable proxy only for this windows

New challenge:

Users with no internet access (proxy disabled) must be allowed to visit one internet-address (for this they need proxy).

So is it possible to:
  • close all existing internet explorers
  • remember current proxy settings (yes, readvalue...)
  • apply correct proxy settings (yes, writevalue...)
  • start new explorer window with specified address (yes, createobject...)
  • prevent users from starting explorer again
  • if KiX explorer windows is closed restore previous proxy settings
  • allow new explorer windows
Running W95, KiX 4.11, WMI installed (not started automatically) <-- need more info???


JochenAdministrator
(KiX Supporter)
2002-11-14 10:36 AM
Re: Run IE and enable proxy only for this windows

Patrick ,

I think you can puzzle this together without using COM at all ... for the start of the Explorer window just use 'run www.dotnot.not', for preventing other instances use Radimus' Application killer script ... searching ...


LonkeroAdministrator
(KiX Master Guru)
2002-11-14 10:37 AM
Re: Run IE and enable proxy only for this windows

doesn't the killer kill this too?

LonkeroAdministrator
(KiX Master Guru)
2002-11-14 10:40 AM
Re: Run IE and enable proxy only for this windows

patrick, what about renaming the iexplore.exe while running script?
should stop usage of it...


JochenAdministrator
(KiX Supporter)
2002-11-14 10:40 AM
Re: Run IE and enable proxy only for this windows

You can always ammend it to leave one instance alive [Razz]

LonkeroAdministrator
(KiX Master Guru)
2002-11-14 10:43 AM
Re: Run IE and enable proxy only for this windows

j, how then you know do you kill your own?
or, if the user closes our window, doesn't it leave one open then too?


JochenAdministrator
(KiX Supporter)
2002-11-14 10:47 AM
Re: Run IE and enable proxy only for this windows

... tricky

JochenAdministrator
(KiX Supporter)
2002-11-14 10:48 AM
Re: Run IE and enable proxy only for this windows

maybe referencing Process ID ?

Shouldn'T be that hard


MightyR1
(MM club member)
2002-11-14 10:53 AM
Re: Run IE and enable proxy only for this windows

If RADIMUS' code ( X ) works on W95, I could:

kill all iexplore.exe
rename it
set proxy
start it
after exit rename it again
and finally restore old proxy settings

Problem is that after renaming the shortcuts and desktop E to IE generate errors...

Hmm, would this work:
copy wkix32.exe to iexplore.exe and place a kixtart.kix script in the same dir displaying a msg???

WIll let you know...


LonkeroAdministrator
(KiX Master Guru)
2002-11-14 11:01 AM
Re: Run IE and enable proxy only for this windows

why not make it an exe?
iexplore.exe selfextracting-selfexecuting-lockeddown-rar-package which has wkix32 and your message file?


MightyR1
(MM club member)
2002-11-14 02:55 PM
Re: Run IE and enable proxy only for this windows

Almost there...

looking for one thing:

Howto suppress a shell window starting an exe from within "Wkix32.exe /i"?


Chris S.
(MM club member)
2002-11-14 02:57 PM
Re: Run IE and enable proxy only for this windows

This will close all open IE Windows...

code:
$objShell=CreateObject("Shell.Application")
$objWindows=$objShell.Windows
For $Index = 0 to $objWindows.Count-1
$objWindows.Item($Index).Quit
Next



Radimus
(KiX Supporter)
2002-11-14 03:01 PM
Re: Run IE and enable proxy only for this windows

have the script: (pseoducode follows)
code:
findproc(@wksta,"iexplore.exe",1)
writevalue() to enable proxy
run ("%comspec% /c start www.msn.com")
$currentIE = findproc(@wksta,"iexplore.exe")

$currentIE will be the PID of the one called by the code

you can then run it in a loop every X seconds returning the PIDS of all iexplore.exe and terminate all PIDS not $currentIE

if there $currentIE isn't running, use writevalue to disable proxy and findproc() to kill all IE windows


LonkeroAdministrator
(KiX Master Guru)
2002-11-14 03:03 PM
Re: Run IE and enable proxy only for this windows

patrick, could you translate this:
quote:
Howto suppress a shell window starting an exe from within "Wkix32.exe /i"?

where that shell window comes from?


JochenAdministrator
(KiX Supporter)
2002-11-14 03:05 PM
Re: Run IE and enable proxy only for this windows

As I said , couldn't be that hard [Razz]

MightyR1
(MM club member)
2002-11-14 03:13 PM
Re: Run IE and enable proxy only for this windows

Here's the code:

code:
$ = SetConsole("MINIMIZE")
$ = SetConsole("HIDE")
Break on

$rc = MessageBox("Sluit alle andere Internet Explorer vensters."+
@crlf+"Na 2 minuten òf na het klikken op OK, worden ze automatisch gesloten!",
"KiXtart message",49,120)

If 2 = $rc
Exit 0
EndIf

Shell "%comspec% /c @scriptdir\kill95 iexplore.exe > nul"

$proxy = ReadValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyEnable")
$ = WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyEnable","1","REG_DWORD")
$ = WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyOverride","10.*.*.*","REG_SZ")
$ = WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyServer",";http=PROXYSERVER","REG_SZ")

$ = WriteValue("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions",
"NoFileOpen","1","REG_DWORD")
$ = WriteValue("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions",
"NoFileNew","1","REG_DWORD")
$ = WriteValue("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions",
"NoFindFiles","1","REG_DWORD")
$ = WriteValue("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions",
"NoTheaterMode","1","REG_DWORD")

$ = WriteValue("HKLM\Software\Policies\Microsoft\Internet Explorer\Infodelivery\Restrictions",
"NoSplash","1","REG_DWORD")

$ie = CreateObject("internetexplorer.application")
$ie.addressbar = 0
$ie.menubar = 0
$ie.statusbar = 0
$ie.toolbar = 0
$ie.resizable = 0
$ie.Left = 10
$ie.top = 10
$ie.width = 1000
$ie.height = 700
$ie.navigate("about:blank")
While $ie.busy AND $ie.readystate <> 4 AND @error=0 Loop
$ie.visible=1

$ie.navigate("http://URL_TO_GO_TO")
While $ie.busy AND $ie.readystate <> 4 AND @error=0 Loop

$ = WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyEnable",$proxy,"REG_DWORD")

Kill95 is the one from helpdesk.kixtart.org (if I remember correctly) and this is giving me the command box.

I run this script with "wkix32 /i"

WMI can't be used as it's not started... Starting also displays the box.

*** Gonna catch my train so will read your replies tomorrow... ***


LonkeroAdministrator
(KiX Master Guru)
2002-11-14 03:57 PM
Re: Run IE and enable proxy only for this windows

just change your line...
don't remember have I used 95 ever but in nt reskit there is kill and using it you can do:
Shell @scriptdir+"\kill iexplore.exe /f"

mm...
not sure does it flash another window or does it show it in same window.
if in same:
Shell @scriptdir+"\kill iexplore.exe /f 2>&1 >nul"

worky?

{edit}
if it still opens the window you can choose from 2:
1.Shell @scriptdir+"\kill iexplore.exe /f" setconsole("hide")
2.Shell "start "+@scriptdir+"\kill iexplore.exe /f"

[ 14. November 2002, 15:59: Message edited by: Lonkero ]


JochenAdministrator
(KiX Supporter)
2002-11-14 04:08 PM
Re: Run IE and enable proxy only for this windows

At least I know that kill doesn't fire a console window if issued by start -> run

LonkeroAdministrator
(KiX Master Guru)
2002-11-14 04:13 PM
Re: Run IE and enable proxy only for this windows

j, not true.
I have multiple times killed wkix32 that way and everytime it flashes the console window


JochenAdministrator
(KiX Supporter)
2002-11-14 04:29 PM
Re: Run IE and enable proxy only for this windows

Yeah correct,

didn't ever notice as it is really quick [Eek!]


Radimus
(KiX Supporter)
2002-11-14 09:18 PM
Re: Run IE and enable proxy only for this windows

get this to work right... and it could be used as a great pop-up ad killer. [Big Grin] [Cool] [Big Grin]

Will Hetrick
(Hey THIS is FUN)
2002-11-19 01:33 PM
Re: Run IE and enable proxy only for this windows

Patrick,
Can the users go to any site they want while in the "proxy enabled" IE that is running?
I would think that they could start up this training site then while it is running go to any site they want while making sure not to close out that session?

Is this true?

Will


LonkeroAdministrator
(KiX Master Guru)
2002-11-19 02:29 PM
Re: Run IE and enable proxy only for this windows

that it the way it's created.

Will Hetrick
(Hey THIS is FUN)
2002-11-19 02:43 PM
Re: Run IE and enable proxy only for this windows

So lonkero,
What you are saying is the people who do not have proxy access, if they are smart enough, they can have it. [Big Grin]


LonkeroAdministrator
(KiX Master Guru)
2002-11-19 02:53 PM
Re: Run IE and enable proxy only for this windows

in this case.
actually, that is a fact of life.
if one is smart enough, he can build a kix-trojan which will destroy the system it's running when it's tried to remove [Razz]

security by ignorance is one of the basic sins of humanity.


Les
(KiX Master)
2002-11-19 02:55 PM
Re: Run IE and enable proxy only for this windows

I guess stupidity would be a close second...

Will Hetrick
(Hey THIS is FUN)
2002-11-19 02:56 PM
Re: Run IE and enable proxy only for this windows

That is the best kind of users to have. That way I still have a job [Big Grin]

Richard H.Administrator
(KiX Supporter)
2002-11-19 02:58 PM
Re: Run IE and enable proxy only for this windows

Apologies for coming a little late to this, but...

Wouldn't the simplest solution be to provide a ".pac" file?

This is a file used to automatically configure the browser proxy settings. It is simple javascript, and would look something like:

code:
function FindProxyForURL(url, host)
{
if (host == "www.training-host.com"){
return "PROXY myproxy.mydomain.com:8080";
} else {
return "DIRECT";
}
}

In this example any request for www.training-host.com would be sent to the proxy "myproxy.mydomain.com", all other requests would be forced to be local.

You would disable access to the IE configuration screens to stop your users fiddling, and assign the ".pac" file name during logon.


MightyR1
(MM club member)
2002-11-19 03:04 PM
Re: Run IE and enable proxy only for this windows

Richard,

howto assign the .pac???

I came up with this:
code:
;****************************************************************************
;
;SCRIPT : IE_with_proxy()
;
;AUTHOR : Patrick Rutten (MightyR1@hotmail.com)
;
;CONTRIBUTORS : KiXtart buddies
;
;ACTION : Starts IE with proxy settings
;
;SYNTAX : <path>wkix32.exe /i <path>IE_with_proxy.kix $proxy="PROXY_IP:PROXY_PORT"
; $url="http://URL_TO_GO_TO"
;
;VERSION : 1.0 - 2002-11-14
; initial release
; 1.1 - 2002-11-15
; added $proxy/$url arguments support
; modified proxyoverride/proxyserver; now contains correct settings
; window is now created dynamically using screenresolution
;
;PARAMETERS : $proxy
; IP-address of proxyserver
; $url
; destination url
;
;REMARKS : Current proxy settings will be remembered
;
;RETURNS : Nothing
;
;DEPENDENCIES : wkix32.exe (4.12) in @scriptdir
; - http://www.scriptlogic.com/downloads/kix/KiX2001_412.zip
; W9x (@inwin=2): kill95.exe in @scriptdir
; - http://helpdesk.kixtart.org/Download/Utils/kill95.zip
; NT and up (@inwin=1): WMI (installed on W2k by default)
; UDF GetScreenRes written by Kholm
; - http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000035
; UDF WMIQuery written by Radimus
; - http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000117
; UDF Taskbar written by Lonkero
; - http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_profile;u=00002306
;
;KIXTART VER : 4.x
;
;EXAMPLE(S) :
;
;KNOWN ISSUES :
;
;****************************************************************************
;
;

;Allow CTRL-C
Break on

;Display error message if parameters are empty and exit
If ""=$url OR ""=$proxy
$rc=MessageBox("Parameters incorrect!"+@crlf+"Neem contact op met uw helpdesk.",
"KiXtart message",16,120)
Exit 0
EndIf

;Display warning message; OK/CANCEL buttons, timeout = 120 seconds
$rc=MessageBox("Sluit alle andere Internet Explorer vensters."+
@crlf+"Na 2 minuten òf na het klikken op OK, worden ze automatisch gesloten!",
"KiXtart message",49,120)

;Quit script if CANCEL is pressed
If 2=$rc
Exit 0
EndIf

;KILL all running iexplore.exe; W95 use kill95, NT use WMI
If 2=@inwin
;Still shows dos box ;(
Shell "%comspec% /c @scriptdir\kill95 iexplore.exe > nul"
Else
$GetObj="winmgmts:{impersonationLevel=impersonate}!//@WKSTA"
$Sel="select * from Win32_Process where Name='IEXPLORE.exe'"
For Each $Process in GetObject("$GetObj").ExecQuery("$sel")
$rc=$Process.Terminate
Next
EndIf

;Save previous proxy settings
$prevprox=ReadValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyEnable")
;Enable proxy
$rc=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyEnable","1","REG_DWORD")
;Set proxy override
$ProxyOverride="PROXY_OVERRIDE_SETTINGS"
$rc=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyOverride",$ProxyOverride,"REG_SZ")
;Set proxy server to $proxy
$ProxyServer="$proxy"
$rc=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyServer",$ProxyServer,"REG_SZ")
;Disable CTRL-O in IE
$rc=WriteValue("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions",
"NoFileOpen","1","REG_DWORD")
;Disable CTRL-N in IE
$rc=WriteValue("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions",
"NoFileNew","1","REG_DWORD")
;Disable F3 in IE
$rc=WriteValue("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions",
"NoFindFiles","1","REG_DWORD")
;Disable F11 in IE
$rc=WriteValue("HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions",
"NoTheaterMode","1","REG_DWORD")
;Disable IE splashscreen
$rc=WriteValue("HKLM\Software\Policies\Microsoft\Internet Explorer\Infodelivery\Restrictions",
"NoSplash","1","REG_DWORD")

;Create IE object
$ie=CreateObject("internetexplorer.application")
;Define IE properties
$ie.addressbar=0
$ie.menubar=0
$ie.statusbar=0
$ie.toolbar=0
$ie.resizable=0
$ie.Left=1
$ie.top=1
$res=Split(getscreenres(),",")
$x=$res[0]
$y=$res[1]
$tb=taskbar()
$y=CInt($y)-$tb
$ie.width=$x
$ie.height=$y

;Display white window
$ie.navigate("about:blank")
;Loop until IE is ready
While $ie.busy AND $ie.readystate <> 4 AND @error=0 Loop
;Make IE window visible
$ie.visible=1

;Browse to $url
$ie.navigate("$url")
;Loop until IE is ready
While $ie.busy AND $ie.readystate <> 4 AND @error=0 Loop

;Restore previous proxy setting
$rc=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings",
"ProxyEnable",$prevprox,"REG_DWORD")

;Quit script
Exit 0

;****************************************************************************
;****************************************************************************
;****************************************************************************
;Following UDF are borrowed from KiXtart buddies...

;Function GetScreenRes written by Kholm
;http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000035
Function GetScreenRes()
Dim $Dev,$Idx,$RKey,$ScreenXRes,$ScreenYRes,$SType
$GetScreenRes = ''
If @InWin = 1
If Split(@ProductType)[1] <> "NT"
$Dev = Split('' + WMIQuery("VideoModeDescription","Win32_VideoController"))
If Ubound($Dev) > 1
$GetScreenRes = $Dev[0] + "," + $Dev[2]
EndIf
Else
$RKey="HKLM\SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Services"
$Dev = "\Device0"
If KeyExist($RKey)
$Idx = 0
Do
$SType = EnumKey($RKey,$Idx)
If @Error = 0 AND $SType <> "VgaSave"
$ScreenXRes = '' + ReadValue($RKey + "\" + $SType + $Dev,"DefaultSettings.XResolution")
$ScreenYRes = '' + ReadValue($RKey + "\" + $SType + $Dev,"DefaultSettings.YResolution")
Else
$Idx = $Idx + 1
EndIf
Until @Error OR $ScreenXRes
If $ScreenXRes
$GetScreenRes = $ScreenXRes + ',' + $ScreenYRes
EndIf
EndIf
EndIf
Else
$RKey="HKLM\Config\0001\Display\Settings"
If KeyExist($RKey)
$GetScreenRes = ReadValue($RKey,"Resolution")
EndIf
EndIf
EndFunction

;Function WMIQuery written by Radimus
;http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000117
Function WMIQuery($what,$where, optional $computer)
Dim $strQuery, $objEnumerator, $value
If NOT $computer $computer="@WKSTA" EndIf
$strQuery = "Select $what From $where"
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//$computer")
$objEnumerator = $SystemSet.ExecQuery($strQuery)
For Each $objInstance in $objEnumerator
If @Error = 0 AND $objInstance <> ""
$=Execute("$$value = $$objInstance.$what")
$WMIQuery="$value"+"|"+"$WMIQuery"
EndIf
Next
$WMIQuery=Left($WMIQuery,Len($WMIQuery)-1)
Exit @error
EndFunction

;Function borrowed from Lonkero's bbChecker
Function TaskBar()
If @dos=="4.0" $_S="StuckRects" Else $_S="StuckRects2" EndIf
$TaskBar=Val("&"+SubStr(ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\$_S","settings"),41,2))
EndFunction

Any comments are welcome...


Will Hetrick
(Hey THIS is FUN)
2002-11-19 03:05 PM
Re: Run IE and enable proxy only for this windows

Richard,
Where would this PAC file reside


Sealeopard
(KiX Master)
2002-11-19 03:15 PM
Re: Run IE and enable proxy only for this windows

If you use the IEAK, there's an option to provide proxy settings through a web link. Never used it myself, however, that might work for you.

Richard H.Administrator
(KiX Supporter)
2002-11-19 03:16 PM
Re: Run IE and enable proxy only for this windows

Working from memory so bear with me boys..

There are a couple of ways.

Open IE and go to Tools->Internet Options->Connections->LAN Settings

There are two fields of interest. The "Automatically detect settings" will look for a file called "wpad.dat" on a local web server called "wpad". This file should be in the same format as a ".pac" file.

"Use automatic configuration script" will allow you to specify the script name. You are supposed to be able to use local file names rather than a URL, but I haven't tried this.

Both these values should be settable via registry writes during logon.

The ".pac" file is described on Netscapes site, but it applies to both NS and IE. Search MS site for more info - the IEAK has more info.