Brad Posted August 30, 2007 Share Posted August 30, 2007 (edited) This is a program i made to query my sms servers, and return the computer a specified user is logged on to. only problem is that if you enter in a incorrect username, a username it has no info for, or accidentaly leave it blank then the script errors out at $objRecordSetSMSdata.movefirst I have been searching for days, looking at vbs scripts, au3 scripts, and searching the forums. I dont usuially post because i can usuialy find something or figure it out. But, i am still just unable to find a way that works for this program. Here is the script for my gui users computer finder, and any help would be appreciated. Thanks expandcollapse popup#NoTrayIcon #include <GuiConstants.au3> #Include <GuiListView.au3> GUIDelete() Dim $filetxtsms, $sConnString, $objSQL, $objRecordset, $objRecordSetSMSdata, $smsResourceID, $input, $listView, $oMyError ;$user = InputBox ( 'User Name', 'Please enter the User Name you wish to find' ) ;If @error Then Exit GuiCreate("Find User", 373, 190) GuiSetIcon(@SystemDir & "shell32.dll",170) GUICtrlCreateLabel ("Username", 10, 15, 50, 20) $input=GUICtrlCreateInput ("", 70, 10, 100, 20) $listView = GuiCtrlCreateListView("User Name|Computer Name|Domain", 10, 40, 353, 140) $fbutton2 = GUICtrlCreateButton ("copy", 240,10,50,20) GUICtrlSetOnEvent($fbutton2,"copy") $fbutton3 = GUICtrlCreateButton ("Find", 310,10,50,20,$BS_DEFPUSHBUTTON) GUICtrlSetOnEvent($fbutton3,"list") GUISetOnEvent($GUI_EVENT_CLOSE,"close") Opt("GUIOnEventMode", 1) GUISetState() while 1 sleep (50) WEnd Func list() $user=GUICtrlRead($input) ;connect to sms $sConnString = "Driver={SQL Server}; Server="put your sms server here"; Database=SMS_TMP; Trusted_Connection=yes;" $objSQL = ObjCreate("ADODB.Connection") $objSQL.open ($sConnString) ;request sms info $objRecordSetSMSdata = ObjCreate("ADODB.RecordSet") $objRecordsetSMSdata.Open ("SELECT SYS.User_Name0, SYS.Netbios_Name0, SYS.User_Domain0, Operating_System_Name_and0, SYS.Resource_Domain_OR_Workgr0 FROM v_R_System SYS WHERE User_Name0 LIKE '" & $user & "' ORDER BY SYS.User_Name0, SYS.Netbios_Name0", $objSQL, 3 , 3) ;if @error then MsgBox(1,"test", "there was an error") ;$error=ObjCreate("ADODB.Error") ;$oMyError = ObjEvent ($objRecordSetSMSdata.ActiveConnection.Errors, "error") ;MsgBox(1,"test",$objRecordSetSMSdata.ActiveConnection.Errors.number) $objRecordSetSMSdata.movefirst;If @error then MsgBox(1,"test", "there was an error") ;if @error then MsgBox(1,"test", "there was an error") ;get sms info while not $objRecordSetSMSdata.eof $smsresourceID = $objRecordSetSMSdata.Fields("User_Name0").value $smsresourceID2 = $objRecordSetSMSdata.Fields("Netbios_Name0").value $smsresourceID3 = $objRecordSetSMSdata.Fields("Resource_Domain_OR_Workgr0").value ;if MsgBox(1,"test",$smsresourceID&" "&$smsresourceID2) = 2 Then close() guiCtrlCreateListViewItem($smsresourceID&"|"&$smsresourceID2&"|"&$smsresourceID3 , $listView) $objRecordSetSMSdata.movenext WEnd guiCtrlCreateListViewItem(" " , $listView) $objSQL.close EndFunc Func copy() $line=GUICtrlRead(GUICtrlRead($listview)) if $line = "" then Return $line = StringSplit($line, "|") ClipPut ($line[2]) EndFunc Func close() GUIDelete() Exit EndFunc ;func error() ; Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ ; "err.description is: " & @TAB & $oMyError.description & @CRLF & _ ; "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ ; "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _ ; "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ ; "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ ; "err.source is: " & @TAB & $oMyError.source & @CRLF & _ ; "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ ; "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ; ) ; ; Local $err = $oMyError.number ; If $err = 0 Then $err = -1 ; ; SetError($err); to check for after this function returns ; $objSQL.close ; Return ;EndFunc As you can see i tried a fiew methods, but lined them all out 1 to show that i was trying, and 2 because they were unsucesfull. I tried more ways, but these were the ones left in the code. Edited August 30, 2007 by Brad Link to comment Share on other sites More sharing options...
cdkid Posted August 30, 2007 Share Posted August 30, 2007 (edited) Not sure if it'd help but you can try the MySQL.au3 in my sig. Might make it easier. ~cdkid Edited August 30, 2007 by cdkid AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide! Link to comment Share on other sites More sharing options...
Brad Posted August 30, 2007 Author Share Posted August 30, 2007 Realy don't feel like rewriting the whole code, for a single error parse, but if that is the only option i will try it, and thanks for your suggestion.See if anyone else can think of anything.Not sure if it'd help but you can try the MySQL.au3 in my sig. Might make it easier.~cdkid Link to comment Share on other sites More sharing options...
Brad Posted August 30, 2007 Author Share Posted August 30, 2007 HAHAH, i knew i shouldn't of posted, it finally came to me i put if $objRecordSetSMSdata.EOF Then MsgBox(1,"Error", "That was an invalid username, or there is no sms info for that user") Return EndIf before $objRecordSetSMSdata.movefirst done, and thanks for your suggestion again. hope this helps others 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