Jump to content
Sign in to follow this  
meows

wonder why ini file written to before runwait finishes

Recommended Posts

meows

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.

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
meows

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..

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
meows

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.

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  

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I was trying to insert function header to the functions of my script, but, in the SciTE console, this appears:
      Function or struct definition not found, unable to insert header. @Jos Any suggestion?
      Thanks in advance.

      Best Regards.
    • vyperhand
      By vyperhand
      I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:
      c:\programdata\vendor\lots\of\folders\randomnumber
      This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.
      This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.
      RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel') I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.
    • Amixg
      By Amixg
      Hi! I have another problem with AutoIT.  You see, I'm still the one who's just starting out with this great programming language. I have a problem with AutoIT, it seems not to recognize the "StringReplace" function even when it is by default. The code was made half in KODA and half of my own. It is a software programmed for the Italian language (I am Italian) and translate the SMS language into Italian correct. Would you help me? Thanks in advance.
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $hull = "hello" StringReplace($hull, "hello", "hellx") $Form1 = GUICreate("Linguaggio SMS A Italiano", 507, 498, 192, 124) $Edit1 = GUICtrlCreateEdit("", 24, 40, 465, 177) GUICtrlSetData(-1, "") $Label1 = GUICtrlCreateLabel("Inserisci qui il testo che non riesci a capire:", 24, 8, 205, 17) $Label2 = GUICtrlCreateLabel("Ecco il testo tradotto(non toccare questo campo):", 27, 237, 237, 17) $Edit2 = GUICtrlCreateEdit("", 24, 264, 465, 137) GUICtrlSetData(-1, "") $Button1 = GUICtrlCreateButton("Traduci", 104, 424, 249, 49) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 StringReplace(GUICtrlGetData($Label1), "qlc", "qualcuno") StringReplace(GUICtrlGetData($Label1), "qls", "qualcosa") StringReplace(GUICtrlGetData($Label1), "ke", "che") StringReplace(GUICtrlGetData($Label1), "x", "per") StringReplace(GUICtrlGetData($Label1), "pls", "per favore") StringReplace(GUICtrlGetData($Label1), "tu6", "tu sei") StringReplace(GUICtrlGetData($Label1), "zzz", "mi fai dormire") StringReplace(GUICtrlGetData($Label1), "hagn", "Buonanotte") StringReplace(GUICtrlGetData($Label1), "tvtb", "Ti voglio tanto bene") StringReplace(GUICtrlGetData($Label1), "tat", "Ti amo tanto") StringReplace(GUICtrlGetData($Label1), "lafs", "Amore a prima vista") StringReplace(GUICtrlGetData($Label1), "fli?", "Flirtiamo?") StringReplace(GUICtrlGetData($Label1), "msidt", "Mi sono innamorato di te") StringReplace(GUICtrlGetData($Label1), "ba", "Bacio") StringReplace(GUICtrlGetData($Label1), "midi", "Mi dispiace.") StringReplace(GUICtrlGetData($Label1), "ntm", "Non ti merito") StringReplace(GUICtrlGetData($Label1), "tdp", "Togliti dai piedi.") StringReplace(GUICtrlGetData($Label1), "amò", "Amore") StringReplace(GUICtrlGetData($Label1), "ap", "A presto!") StringReplace(GUICtrlGetData($Label1), "cmq", "comunque") StringReplace(GUICtrlGetData($Label1), "cvd", "Ci vediamo dopo") StringReplace(GUICtrlGetData($Label1), "Tvb", "Ti voglio bene") StringReplace(GUICtrlGetData($Label1), "nn", "non") StringReplace(GUICtrlGetData($Label1), "risp", "rispondimi") StringReplace(GUICtrlGetData($Label1), "cel", "cellulare") StringReplace(GUICtrlGetData($Label1), "dom", "qualcosa") StringReplace(GUICtrlGetData($Label1), "nm", "numero") StringReplace(GUICtrlGetData($Label1), "fv", "favore") StringReplace(GUICtrlGetData($Label1), "-male", "meno male") StringReplace(GUICtrlGetData($Label1), "disc", "discoteca") StringReplace(GUICtrlGetData($Label1), "se#", "settimana") StringReplace(GUICtrlGetData($Label1), "+ o -", "più o meno") StringReplace(GUICtrlGetData($Label1), "ts", "torno subito") StringReplace(GUICtrlGetData($Label1), "tvtbcoa", "Ti voglio tanto bene come amica") EndSwitch WEnd  
    • Jibsbrown
      By Jibsbrown
      Need some help understanding why the ConsoleWrite works inside 2nd For loop but not out side. Between Audit Wiki, Help file , Forum searching (lots of code reading), and YouTube ( shout out to TutsTeach), I have not been able to find the reason why. 
      $sIniPath = "installLog.ini" ; - Get section name $iniSctionNames = IniReadSectionNames($sIniPath) ; - Get Keys and Vaules For $a = 1 to UBound($iniSctionNames) - 1 $keys = IniReadSection($sIniPath , $iniSctionNames[$a]) For $b = 1 to UBound($keys) - 1 $oldSysInfo = IniRead($sIniPath , $iniSctionNames[1], $keys[$b][0], "") $PntIPInfo = IniRead($sIniPath , $iniSctionNames[2], $keys[$b][0], "") $NewPCInfor = IniRead($sIniPath , $iniSctionNames[3], $keys[$b][0], "") ;ConsoleWrite($oldSysInfo & @LF) Next ;ConsoleWrite($oldSysInfo & @LF) Next ConsoleWrite($oldSysInfo) My intention is to use the variables later for Listboxes. Any explanation, forum post links or whatever would help. Sorry also very very new to Autoit.
      Also here's the ini file.
      [OldSysInfo] 4=192.168.0.4|DESKTOP-RDIU2SN|R90M05Q8 5=192.168.0.5|SD0123456789101|R9WGP9P 6=192.168.0.6|SD0123456789102|R9WGP9PT 3=192.168.0.3|DESKTOP-3RS4LKL|R9WGP9P 23=192.168.0.23|SD0123456789102|MXL1234P5I [PrinterIp] 50=192.168.0.50 48=192.168.0.48 47=192.168.0.47 [NewSysInfo] newPC = SD0123456789adfs|192.168.0.185|2UA1234FTR Thank you for your time.
    • lewisg
      By lewisg
      Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.  
       
      $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g.  ShellExecuteWait , etc.
      The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2.
      Searching here and Google has not yielded any clues that helped. 
×