craigholohan Posted November 18, 2006 Posted November 18, 2006 Ok thats itAttached is what I have it is very untidy and very amateur but most of it works.I know I need to put more error messages in but to be honest I am too afraid to mess with it now so if anyone wants to help with that it would be great.Main Problem though:Everything works except for the Proxy Setting when logged on as a User, when logged on as Admin it works fine, so pleeeease show me where I am doing it wrong and how I can fix it.If you log on as a user, click "Proxy">>"Change Proxy" you will see what I mean, but when logged on as an Admin it will change the proxy settings.Thanks,CraigQuick_NIC.au3INIFiles.zip
The Kandie Man Posted November 19, 2006 Posted November 19, 2006 (edited) You aren't going to get any help this way craigholohan. You won't find many people here with the time or the effort that will go through a 1186 line script to find a problem. Post the 10 lines of code that are giving the problem. The more detail and insight you give us, the more we will be able to help you. The key here is, the easier you make it for us to help you, the more likely you will get help. Edited November 19, 2006 by The Kandie Man "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire
craigholohan Posted November 19, 2006 Author Posted November 19, 2006 Thanks The Kandie Man, I was not sure how to handle this one but thanks for the advice, I am going to look at it with fresh eyes today. I think the code is ok actually the problem I think is the Reg keys so I am going to play with that today, if I still have problems I will post again and try explaining in more detail. The lines I thought where the problem is between 878 and 986 where I am trying to write to the registry. I am strating the script to RunAsSet so I thought the whole time it will be running as Admin, but still the RegWrite and RegDelete dont seem to work as a user. Well I will crack on now, Cheers, Craig
MHz Posted November 19, 2006 Posted November 19, 2006 (edited) Unchanged codeexpandcollapse popupIf Not IsAdmin() Then Call("_setAdmin") Exit EndIf Func _setAdmin() $AdminName = IniRead(@SystemDir & "\QuickNIC.ini", "String225", "String200", "") $AdminPass = IniRead(@SystemDir & "\QuickNIC.ini", "String225", "String100", "") $UserString = _HexToString($AdminName) $PassString = _HexToString($AdminPass) If @UserName <> $UserString Then Select Case @error = 0 RunAsSet($UserString, @ComputerName, $PassString) If StringInStr(@ScriptFullPath, '.au3') Then Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" ' & $PassString) Else Run('"' & @ScriptFullPath & '" ' & $PassString) EndIf If @error Then $iMsgBoxAnswer = MsgBox(49, "Quick NIC", "Admin rights required for Quick NIC to run." & @CRLF & "You unfortunately do not have Admin rights on this computer." & @CRLF & @CRLF & "1) If you know the Administrator User Name and Password click Ok and follow the instructions." & @CRLF & "You will only need to supply this information once, unless you change the Admin Password." & @CRLF & @CRLF & "2) If you do not know the Administrator User Name and Password click Cancel" & @CRLF & "and contact your systems administrator for the information before continuing." & @CRLF & @CRLF) Select Case $iMsgBoxAnswer = 1 $StringUser = InputBox($s_Title, "Enter local Admin user name:", '', '', '280', '160', '-1', '-1') $StringPass = InputBox($s_Title, "Enter local Admin password:", '', '*', '280', '160', '-1', '-1') $HexUser = _StringToHex($StringUser) $HexPass = _StringToHex($StringPass) IniWrite(@SystemDir & "\QuickNIC.ini", "String225", "String200", $HexUser) IniWrite(@SystemDir & "\QuickNIC.ini", "String225", "String100", $HexPass) MsgBox(64, $s_Title, "You have successfully set Admin credentials." & @CRLF & "Please restart Quick NIC?") Case $iMsgBoxAnswer = 2 Exit EndSelect EndSelect Else Exit EndIf EndFunc1. You do not need to use Call(). Just call the function directly as _setAdmin().2. You only use RunAsSet if the logon user <> ini user which seems undesirable so you may not get admin permissions. If your not Admin, then you may need to RunAsSet one way or another or just Exit, cause your script needs the permission? Edited November 19, 2006 by MHz
craigholohan Posted November 20, 2006 Author Posted November 20, 2006 Hi Guys, MHz thanks for the post, I dont really understand. I need to run my script as Admin in order to change the IP address info. But after reading and trying to understand what you said I created a new .exe for the proxy settings without checking if the user is an Admin or not. The script then works so I figures when running the script as Admin, the proxy setting in the REG are being changes for Admin and not current user logged on - hope I am making sence. In the begining of my script as below, am I right at saying that the whole time the script is running, if I am not an Admin it is running as user Admin and not currently logged on user? If so then that explains why my Proxy settings will not cahnge because I am trying to change HKEY_CURRENT_USER If Not IsAdmin() Then call("_setAdmin") Exit EndIf Func _setAdmin() $AdminName = IniRead (@SystemDir & "\QuickNIC.ini", "String225", "String200","") $AdminPass = IniRead (@SystemDir & "\QuickNIC.ini", "String225", "String100","") $UserString = _HexToString($AdminName) $PassString = _HexToString($AdminPass) If @UserName <> $UserString Then Select Case @error = 0 RunAsSet($UserString, @ComputerName, $PassString) If StringInStr(@ScriptFullPath, '.au3') Then Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" ' & $PassString) Else Run('"' & @ScriptFullPath & '" ' & $PassString) EndIf If @error Then $iMsgBoxAnswer = MsgBox(49,"Quick NIC","Admin rights required for Quick NIC to run." & @CRLF & "You unfortunately do not have Admin rights on this computer." & @CRLF & @CRLF & "1) If you know the Administrator User Name and Password click Ok and follow the instructions." & @CRLF & "You will only need to supply this information once, unless you change the Admin Password." & @CRLF & @CRLF & "2) If you do not know the Administrator User Name and Password click Cancel" & @CRLF & "and contact your systems administrator for the information before continuing." & @CRLF & @CRLF) Select Case $iMsgBoxAnswer = 1 $StringUser = InputBox($s_Title, "Enter local Admin user name:", '', '', '280', '160', '-1', '-1') $StringPass = InputBox($s_Title, "Enter local Admin password:", '', '*', '280', '160', '-1', '-1') $HexUser = _StringToHex($StringUser) $HexPass = _StringToHex($StringPass) IniWrite(@SystemDir & "\QuickNIC.ini", "String225", "String200", $HexUser) IniWrite(@SystemDir & "\QuickNIC.ini", "String225", "String100", $HexPass) MsgBox(64,$s_Title,"You have successfully set Admin credentials." & @CRLF & "Please restart Quick NIC?") Case $iMsgBoxAnswer = 2 Exit EndSelect EndSelect Else Exit EndIf EndFunc So what I tried was to put the "RunAsSet()" in the begining of the function where I call the Proxy Form, I though that would set me back to running the script as logged on user but it does not help. Func _ProxyForm() RunAsSet() ; GUIPROXY ; ======== $Proxy_Form = GUICreate($s_TitleProxy& " - v" &$s_Version, 297,180,-1,-1,$ws_sysmenu,$ws_ex_overlappedwindow) GUISetState (@SW_SHOW) GuiSetIcon(@ScriptDir & "\Icons\proxy.ico", 0) RunAsSet(@UserName,@ComputerName,"") ; INPUT-PROXY ; =========== GUICtrlCreateGroup("Proxy Server", 5, 15, 280, 95) $proxy_AutoDummy = GUICtrlCreateCheckbox("Automatically Detect Settings",25,30,-1,-1) GUICtrlSetState($proxy_AutoDummy, $gui_unchecked) GUICtrlSetOnEvent ($proxy_AutoDummy, "_ProxyAuto") $proxy_UseProxyDummy = GUICtrlCreateCheckbox("Use a Proxy server for your LAN",25,50,-1,-1) GUICtrlSetState($proxy_UseProxyDummy, $gui_unchecked) GUICtrlSetOnEvent ($proxy_UseProxyDummy, "_ProxySet") $proxy_address = GUICtrlCreateInput("", 75, 80, 103, 20, $ES_AUTOHSCROLL+$WS_DISABLED) GUICtrlCreateLabel("Address :", 20, 83,-1,20) $proxy_port = GUICtrlCreateInput("", 235, 80, 40, 20,$WS_DISABLED) GUICtrlCreateLabel("Port :", 190, 83,-1,20) GUICtrlCreateGroup("", -99, -99, 1, 1) ; BUTTON ; ====== $buttonDummyProxy = GUICtrlCreateButton("Change Proxy", 5, 115, 137, 30, $WS_DISABLED) $buttonDoneProxy = GUICtrlCreateButton("Exit Application", 147, 115, 137, 30, "") GUICtrlSetOnEvent($buttonDoneProxy, "buttonDone_Proxy") GUICtrlCreateGroup("", -99, -99, 1, 1) EndFunc How can I change the script to run as logged on user when calling the proxy form without exiting the main script. Hope this all makes sence and some one has a resolution for me. Thanks, Craig
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now