Sign in to follow this  
Followers 0
mehrdad39

enabling and disabling buttons

12 posts in this topic

Hi All,

I have three scripts that are tied together. The first script checks the filename that holds the login information for a login script (second script). If the file exists, then the second script (login script) launches and asks for the login information before executing the third script (bunch of utility tools) which is the actual GUI with all the tools. If the file does not exist, then it loads the third script, bypassing the login. All of these work fine. One of the buttons (options) in the third script provides an option to setup new login information using the second script and creating a new login or delete the old login. The problem is that, since the third script is already running, using the option of creating “new/updating login information” and launching the second script (login script), it reloads a duplicate session of the third script (the utilities) through the second script. How can I check to see if the third script is running already (from the second script) and not reload it, once it gets to that part of the code?

Thanks

Mehrdad

Share this post


Link to post
Share on other sites



Thanks for the info. I am not sure how to use the flags. Here is what I run and I still get a second instance of the program.

#include <Misc.au3> 
                if _Singleton("Utility.exe",1) = 0 Then
                Msgbox(0,"","Utility already running")
                Exit
                EndIf
                Run("DCIUtility.exe", "", @SystemDir)

Share this post


Link to post
Share on other sites

It would use the GUI name you created in you script with GUICreate:

#include <Misc.au3>

if _Singleton("GUICreate Title Name",1) = 0 Then

Msgbox(0,"","Utility already running")

Exit

EndIf

Run("DCIUtility.exe", "", @SystemDir)

Share this post


Link to post
Share on other sites

It would use the GUI name you created in you script with GUICreate:

#include <Misc.au3>

if _Singleton("GUICreate Title Name",1) = 0 Then

Msgbox(0,"","Utility already running")

Exit

EndIf

Run("DCIUtility.exe", "", @SystemDir)

I am not sure what you mean by the GUI. The GUI for the second script is already running for the login screen to be present so if I am checking for it, then the state would be true and it will not run the exe file. If the gui is the gui for the utility, then how can I call it from another script? Do I understant it correctly or am I lost? Please keep in mind that I am still very new and still learning.

Thanks

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I am not sure what you mean by the GUI. The GUI for the second script is already running for the login screen to be present so if I am checking for it, then the state would be true and it will not run the exe file. If the gui is the gui for the utility, then how can I call it from another script? Do I understant it correctly or am I lost? Please keep in mind that I am still very new and still learning.

Thanks

The string can be anything globally unique to your script. The string gets used to create a named mutex object, so it doesn't have to come from the file name, GUI name, etc. For example:
#include <Misc.au3>

HotKeySet("{ESC}", "_Quit")

If _Singleton("My_Singleton_Verification_String_ABCD1234", 1) = 0 Then
    MsgBox(0, "", "Utility already running")
    Exit
EndIf

While 1
    ToolTip("Hit ESC to quit...")
    Sleep(100)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

The @ScriptName is usually not a good choice, because simply changing the script/file name allows a second instance of the same script to run.

>_<

Edit: Expanded demo so it could run multiple instances.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The string can be anything globally unique to your script. The string gets used to create a named mutex object, so it doesn't have to come from the file name, GUI name, etc. For example:

#include <Misc.au3>

HotKeySet("{ESC}", "_Quit")

If _Singleton("My_Singleton_Verification_String_ABCD1234", 1) = 0 Then
    MsgBox(0, "", "Utility already running")
    Exit
EndIf

While 1
    ToolTip("Hit ESC to quit...")
    Sleep(100)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

The @ScriptName is usually not a good choice, because simply changing the script/file name allows a second instance of the same script to run.

>_<

Edit: Expanded demo so it could run multiple instances.

I must admit, I am totally lost!!! What you are suggesting as a string for me to check for is fine if all functions were inside of one script. However, they are not. There are three completely seperate scripts. The only time they get called from each other is when the check is being done. I have tried your suggestions and nothing happens and I think is because the string it is searching for ("System Management", 1) from the third script (utility script) is nowhere inside the second script (login script). To reiterate my problem in my first post, I have a flowchart created and below are the steps:

1. Use hot keys to launch File Exist script (1st script)

2. Check for filename (userlog.ini)

3. If exist, launch Login script (2nd Script), if it does not go to Utility script directly.

4. If login correct launch Utility (3rd script)

5. To change, delete or create a new login click “set login” button

6. Launch Login script (2nd script)

7. Assign login, delete login

8. Exit back to Utility already running

