Jump to content

wonder why ini file written to before runwait finishes


Go to solution Solved by Jos,

Recommended Posts

Func Button2Click()   ;==>        SonoLvl2 *******************************************************
SoundPlay(@ScriptDir &  "\schoolbell.wav", 1)
Local $Test2 = IniRead(@ScriptDir &  "\runer.ini", "Levels", "LComplete1", "Default Value")
If $Test2 = 1 Then
;       $updatepid =
        RunWait(@ScriptDir & "\SonoLvl2\SonoLvl2_.exe", "", @SW_SHOWDEFAULT)
Else
    MsgBox(4096, "", "You did not complete Lesson1")

 EndIf
;MsgBox($MB_SYSTEMMODAL, "Bug Report Environment", _DebugBugReportEnv())


IniWrite(@ScriptDir &  "\runer.ini", "Levels", "LComplete2", "2")

EndFunc ;==>Button2Click

I have tried PID checks and updatepid per the help file and they just didn't work out. and usually caused errors. Then (not included I tried making a separate function to write to a INI file. that was a lesson in frustration and defeat. It worked.. just the same as the code in the function now. as soon as you click the button and the runwait line starts the ini gets updated. The file can only be written to after runwait is running is closed. Also tried the ProcessWait, ProcessWaitCloseShellExecute, ShellExecuteWait

Then in desperation I tried a Debug i read about

Func Button2Click()   ;==>        SonoLvl2 *******************************************************
$__iLineNumber=162 & ' - SoundPlay(@ScriptDir &  "\schoolbell.wav", 1)•'
SoundPlay(@ScriptDir &  "\schoolbell.wav", 1)
$__iLineNumber=163 & ' - Local $Test2 = IniRead(@ScriptDir &  "\runer.ini", "Levels", ...•'
Local $Test2 = IniRead(@ScriptDir &  "\runer.ini", "Levels", "LComplete1", "Default Value")
$__iLineNumber=164 & ' - If $Test2 = 1 Then•'
If $Test2 = 1 Then
        $__iLineNumber=165 & ' - $updatepid = RunWait(@ScriptDir & "\SonoLvl2\SonoLvl2_.exe", ...•'
        $updatepid = RunWait(@ScriptDir & "\SonoLvl2\SonoLvl2_.exe", "", @SW_SHOWDEFAULT)
Else
    $__iLineNumber=167 & ' - MsgBox(4096, "", "You did not complete Lesson1")•'
    MsgBox(4096, "", "You did not complete Lesson1")

 EndIf
;MsgBox($MB_SYSTEMMODAL, "Bug Report Environment", _DebugBugReportEnv())


$__iLineNumber=173 & ' - IniWrite(@ScriptDir &  "\runer.ini", "Levels", "LComplete2", ...•'
IniWrite(@ScriptDir &  "\runer.ini", "Levels", "LComplete2", "2")

EndFunc ;==>Button2Click

unfortunately I was not smart enough to get it to work for me. What I wanted was a Debugger that explains what each line does and why. Then I figured out that isn't happening.

Link to comment
Share on other sites

If SonoLvl2 is a script you've written, does it have a #requireadmin line in it?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

meows,

Runwait is indeed waiting as demonstrated by this code...

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***

#AutoIt3Wrapper_Add_Constants=n

Local $gui010 = GUICreate('')
Local $aSize = WinGetClientSize($gui010)
Local $Button2 = GUICtrlCreateButton('Test INI', 0, 20, $aSize[0], 50)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $Button2
            Button2Click()
    EndSwitch
WEnd


Func Button2Click() ;==>        SonoLvl2 *******************************************************
    SoundPlay(@ScriptDir & "\schoolbell.wav", 1)
    Local $Test2 = IniRead(@ScriptDir & "\runer.ini", "Levels", "LComplete1", "Default Value")
    If $Test2 = 1 Then
        ;       $updatepid =.
        ;RunWait(@ScriptDir & "\SonoLvl2\SonoLvl2_.exe", "", @SW_showdefault)
        RunWait("notepad.exe", "", @SW_SHOWDEFAULT)
        ConsoleWrite(@error & @CRLF)
    Else
        MsgBox(4096, "", "You did not complete Lesson1")
    EndIf

    IniWrite(@ScriptDir & "\runer.ini", "Levels", "LComplete2", "2")

EndFunc   ;==>Button2Click

Try adding a test of @ERROR following the RunWait...

Hope this helps,

kylomas

edit: additional info 

If @error is returning non 0 then there is a problem with finding or executing your program (as BrewmanNH suggests).

If @error is 0 then SonoLvl2.exe may be spawning another program as Jos suggests.  From the Help file...

Some programs will appear to return immediately even though they are still running; these programs spawn another process - you may be able to use the ProcessWaitClose() function to handle these cases.

 

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Oh my gosh this just keeps getting deeper and deeper.. I have the unfortunate or fortunate gift from the Lord to know a bit about a lot but not a lot about much and the more I know, the more I need to know. 2 year project oct 2011 start date.  At one time DOS4 I could make anything. even the first passenger boarding program for Bonanza airlines at McCarren Airport. Then having a few children and +8 years later I wake up and discover I was now dumb and stupid. +20 years and the world moved on. Now with forced medical retirement at 64 trying to learn things all over and WOW.

Yes #RequireAdmin is the first line. in the file.

My brain works by knowing the why and how of how of things and their works.

now not being really up to speed and finding the howto i need. i use what I can get,, I have 5 programs that are called at special times as needed. one must complete and I test that is is completed then the option to continue is presented.

SO I added more checks and Yes

