Simulator Posted September 26, 2006 Share Posted September 26, 2006 Hi, So, I have a program that attempts to connect to a remote computer. When the computer does not have its network enabled, it shows an error. I want to determine if this has happened and then show a message box only if the error dialog has been shown. My code is below. If you can help me, I give tnaks in advance. Regards, Simulator expandcollapse popup#include <GUIConstants.au3> #include <Process.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=j:\koda_1.6.0.2\forms\remoteconnect.kxf $Form1_1 = GUICreate("Remote Connect", 218, 100, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "AForm1_1Close") GUISetOnEvent($GUI_EVENT_MINIMIZE, "AForm1_1Minimize") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "AForm1_1Maximize") GUISetOnEvent($GUI_EVENT_RESTORE, "AForm1_1Restore") $ComputerList = GUICtrlCreateList("", 8, 8, 201, 45) GUICtrlSetData(-1, "Andrew-27r2p7m7|Homeuser-khvkjq") GUICtrlSetOnEvent(-1, "ComputerListClick") GUICtrlSetTip(-1, "Select The Computer You Want To Connect To") $buttonConnect = GUICtrlCreateButton("Connect", 8, 64, 57, 25, 0) GUICtrlSetOnEvent(-1, "buttonConnectClick") GUICtrlSetTip(-1, "Connect To Selected Computer") $buttonAbout = GUICtrlCreateButton("About", 80, 64, 57, 25, 0) GUICtrlSetOnEvent(-1, "buttonAboutClick") $buttonExit = GUICtrlCreateButton("Exit", 152, 64, 57, 25, 0) GUICtrlSetOnEvent(-1, "buttonExitClick") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func AForm1_1Close() ; Exits The Script Exit EndFunc Func AForm1_1Maximize() EndFunc Func AForm1_1Minimize() EndFunc Func AForm1_1Restore() EndFunc Func buttonAboutClick() ; Display A Simple ABout Dialog MsgBox(64, "About", "Program By: James Pannell (pannellj@vic.chariot.net.au)") EndFunc Func buttonConnectClick() ;Display Message Box to confirm connect. ;MsgBox(4, "Confirm?", "Are You Sure You Want To Connect To:") If MsgBox(4, "Confirm?", "Are You Sure You Want To Connect To: " & GUICtrlRead($ComputerList)) = 6 Then Sleep(200) MsgBox(48, "Exclamation", "A Dialog May Appear Asking For Your USername and Password!") ;Calls the connecting routine Call ("Connecting") Else EndIf EndFunc Func buttonExitClick() ;Exits The Program Exit EndFunc Func ComputerListClick() EndFunc Func Connecting() ;This function performs the actual connecting routine. Send("{LWINDOWN}") Sleep(200) Send("{r}") Sleep(200) Send("{LWINUP}") Sleep(200) Send("\\" & GUICtrlRead($ComputerList)) Sleep(200) Send("{ENTER}") EndFunc Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 26, 2006 Share Posted September 26, 2006 Hi, there are several things I would do a different way, but maybe this helps you out: expandcollapse popup#include <GUIConstants.au3> #include <Process.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=j:\koda_1.6.0.2\forms\remoteconnect.kxf $Form1_1 = GUICreate("Remote Connect", 218, 100, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "AForm1_1Close") GUISetOnEvent($GUI_EVENT_MINIMIZE, "AForm1_1Minimize") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "AForm1_1Maximize") GUISetOnEvent($GUI_EVENT_RESTORE, "AForm1_1Restore") $ComputerList = GUICtrlCreateList("", 8, 8, 201, 45) GUICtrlSetData(-1, "Andrew-27r2p7m7|Homeuser-khvkjq") GUICtrlSetOnEvent(-1, "ComputerListClick") GUICtrlSetTip(-1, "Select The Computer You Want To Connect To") $buttonConnect = GUICtrlCreateButton("Connect", 8, 64, 57, 25, 0) GUICtrlSetOnEvent(-1, "buttonConnectClick") GUICtrlSetTip(-1, "Connect To Selected Computer") $buttonAbout = GUICtrlCreateButton("About", 80, 64, 57, 25, 0) GUICtrlSetOnEvent(-1, "buttonAboutClick") $buttonExit = GUICtrlCreateButton("Exit", 152, 64, 57, 25, 0) GUICtrlSetOnEvent(-1, "buttonExitClick") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func AForm1_1Close() ; Exits The Script Exit EndFunc ;==>AForm1_1Close Func AForm1_1Maximize() EndFunc ;==>AForm1_1Maximize Func AForm1_1Minimize() EndFunc ;==>AForm1_1Minimize Func AForm1_1Restore() EndFunc ;==>AForm1_1Restore Func buttonAboutClick() ; Display A Simple ABout Dialog MsgBox(64, "About", "Program By: James Pannell (pannellj@vic.chariot.net.au)") EndFunc ;==>buttonAboutClick Func buttonConnectClick() ;Display Message Box to confirm connect. Ping(GUICtrlRead($ComputerList, 250)) If Not @error = 0 Then MsgBox(0, "", GUICtrlRead($ComputerList) & " is offline") Exit EndIf If MsgBox(4, "Confirm?", "Are You Sure You Want To Connect To: " & GUICtrlRead($ComputerList)) = 6 Then Sleep(200) MsgBox(48, "Exclamation", "A Dialog May Appear Asking For Your USername and Password!") ;Calls the connecting routine Connecting() Else EndIf EndFunc ;==>buttonConnectClick Func buttonExitClick() ;Exits The Program Exit EndFunc ;==>buttonExitClick Func ComputerListClick() EndFunc ;==>ComputerListClick Func Connecting() ;This function performs the actual connecting routine. Send("#r") Send("\\" & GUICtrlRead($ComputerList) & "{ENTER}") EndFunc ;==>Connecting So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Simulator Posted September 29, 2006 Author Share Posted September 29, 2006 Thanks for your reply. I think you may have misunderstood me but thanks for the tip on the keypresses. Saved me a lot of code When the computer is unavailable, the error is titled the computer name and then it says the network path was not found. I want to detect if this has occurred. If anyone else can help. Please do. Regards, Simulator Link to comment Share on other sites More sharing options...
jinxter Posted September 29, 2006 Share Posted September 29, 2006 it does seem like you are missing the first letter in the computername when you try to run the map command. Is it possible for you to do a drivemapadd instead ? otherwise this might help (at least it did for me) Send("#r") Sleep(200) Send("\\" & GUICtrlRead($ComputerList) & "{ENTER}") > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
Simulator Posted September 29, 2006 Author Share Posted September 29, 2006 it does seem like you are missing the first letter in the computername when you try to run the map command. Is it possible for you to do a drivemapadd instead ? otherwise this might help (at least it did for me) Send("#r") Sleep(200) Send("\\" & GUICtrlRead($ComputerList) & "{ENTER}") Thanks, thats how i want it. I dont want to map the drive i just want to connect to the computer. The code I have does exactly what I want it to. I'm just having probs catching if an error occurs. And if i have it in there, it will display my message even if the error occurs. I've attached a pic of the error I want a msgbox to appear on (Only want it to occur on this error!) Link to comment Share on other sites More sharing options...
jinxter Posted September 29, 2006 Share Posted September 29, 2006 (edited) Like this ? Func buttonConnectClick() ;Display Message Box to confirm connect. $var = Ping(GUICtrlRead($ComputerList, 250)) if $var Then If MsgBox(4, "Confirm?", "Are You Sure You Want To Connect To: " & GUICtrlRead($ComputerList)) = 6 Then Sleep(200) MsgBox(48, "Exclamation", "A Dialog May Appear Asking For Your USername and Password!") ;Calls the connecting routine Connecting() Else ;~ EndIf Else Select ; Trap the @error here Case @error = 2 ; 2 = Host is unreachable Msgbox(0,"\\"&GUICtrlRead($ComputerList),"\\"&GUICtrlRead($ComputerList)&@CRLF&@CRLF&"The network path was not found.") Case @error = 0 Case Else ; else EndSelect EndIf EndFunc ;==>buttonConnectClick Edited September 29, 2006 by jinxter > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
Simulator Posted September 29, 2006 Author Share Posted September 29, 2006 (edited) Thanks. I'll give that a try. EDIT: Unfortunately it didn't work. It would do nothing after i clicked the Connect button. I waited a minute or two as well. Regards, Simulator Edited September 29, 2006 by Simulator Link to comment Share on other sites More sharing options...
jinxter Posted September 29, 2006 Share Posted September 29, 2006 Thanks. I'll give that a try.EDIT: Unfortunately it didn't work. It would do nothing after i clicked the Connect button. I waited a minute or two as well.Regards, Simulatorhmm... it worked for me, I tried to add a computer not on my network, and one that wasn't alive... both of them worked.add a TrayIconDebug = 1 so you can see if it hangs on a line... > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
Simulator Posted September 29, 2006 Author Share Posted September 29, 2006 Well it seems to be pinging but even if the computer is there it still does nothing. When i put my mouse over the system tray icon is says it is at line 33 which is a Sleep(100) command in the first GUI's loop routine. It looks as if it isn't reading the button click function. Regards, Simulator Link to comment Share on other sites More sharing options...
jinxter Posted September 29, 2006 Share Posted September 29, 2006 hmmm... strange... wonder if you should do a GuiGetMsg() with select-case's in the Gui loop instead... what version of AutoIT are you using ? > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
Simulator Posted September 29, 2006 Author Share Posted September 29, 2006 hmmm... strange... wonder if you should do a GuiGetMsg() with select-case's in the Gui loop instead... what version of AutoIT are you using ?I'm using AutoIt v3.2.0.1It certainly is strange.Regards, Simulator 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