Jump to content
Sign in to follow this  
dmkirkland

Same command; different outcomes

Recommended Posts

dmkirkland

Wondering if someone might know why, with the below code, when the first function is run (looking particularly at the middle part of the function with the ShellExecuteWait), msinfo32 (which runs fine from a Run box) pops up as the main window disappears. The main window reappears once msinfo32 closes, as expected. When the "control system" command is executed, however (which again, runs fine from Run box), the new window appears when the main window disappears but, the main window pops back open again (in the background). It's baffling me. The only reason I can think of is that "control system" is really a command with an argument and that Windows application is actually a "subset" of sorts (or appears to be) of the explorer.exe program in Windows. So, if I'm right, maybe, in addition to confirmation, someone might know how to make the main window actually hide until the "control system" application closes?

 

Func systemInformation()

    WinSetState ($mainWindow, "", @SW_HIDE)

    ShellExecuteWait ("msinfo32")

    WinSetState ($mainWindow, "", @SW_SHOW)

EndFunc


Func runSystemProperties()

    WinSetState ($mainWindow, "", @SW_HIDE)

    ShellExecuteWait ("control", " system")

    WinSetState ($mainWindow, "", @SW_SHOW)

EndFunc

 

Share this post


Link to post
Share on other sites
Malkey

It appears the  ShellExecuteWait () function isn't waiting for the Control Panel windows to close. 
The AutoIt help file for the ShellExecuteWait () function says "Runs an external program". 
Maybe the Control Panel commands, or applets, are internal type programs. Therefore, the  ShellExecuteWait () function executes the commands but does not wait for the command's window to close.  If it actually is the command's window that opens. 
I really don't know why ShellExecuteWait ()  isn't waiting on "control".

Here is a work around.

Run("notepad.exe")
Global $mainWindow = WinWait("[CLASS:Notepad]", "")

Sleep(1000)
_SystemInformation()
Sleep(1000)

_RunSystemProperties()
Sleep(3000)
WinClose($mainWindow)


Func _SystemInformation()
    WinSetState($mainWindow, "", @SW_HIDE)
    ShellExecuteWait("msinfo32")
    WinSetState($mainWindow, "", @SW_SHOW)
EndFunc   ;==>_SystemInformation


Func _RunSystemProperties()
    WinSetState($mainWindow, "", @SW_HIDE)
    ;ShellExecuteWait("control"); , "system") ;,"","open")
    Run("control.exe system") ;,"","open") ;, @SW_SHOW)
    $CtrlWindow = WinWait("[CLASS:CabinetWClass]", "")
    WinWaitNotActive($CtrlWindow)
    ;WinSetOnTop($mainWindow, "", 1) ;  $WINDOWS_ONTOP (1) = set on top flag
    WinSetState($mainWindow, "", @SW_SHOW)
EndFunc   ;==>_RunSystemProperties

 

Share this post


Link to post
Share on other sites
BrewManNH

Because the Control command starts a second process and then closes.


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
dmkirkland

I know it's been a while. I've been on TDY in Germany. @BrewManNH, I'm wondering, now that I understand from your post what is happening (and suspected as much but wasn't sure), are you aware of a way to somehow "tag" or "assign" the "subprocess" of " system" a variable or something that I can cause the script to wait for? I'm assuming if I do something akin to 

$window = ShellExecuteWait("control", " system")

that the variable will get assigned to the "control" execution, not the subprocess " system"?

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  

×