karmayogi Posted December 2, 2008 Share Posted December 2, 2008 Hi Guys, I am using the _IE UDFs to automate a web page login. The script works wonderfully if I compile and run it as a logged in user. But I have a problem when the same script is run via a Windows service. The following option is already enabled on my Windows Service "Allow interact with desktop" The following is the pseudo code of what I am trying to achieve. ;Create the browser instance and navigate to page. _IECreate() ;get the form _IEFormGetObjByName() ;Get the element required. _IEFormElementGetObjByName() ;set the value for the element retrieved. _IEFormElementSetValue() ;submit the form _IEAction() I have tried at least two variants of submitting a form, using _IEFormSubmit(), iterating through the buttons and calling _IEAction to click. All of these approaches fail under the Windows service model. Why, but oh Why ? Any advice would be invaluable ... Ciao Yogi I came, I saw and I copied. Link to comment Share on other sites More sharing options...
DaleHohm Posted December 3, 2008 Share Posted December 3, 2008 Have you tried doing something simple like bringing up Notepad, typing to it and saving the file using the same model to see if that works? Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
karmayogi Posted December 3, 2008 Author Share Posted December 3, 2008 (edited) I have tried that before, but in the current context I am only dealing with the IE functions and the pure windowing calls are not of relevance to me. In my example, all the calls works except for the submit related ones via the Windows Service. I have even tried link clicks and they all seem to be fine. Its just the submit action. Here is my actual code expandcollapse popup#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** #include <IE.au3> $oIE = _IECreate("http://localhost/abcd/perform.dll?Dashboard", 0, 1, 1, 0) ;To get a form within a page. $oForm = _IEFormGetObjByName($oIE, "logonForm") ;just for debug purposes If ($oForm <> 0) Then logMsg($oForm.innerText) logMsg("Found logonForm") Else logMsg("Did not find logonForm. Cause " & @error) _IEQuit($oIE); Exit EndIf $fldUserId = _IEFormElementGetObjByName($oForm, "User", 0) If ($fldUserId = 0) Then logMsg("Unable to get UserId Field on Logon Form. Cause :" & @error) _IEQuit($oIE); Exit Else _IEFormElementSetValue($fldUserId, "Administrator", 1) logMsg("Set userid"); EndIf $fldPassword = _IEFormElementGetObjByName($oForm, "Password", 0) If ($fldPassword = 0) Then logMsg("Unable to get Password Field on Logon Form. Cause :" & @error) _IEQuit($oIE); Exit Else _IEFormElementSetValue($fldPassword, "Somepass", 1) logMsg("Set Password") EndIf $formElementsCol = _IEFormElementGetCollection($oForm) For $elementX In $formElementsCol If ($elementX.type = "submit") Then logMsg("Located login button"); Global $btnLogin = $elementX ExitLoop Else logMsg("Located some other field " & $elementX.type); EndIf Next $sStatus = _IEAction($btnLogin, "click"); ;_IEAction($btnLogin,"click"); If ($sStatus = 0) Then logMsg("Unable to submit login form. Cause :" & @error) _IEQuit($oIE); Exit Else logMsg("Submitted form to login") _IEQuit($oIE); Exit EndIf _IELoadWait($oIE, 1000, 60000) ;This call clicks on a link to open the admin panel _IENavigate($oIE, "http://localhost/abcd/perform.dll?a=Admin", 1) _IELinkClickByText($oIE, "Marketing", 0, 1) ;This call waits for the new page to load _IELoadWait($oIE, 1000, 60000) ;This call clicks on a link _IELinkClickByText($oIE, "Log Out", 0, 1) _IEQuit($oIE) Thanks Yogi Have you tried doing something simple like bringing up Notepad, typing to it and saving the file using the same model to see if that works? Dale Edited December 3, 2008 by karmayogi I came, I saw and I copied. Link to comment Share on other sites More sharing options...
karmayogi Posted December 4, 2008 Author Share Posted December 4, 2008 I think I figured out what the deal with this problem was. I was running the service as "Local System" with interact with desktop turned on. That was the problem. Looks like when an IE browser is invoked on a server with a "Local System" credential there are some security settings that prevent data from being posted. That explains why only my posts were not working. Solution: Run the service as a domain id and don't worry about not being able to interact with desktop. This will only work if your autoit script is dealing purely with IE automation tasks and has no windowing requirements. Hope this helps someone else. Thanks Yogi I came, I saw and I copied. Link to comment Share on other sites More sharing options...
DaleHohm Posted December 4, 2008 Share Posted December 4, 2008 (edited) this actually would be a good reference for others if you would provide some detailed instructions on what you did and what works and what does not. This question comes up frequently and a cookbook would be very useful if you would be willing to spend the time to create it while it is fresh in your mind. thanks, Dale Edited December 4, 2008 by DaleHohm Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
karmayogi Posted December 4, 2008 Author Share Posted December 4, 2008 Yes Dale, I can help out. I am still trying to figure out the nuance of the actual privileges required. Currently looks like just any id is not enough, it has to be either domain level admin ID or the local administrator ID on the box. If I use an ID which either is just a regular user or a member of the local administrators group, it still hangs on the form.submit(). By the way this is a server 2003 box, so I am still trying to figure out what is the specific privilege it requires to make this happen. I will keep this topic active till I figure that out. If you come across the exact privilege required please let me know. Thanks Yogi I came, I saw and I copied. Link to comment Share on other sites More sharing options...
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