Trying to unlock network system preferences.

I have a script that i made to add our wireless network to a laptop. It works great if the network system preferences is already unlocked. I want this to a total easy to use script and do not want the user to have to unlock it. I have tried this script with no luck.

set myPass to "password"

tell application "System Events"
	tell application process "System Preferences"
		
		click button "Click the lock to make changes." of window "Network"
		tell window 1
			tell scroll area 2 of group 1
				set value of text field 2 to myPass
			end tell
			click button "OK" of group 2
			
		end tell
	end tell
end tell


It dose not seem to work:(

Model: Macbook
Browser: Safari 525.28.3
Operating System: Mac OS X (10.5)

Hi,

it cannot work, because the window belongs to the process SecurityAgent


tell application "System Preferences"
	reveal pane id "com.apple.preference.network"
	activate
end tell

tell application "System Events" to tell window 1 of process "System Preferences"
	tell button 6
		if (its name is "Click the lock to make changes.") then
			click
			my authenticate_changes()
		end if
	end tell
end tell

to authenticate_changes()
	tell application "System Events" to tell window 1 of process "SecurityAgent"
		tell scroll area 1 of group 1
			set value of text field 1 to "username"
			set value of text field 2 to "password"
		end tell
		click button "OK" of group 2
	end tell
end authenticate_changes