Sign in to follow this  
Followers 0
cherdeg

Problems with my Script

13 posts in this topic

#1 ·  Posted (edited)

Hello Alltogether,

Being a total newb when it comes to coding I'm trying to implement a utility to facilitate the post installation configuration of our testbed computers. At the moment I'm completely lost because the app exits when done with the network settings. As you will definiteley notice, I took to freedom to include many pieces of code from different posts here to use them within my tool - of course everybody else is encouraged to do so with my code (if you think it's helpful). When I'm finished I will credit every person I took code from.

The app consists of three files: the main code, an include-file defining the required functions and an .ini-file to read certain values from.

Meanwhile I could trace the problem back to the GUI-loop...:

;Run the GUI-Loop
While 1
    sleep(10)
Wend

...if the loop is disabled, the script runs through to its end, but does many things in parallel. If it is enabled, the tool stops after doing the network settings (it doesn't even display the MsgBox at the end).

While minuteley checking for answers here I made a little cleanup and even translated my originally German comments to English, so everyone here can now easily understand what it is all about. The new versions of my files are attached below - I deleted my own replies and edited this one.

Please help, I'm completely lost...

Many thanks and best Regards,

Chris

p.s.: the network part descends from "Network Changer", please look at this post: http://www.autoitscript.com/forum/index.php?showtopic=18603

PostInstall.ini.au3

PostInstall.au3

PostInstall_Func.au3

Edited by cherdeg

Share this post


Link to post
Share on other sites



Hello Alltogether,

Being a total newb when it comes to coding I'm trying to implement a utility to facilitate the post installation configuration of our testbed computers. At the moment I'm completely lost because the app exits when done with the network settings. As you will definiteley notice, I took to freedom to include many pieces of code from different posts here to use them within my tool - of course everybody else is encouraged to do so with my code (if you think it's helpful). When I'm finished I will credit every person I took code from.

The app consists of three files: the main code, an include-file defining the required functions and an .ini-file to read certain values from.

Meanwhile I could trace the problem back to the GUI-loop...:

;Run the GUI-Loop
While 1
    sleep(10)
Wend

...if the loop is disabled, the script runs through to its end, but does many things in parallel. If it is enabled, the tool stops after doing the network settings (it doesn't even display the MsgBox at the end).

While minuteley checking for answers here I made a little cleanup and even translated my originally German comments to English, so everyone here can now easily understand what it is all about. The new versions of my files are attached below - I deleted my own replies and edited this one.

Please help, I'm completely lost...

Many thanks and best Regards,

Chris

I had a very quick look and only at your main script. My only observation is that you have selected to use onevent mode. You only have one event for $GUI_EVENT_CLOSE. When the script get to the While/wend loop there is nothing more it will do, so the code which follows it is never executed. As I say, only a quick look so maybe I've misunderstood something.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

That empty endless loop doesn't make any sense to me.

You can't run parallel AutoIt code unless you run more than one script or you run other programs, which I think is what's giving you that impression of more things being done at the same time.

Looking thru your PostInstall_Func.au3 file, I see that you call the function Run sometimes, and other times you use function RunWait. There's a difference between those: Run will just start the command you pass it and the script will keep going. So, if what you start using Run doesn't immediately stop, then it will execute parallel to the script. RunWait will wait until whatever you started stop.

You could try removing that endless loop and replacing the calls you do to Run with calls to RunWait.


[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

I had a very quick look and only at your main script. My only observation is that you have selected to use onevent mode. You only have one event for $GUI_EVENT_CLOSE. When the script get to the While/wend loop there is nothing more it will do, so the code which follows it is never executed. As I say, only a quick look so maybe I've misunderstood something.

Hello Martin,

many thanks for your answer. That is exactly the thing I noticed...but how could I cope with this? All the GUI-Examples I went trough used this loop to keep the GUI running. My goal is that the script runs from start to end, fullfilling each single task after the other:

- check if the process already runs (needs to be fixed)

- check if the .ini-file exists

- get IP info by user input

- get desired Network profile by user input

- read Network info from .ini-file

- read the other infos from .ini-file

- do the other RunWait tasks

What I need, is something to make the tool wait untill all tasks triggered by clicking the Apply-Button are completed. Only then it should continue to process the rest of the tasks. Another approach would be to encapsulate the whole "networking-part" to the "_Func.au3"-file and to only call it by an "Apply-event" from the "main"-file. But how to do this? I'm really lost.

@CoePSX: The use of RunWait instead of Run isn't practicable for the following line (but I replaced the other one in the call for wuauclt.exe - thanks!):

$PID = Run(@ComSpec & " /c " & "net user", "", @SW_HIDE, $STDOUT_CHILD)

But to be honest...I don't really think that these two Runs() are responsible for making the 2nd part of the script start immediately when clicking the Apply-Button (after removing the loop).

As you all will have noticed, I'm really a bloody beginner when it comes to coding...so please supply me with some pieces of code to get my app done...that would be very great indeed.

Thank you very much,

Best Regards,

Chris

Share this post


Link to post
Share on other sites

...PLEASE...somebody of the Professionals her lend me 20 Minutes of his/her time!!! I'm sure the problem is not very complex: you will be able to solve it in not time!!!

Share this post


Link to post
Share on other sites

You don't need the loop to show the GUI. The GUISetState function is what makes the GUI appear. The loop in the example scripts is to keep it running, receiving user input.

What goes wrong if you remove the loop?


[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

I got it... you're waiting for the Apply button to be pressed...

The problem is that you're using the event model to handle the GUI... it would be easier if you used the simple loop mode... like this:

$GUI = GUICreate ( ... )

While 1
    Switch (GUIGetMsg ())
        Case $GUI_EVENT_CLOSE
            CLOSEClicked ()
        Case $ApplyButton
            _ApplyButton ()
            ExitLoop ; this will get out of the loop
    EndSwitch
WEnd

; Read further settings defined in the ini file
$s_ToolsServer = IniRead($s_ini_file, "Settings", "ToolsServer", "")
$s_ToolsShare = IniRead($s_ini_file, "Settings", "ToolsShare", "")
$s_RegFile = IniRead($s_ini_file, "Settings", "RegFile", "")
$s_ADshare = IniRead($s_ini_file, "Settings", "ADshare", "")

;; and all the rest that needs to be done

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

I got it... you're waiting for the Apply button to be pressed...

Thank you very much for your attempt. I tried to include your example, my code looks like that now:

; Configure of the GUI
Opt("GUIOnEventMode", 1)
$MainWindow = GUICreate("Netzwerk-Profile", 300, 80)

; Create the apply button
$ApplyButton = GUICtrlCreateButton("Anwenden", 190, 50, 100)
GUICtrlSetOnEvent($ApplyButton, "_ApplyButton")
Opt("GUICoordMode", 1)
GUICtrlcreateLabel("Bitte Profil auswählen: ", 10, 5)

; Read the running Settings
$s_current = IniRead($s_ini_file, "Settings", "Current", "")

; Create a list of the network-settings defined in the .ini file
$ComboBox = GUICtrlCreateCombo ($s_ini_sections[2],  10, 25, 280)
For $i = 3 To $s_ini_sections[0]
    if $i < $s_ini_sections[0] then 
        GuiCtrlSetData($ComboBox, $s_ini_sections[$i])
    else
        ; Set the running settings as Default
        GuiCtrlSetData($ComboBox, $s_ini_sections[$i], $s_current)
    endif
Next

; Show the GUI
GUISetState (@SW_SHOW)

; Your snip
While 1
    Switch (GUIGetMsg ())
        Case $GUI_EVENT_CLOSE
            CLOSEClicked ()
        Case $ApplyButton
            _ApplyButton ()
            ExitLoop ; this will get out of the loop
    EndSwitch
WEnd

; Read further settings defined in the ini file
$s_ToolsServer = IniRead($s_ini_file, "Settings", "ToolsServer", "")
$s_ToolsShare = IniRead($s_ini_file, "Settings", "ToolsShare", "")
$s_RegFile = IniRead($s_ini_file, "Settings", "RegFile", "")
$s_ADshare = IniRead($s_ini_file, "Settings", "ADshare", "")

The problem is now almost the same: that the network-part runs perfectly, but the rest of the script is not being executed. And after executing the code defined in function _ApplyButton the GUI does not exit; it even does not react to the X (close-) button.

What do I do wrong?

Regards,

Chris

Share this post


Link to post
Share on other sites

You're setting the GUIOnEventMode option to 1, so it's still in event mode.

Try not setting this option, removing this line:

Opt("GUIOnEventMode", 1)

Also, you don't need to call the GUICtrlSetOnEvent function if you're not using the event mode.


[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

You're setting the GUIOnEventMode option to 1, so it's still in event mode.

Try not setting this option, removing this line:

Opt("GUIOnEventMode", 1)

Also, you don't need to call the GUICtrlSetOnEvent function if you're not using the event mode.

YOU'RE MY MAN!!! Thank you very much!!! After tree days of kicking myself you could help me in seconds...CAN I DONATE SOEMTHING SOMEWHERE?

One little last thing: How could I make the GUI immediateley close after klicking Apply, but to still do the tasks it is supposed to?

p.s.: ...about the females...in your sig...they all like it that way, believe me...they even love it.

Edited by cherdeg

Share this post


Link to post
Share on other sites

GUIDelete ($MainWindow)

About the sig... Valik didn't say that to me, it was to someone else. I just found it funny and copied it to my sig [:)]


[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hello Alltogether,

I've got a new version of my tool (see the dl-links below, please rename the "PostInstall.ini.au3" to "PostInstall.ini"). It works flawless in XP and 2003 Server, but I still have certain problems.

1) Problems on W2K8 Server when only one NIC is in the system (a COM error?!?)

2) Function "_UserCtrlAttribs" takes ages (abou 2minutes) to set one attribute on about 10 user accounts

3) No user accounts are created on W2K8

Please do me a favour and compile the code on one of your testbed systems (e.g. VMware).

I would be very interested in your results.

Thank you very much in advance of your efforts,

Best Regards,

Chris

PostInstall.au3

Edited by cherdeg

Share this post


Link to post
Share on other sites

I really don't mean to stress you, but COULD PLEASE SOMEBODY AT LEAST TRY TO HELP ME???

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