Page 1 of 1 1
Topic Options
#184614 - 2008-01-16 08:18 PM Add logging to this script
CasaMia Offline
Lurker

Registered: 2008-01-16
Posts: 2
I have a script that checks if you are in group and based on this it changes IE Settings.....Can someone tell me how and where I can place an audit for this script.

In other words if you are in this group and if this script changes your IE Settings add a log which says &username was changed to new IE

 Code:
; ===========================================================================================
$ = MessageBox("Checking Group Membership", "AD Group Check ", 0)


If InGroup ("XXXXXXX-US")		;Run this if you are in this group

;setproxy(0,,1)					;remove per user settings
;setproxy(0,,0)					;remove per machine settings
setproxy(1,"XXXXXXX",1)			;set per user settings
;setproxy(1,"XXXXXX",0)			;set per machine settings
? "You will now be migrated to the new proxy server. Please wait..."
Sleep 3
? "-- Updating Internet Explorer Proxy settings."
? ========================================================
? ========================================================
? "-- Done with updating Internet Explorer Proxy settings."
?
?
EndIf 

Function SetProxy($type, optional $Proxy, optional $PerUser)
;Type:
;	0 - disable proxy
;	1 - enable proxy
;Proxy:
;	proxy.domain.com:80
;PerUser
;	1 or not nul - to make proxy settings per user, requires admin privledes
;	0 - to make proxy settings per Machine, requires admin privledes
;
;returns
;	1 - Incorrect Type
;	2 - no proxy server specified
;	3 - policy is set to per machine / requires admin priv

	Dim $regkey, $admin, $gpkey
	$admin = InGroup("@wksta\Administrators")
	$Regkey='HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion'
	$gpkey ='HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion'

	If $admin
		If $PerUser>0				; "per user"
			$=WriteValue("$gpkey\Internet Settings","ProxySettingsPerUser","1",REG_SZ)
			$=WriteValue("$Regkey\Internet Settings","ProxySettingsPerUser","1",REG_SZ)
			EndIf
		If Len($peruser)>0 And $PerUser=0	; "per machine"
			$=WriteValue("$gpkey\Internet Settings","ProxySettingsPerUser","0",REG_SZ)
			$=WriteValue("$Regkey\Internet Settings","ProxySettingsPerUser","0",REG_SZ)
			EndIf
	Else
		If ReadValue("$Regkey\Internet Settings","ProxySettingsPerUser")=0 
		Or ReadValue("$gpkey\Internet Settings","ProxySettingsPerUser") =0
			Exit 3
			Return
			EndIf
		$Regkey='HKEY_Current_User\SOFTWARE\Microsoft\Windows\CurrentVersion'
		EndIf
	If ReadValue("$Regkey\Internet Settings","ProxySettingsPerUser")=1 
	Or ReadValue("$gpkey\Internet Settings","ProxySettingsPerUser") =1		; "per user is set"
		$Regkey='HKEY_Current_User\SOFTWARE\Microsoft\Windows\CurrentVersion'
		EndIf

	Select
		Case $Type=1 And $Proxy 
			$=WriteValue("$Regkey\Internet Settings","ProxyServer","$Proxy",REG_SZ)
			$=WriteValue("$Regkey\Internet Settings","ProxyEnable","1",REG_DWORD)
			$=WriteValue("$Regkey\Internet Settings","ProxyOverride","<local>",REG_SZ)
		Case $Type=0
			$=WriteValue("$Regkey\Internet Settings","ProxyServer","",REG_SZ)
			$=WriteValue("$Regkey\Internet Settings","ProxyEnable","0",REG_DWORD)
			$=WriteValue("$Regkey\Internet Settings","ProxyOverride","<local>",REG_SZ)
		Case $Type=1 
			Exit 2
		Case 1
			Exit 1
		EndSelect
	EndFunction


Top
#184617 - 2008-01-16 10:07 PM Re: Add logging to this script [Re: CasaMia]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
That would not be so hard.

You could open a log file with the Open() function and write stuff to it with the Writeline() function after each change you do to the registry.
When all is done don't forget to close the log file with the Close() function.

One should be careful with this because if one client is writing to the log file any other clients trying to write to it will fail. Best would be creating a specific log file for each user or computer.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#184622 - 2008-01-16 11:15 PM Re: Add logging to this script [Re: Mart]
CasaMia Offline
Lurker

Registered: 2008-01-16
Posts: 2
I cant find these UDF's also where do I place them within this script
Top
#184626 - 2008-01-17 12:18 AM Re: Add logging to this script [Re: CasaMia]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
They are not UDF's but build in functionality. They are all in the manual.

Where to put them? Like I said you could let WriteLine write a line to a log file just after writing something to the registry.
At the top of the script you should use the Open() function (page 85/86 of the 4.60 manual), use the Writeline() function (page 107/108 of the 4.60 manual) to write whatever you want to the file you opened at the top of the script and use the Close() function (page 57/58 of the 4.60 manual) at the bottom of the script to close the log file that you opened at the top of the script.


Edited by Mart (2008-01-17 12:19 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#184630 - 2008-01-17 02:19 AM Re: Add logging to this script [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Much easier than open/writeline/close....

 Code:
; This goes in the main script - change the "my log file" to a valid file/path
Global $LOGFILE
$LOGFILE = "my log file"
Del $LOGFILE              ; always start with a fresh log file

; This goes any place you want to log a message:
LogMsg("This is my log message")

; or - an example including a variable
LogMsg("The value of X is " + $X)


; This goes at the end of your script
Function LogMsg($_Msg)

  Dim $_
  $_ = RedirectOutput($LOGFILE)
  $_Msg ?
  $_ = RedirectOutput('')

  Exit 0

EndFunction

You can place references to LogMsg() anyplace you want to log an event.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#184637 - 2008-01-17 09:34 AM Re: Add logging to this script [Re: Glenn Barnas]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You could also write to the Windows Event log using LogEvent() - it depends on how long you need the information around.
Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.129 seconds in which 0.086 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org