What exactly does SonoLvl2_.exe do?
Does it maybe shell another program?

Jos

yes a required wrapper of my program. it runs my software with a security wrap.. SO I am told.

If SonoLvl2 is a script you've written, does it have a #requireadmin line in it?

yes first line is #requireadmin

However I am confused by the second tab in Compile and the ExecutionLevel radio buttons and what they imply. Does require Administrator mean they have to be the admin to run the program? Reason I ask is the highestavailable button that I would think is the Administrator .. either way where is the I am just a nobody wanting to run this software button?

meows,

Runwait is indeed waiting as demonstrated by this code...

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***

#AutoIt3Wrapper_Add_Constants=n

Local $gui010 = GUICreate('')
Local $aSize = WinGetClientSize($gui010)
Local $Button2 = GUICtrlCreateButton('Test INI', 0, 20, $aSize[0], 50)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $Button2
            Button2Click()
    EndSwitch
WEnd


Func Button2Click() ;==>        SonoLvl2 *******************************************************
    SoundPlay(@ScriptDir & "\schoolbell.wav", 1)
    Local $Test2 = IniRead(@ScriptDir & "\runer.ini", "Levels", "LComplete1", "Default Value")
    If $Test2 = 1 Then
        ;       $updatepid =.
        ;RunWait(@ScriptDir & "\SonoLvl2\SonoLvl2_.exe", "", @SW_showdefault)
        RunWait("notepad.exe", "", @SW_SHOWDEFAULT)
        ConsoleWrite(@error & @CRLF)
    Else
        MsgBox(4096, "", "You did not complete Lesson1")
    EndIf

    IniWrite(@ScriptDir & "\runer.ini", "Levels", "LComplete2", "2")

EndFunc   ;==>Button2Click

Try adding a test of @ERROR following the RunWait...

Hope this helps,

kylomas

edit: additional info 

If @error is returning non 0 then there is a problem with finding or executing your program (as BrewmanNH suggests).

If @error is 0 then SonoLvl2.exe may be spawning another program as Jos suggests.  From the Help file...

You are right.

I did

If @error is returning non 0 then there is a problem with finding or executing your program (as BrewmanNH suggests).

>>Non issue it finds and run the program as requested

If @error is 0 then SonoLvl2.exe may be spawning another program as Jos suggests.  From the Help file...

Yes it does spawn a additional program it is a security wrapper. And that seems to be the issue..

SO to Fix this I think the answer is to use the DATE.au3

I put in

Func Button2Click()   ;==>        SonoLvl2 *******************************************************
MsgBox($MB_SYSTEMMODAL, "", "The current working directory: " & @CRLF & @WorkingDir)   ;test check remove if compile
$newdir1=@ScriptDir & "\00\Files\core"
 FileChangeDir($newdir1)

    ; Display the working directory after setting it to the core directory.
    MsgBox($MB_SYSTEMMODAL, "", "The current working directory: " & @CRLF & @WorkingDir) ;test check remove if compile

RunWait(@ComSpec & " /c " & "filetouch.exe /d 09-09-2000 *.jpg") ; don't forget " " before "/c"
SoundPlay(@ScriptDir &  "\schoolbell.wav", 1)
Local $Test2 = IniRead(@ScriptDir &  "\runer.ini", "Levels", "LComplete1", "Default Value")
If $Test2 = 1 Then
;        $updatepid =
        ProcessWaitClose(@ScriptDir & "\SonoLvl2\SonoLvl2_.exe")
Else
    MsgBox(4096, "", "You did not complete Lesson1")

 EndIf
;MsgBox($MB_SYSTEMMODAL, "Bug Report Environment", _DebugBugReportEnv())

Call Func Timecheck()
                        ;$file1_1 = FileGetTime("C:\file1.txt", 2, 1)
    $file1_1 = FileGetTime(@ScriptDir & "\00\Files\core\2a.jpg", 2, 1)   ;program file time
    $file1_2 = FileGetTime(@ScriptDir & "2a.jpg", 2, 1)   ;placeholder time
    If $file1_1 > $file1_2 Then
        ; They Completed task Do something here
    EndIf
    If $file1_2 == $file1_1 Then 
do nothing return to program

to me this is the answer to update the ini file. touch 2 image files. one in the program root dir the other in the called program directory, when a internal program ends the images are compared, if any time is different they did indeed complete the task and we continue. Now to make it happen.

Many thanks guys. you really made this old brain work.. and I think this is the way to handle this.. as soon as i figure it out.

suggestions ? am I totally off??

Many thanks for using your time to assist,, a blessing you are..

Link to comment
Share on other sites

  • Developers
  • Solution

A script with #requireadmin will restart itself when not running with the right level credentials, meaning the first instances will end right away and shelling a new instance of the script.
Using one of these with force the original script (SonoLvl2_.au3) to start at the right level and should fix your issue:

#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
-or-
#pragma compile(ExecLevel, requireAdministrator)

Jos

ps.. I also started in the punchcard and CP/M era. :)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

A script with #requireadmin will restart itself when not running with the right level credentials, meaning the first instances will end right away and shelling a new instance of the script.

Using one of these with force the original script (SonoLvl2_.au3) to start at the right level and should fix your issue:

#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
-or-
#pragma compile(ExecLevel, requireAdministrator)

Jos

ps.. I also started in the punchcard and CP/M era. :)

Going to try this asambfh (as soon as make breakfast for husband)

RE: ps.. I also started in the punchcard and CP/M era

Pre what we call a computer now// sitting on the floor with a TV for a monitor and a tape deck to store files. wow.

Link to comment
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
 Share

×
×
  • Create New...