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 post
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 post
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 post
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 post
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 post
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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By UE_morf_boon
      Hi!
      I have a program that has a specific function that renames the computer.
      The entire program should be executed only on behalf of the current user, because some registry keys in the HKCU are being changed.
      The current user does not have administrator rights, so #Requireadmin is not suitable as a solution.
      The administrator accounts on the computers are different, so "RunAs" is not suitable.
      Is there a way to trigger a UAC, when running a function?
      The function code, if you need:
      Func _RenamePC($Input2) Local $Name = GUICtrlRead($Input2) $objWMIService = ObjGet("winmgmts:\root\cimv2") For $objComputer In $objWMIService.InstancesOf("Win32_ComputerSystem") $oReturn = $objComputer.rename($Name) Next EndFunc  
    • By ahha
      I seem to have lost my sense of how the Global scope works.  In this example $p is Global but I can't seem to set $p in function __One and then pass that version of $p to function __Two.  I thought you could set a Global to a new value from within a function and it would affect the Global value. 
      I've stared and played with this code for over an hour and I'm missing something really basic.  Help appreciated.
      #AutoIt3Wrapper_run_debug_mode=Y ; use this to debug in console window <--- LOOK Global $p = 999 MsgBox(0, "DEBUG", "MAIN - $p = '" & $p & "'") __One() Exit Func __One() ;Global $p ;this seems to make no difference - comment it out to see - how does one affect the Global in a function? MsgBox(0, "DEBUG", "Entering Func __One() - $p = '" & $p & "'") For $p = 1 to 3 MsgBox(0, "DEBUG", "IN Func __One() - $p = '" & $p & "'") __Two() Next EndFunc Func __Two() MsgBox(0, "DEBUG", "Entering __Two() $p = '" & $p & "'") EndFunc  
    • By Iraj
      Hi Team,
      Greetings!
       
      One silly doubt, I need to pass one parameter using RunWait to write an output to a file using Cmd Line, but the below isn't writing to the file specified. Kindly assist.
      $pass = $CmdLine[1] $CMD = "C:\Progra~1\bin\Encrypt.exe" &$pass& " > C:\temp\pwd.txt" #write the parameter $pass in C:\temp\pwd.txt RunWait(@ComSpec & " /c " & $CMD,"",@SW_HIDE) Thank you!!
    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.26 contains 214 functions divided into these topics:
      window, desktop and monitor GUI, mouse and color GUI controls including graphical buttons (jpg, png) logics and mathematics include constants string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info Change log and files section  on the PAL website (SourceForge).
      A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By meety
      My au3 script program needs administrator privileges on win10 to be executed correctly, because it needs to be added to the boot---Script code:RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      I need to let the program automatically get administrator privileges, so I use a function of #RequireAdmin. Although the program can be added to the boot, but does not execute after system boot up? why is that?
      What should I do?
      --------------------------------------------------------------------
      Update:
      I found that after using the #RequireAdmin function, the program cannot be executed after system boot up.
      An example is given below. after it is compiled, it will not be executed after system boot up in the following two ways.
      1. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\
      2. RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      why is that?
      example
      #include <MsgBoxConstants.au3>
      #RequireAdmin
      Func test()
          MsgBox(0, "", "this is test message")
      EndFunc   ;==>test
      test()
       
       
×
×
  • Create New...