Steps 7 and 8 are where I have problems. Since the utility was already running from step 4. It reloads it again when it hits that section of the code in Login script and it continues to load a new session every time the login script is accessed from within the Utility script. I am sure there is something you are trying to teach me here, but I am having a hard time following it. I cannot yet understand all the programming lingo, so if you are still suggesting your previous thoughts, I would like to ask you to put it in dummies terms so I can get it :( .

Thanks for your patience.

Edited by mehrdad39

Share this post


Link to post
Share on other sites

I must admit, I am totally lost!!! What you are suggesting as a string for me to check for is fine if all functions were inside of one script. However, they are not. There are three completely seperate scripts. The only time they get called from each other is when the check is being done. I have tried your suggestions and nothing happens and I think is because the string it is searching for ("System Management", 1) from the third script (utility script) is nowhere inside the second script (login script). To reiterate my problem in my first post, I have a flowchart created and below are the steps:

1. Use hot keys to launch File Exist script (1st script)

2. Check for filename (userlog.ini)

3. If exist, launch Login script (2nd Script), if it does not go to Utility script directly.

4. If login correct launch Utility (3rd script)

5. To change, delete or create a new login click “set login” button

6. Launch Login script (2nd script)

7. Assign login, delete login

8. Exit back to Utility already running

Steps 7 and 8 are where I have problems. Since the utility was already running from step 4. It reloads it again when it hits that section of the code in Login script and it continues to load a new session every time the login script is accessed from within the Utility script. I am sure there is something you are trying to teach me here, but I am having a hard time following it. I cannot yet understand all the programming lingo, so if you are still suggesting your previous thoughts, I would like to ask you to put it in dummies terms so I can get it :D .

Thanks for your patience.

I guess I misunderstood the OP. I thought you wanted the third script to simply bail out if another instance of it was already running. _Singleton() would have only been used inside script 3 to keep it from running multiple instances.

Now it seems you just want to check if it's running before even trying to kick it off again. So, the crux of it simply one process seeing if another process (script 3) is running. That would be ProcessExists():

$sProc3Dir = "C:\Temp\MyTest"
$sProc3 = "Script3.exe"
If ProcessExists($sProc3) Then
    MsgBox(16, "Skip 3", "Script 3 is already running.")
Else
    Run($sProc3Dir & "\" & $sProc3, $sProc3Dir)
EndIf

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I guess I misunderstood the OP. I thought you wanted the third script to simply bail out if another instance of it was already running. _Singleton() would have only been used inside script 3 to keep it from running multiple instances.

Now it seems you just want to check if it's running before even trying to kick it off again. So, the crux of it simply one process seeing if another process (script 3) is running. That would be ProcessExists():

$sProc3Dir = "C:\Temp\MyTest"
$sProc3 = "Script3.exe"
If ProcessExists($sProc3) Then
    MsgBox(16, "Skip 3", "Script 3 is already running.")
Else
    Run($sProc3Dir & "\" & $sProc3, $sProc3Dir)
EndIf

:D

YOU ARE AWESOME!!!!!!!!! it worked great. I have been working on this for a week. Thanks a lot.

Mehrdad

Share this post


Link to post
Share on other sites

YOU ARE AWESOME!!!!!!!!! it worked great. I have been working on this for a week. Thanks a lot.

Mehrdad

Glad it worked. Have a nice weekend!

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Glad it worked. Have a nice weekend!

:D

Thank you. I have one more favor to ask. Looking at the enclosed partial code, why is UltraVNC not starting? It is installed in "C:\ultravnc" directory and it is setup as "server silent" only. if I type "c:\ultravnc\winvnc.exe" in the windows Run command line window, it loads fine. Clicking the button will not launch it. I have also tried typing the full path in the code in place of $uvncpath and it still will not load. I have done the same thing with task manager and other items and they all run fine. Is there something special between Uvnc and Autoit? Thanks for your help.

Edit: I have tried all of the launch commands. I have tried shellexecute, Shellexecutewait, runwait, runas and run (Dos) and it still will not launch it. I tried it on two different systems and in two different directories without any success. I did a search in the forum and google but could not find anything related to this problem. I do not get any errors so I know the commands are correct, I just can't see why it will not lauch it from within the script.

Dim $syspath = "c:\windows\system32\"
    Dim $uvncpath = "c:\ultravnc\"
..
..
..
                Case $msg = $Restart
                    MsgBox(4096, "", "Remove any USB Flash Drives and Click OK")
                    Shutdown(2)
                
                Case $msg = $Finish
;                   MsgBox(4096, "", "Are you sure you want to Exit?")              
                    Exit
                    
                Case $msg = $runTaskMan
                    Run( "taskmgr", $syspath)
                    
                case $msg = $runCMD
                    RunWait(@ComSpec & " /k", @WindowsDir)  
                    
                case $msg = $runUVNC
                    Run( "winvnc.exe", $uvncpath)
                    
                case $msg = $helpitem
                    Run(@comspec & " /c" & $syspath & "dvrmgnt.mht")
                    
                Case $msg = $passwordset
                    Run( "setpass.exe", $syspath)       ;   This starts the password setup program
Edited by mehrdad39

Share this post


Link to post
Share on other sites

Thank you. I have one more favor to ask. Looking at the enclosed partial code, why is UltraVNC not starting? It is installed in "C:\ultravnc" directory and it is setup as "server silent" only. if I type "c:\ultravnc\winvnc.exe" in the windows Run command line window, it loads fine. Clicking the button will not launch it. I have also tried typing the full path in the code in place of $uvncpath and it still will not load. I have done the same thing with task manager and other items and they all run fine. Is there something special between Uvnc and Autoit? Thanks for your help.

Edit: I have tried all of the launch commands. I have tried shellexecute, Shellexecutewait, runwait, runas and run (Dos) and it still will not launch it. I tried it on two different systems and in two different directories without any success. I did a search in the forum and google but could not find anything related to this problem. I do not get any errors so I know the commands are correct, I just can't see why it will not lauch it from within the script.

Dim $syspath = "c:\windows\system32\"
    Dim $uvncpath = "c:\ultravnc\"
..
..
..
                Case $msg = $Restart
                    MsgBox(4096, "", "Remove any USB Flash Drives and Click OK")
                    Shutdown(2)
                
                Case $msg = $Finish
;                   MsgBox(4096, "", "Are you sure you want to Exit?")              
                    Exit
                    
                Case $msg = $runTaskMan
                    Run( "taskmgr", $syspath)
                    
                case $msg = $runCMD
                    RunWait(@ComSpec & " /k", @WindowsDir)  
                    
                case $msg = $runUVNC
                    Run( "winvnc.exe", $uvncpath)
                    
                case $msg = $helpitem
                    Run(@comspec & " /c" & $syspath & "dvrmgnt.mht")
                    
                Case $msg = $passwordset
                    Run( "setpass.exe", $syspath)       ;   This starts the password setup program

I figured it out. Thanks

case $msg = $runUVNC
                    Run(@ProgramFilesDir & $uvncpath & "winvnc.exe")

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0