Jump to content

Msgbox sleep issue


Recommended Posts

Hi

I have created a program that run list of actions upon loading up into a user account each user account could have it own start up list.

I have create a sleep,n command(n= seconds to sleep) which the user and use to slow the process down if needed. I have deployed this script to over 2000 machine and all except a random 6-10 machines on of the 2000 machine behave perfectly. However 6-10 machines every night get stuck on the on the msgbox which controls the the sleep cycle. As soon as to click the ok button the script continues to process.

Has anyone expeience problem with using the sleep function built into the msgbox command?

Here my code

HotKeySet("{esc}","Endloop")

;Include some additional autoit funcutions into my script
#Include <process.au3>

;Declaring some varibles
Dim $errormessage,$admin,$x

;Read Values from ini file
$SynchTime = IniRead (@ScriptDir & "\load.ini","General","SynchTime","No")
$SynchTimeComputer = IniRead (@ScriptDir & "\load.ini","General","SynchTimeComputer","")
$WaitforTimeServer = IniRead (@ScriptDir & "\load.ini","General","WaitforTimeServer","No")
$MapADriveToComp = IniRead (@ScriptDir & "\load.ini","General","MapADriveToComp","No")
$MapPath = IniRead (@ScriptDir & "\load.ini","General","MapPath","No")
$DeleteTempDir = IniRead (@ScriptDir & "\load.ini","General","SynchTime","No")
$DeletecustomDir = IniRead (@ScriptDir & "\load.ini","General","SynchTime","No")
$DeleteCustomDirPath = IniRead (@ScriptDir & "\load.ini","General","SynchTime","")
$RunState = IniRead (@ScriptDir & "\load.ini","General","RunState","@SW_HIDE")

    IF Not FileExists (@ScriptDir & "\load.ini") THEN Exit
    IF $WaitforTimeServer = "Yes" THEN
        Do
            SplashTextOn ("","Waiting For " & $SynchTimeComputer &@CRLF&@CRLF& "Press Esc to skip",200,100,-1,-1,1,"",16)
                $p = Ping ($SynchTimeComputer)
                    IF $X = 1 THEN Exitloop
        Until $p > "0"
            SplashOff()
    ENDIF
    HotKeySet("{esc}")

    IF $MapADriveToComp = "Yes" THEN
        SplashTextOn ("","Mapping drive" ,200,100,-1,-1,1,"",16)
            Run ($MapPath,"",@SW_HIDE)
    ENDIF
        Splashoff()

    IF $SynchTime = "Yes" THEN _Rundos ("net time \\" & $SynchTimeComputer & " /set /y")
    IF $DeleteTempDir = "Yes" THEN FileDelete ("c:\temp\*.*")
    IF $DeletecustomDir = "Yes" THEN FileDelete ($DeleteCustomDirPath)

    $DoOnce = IniReadSection (@ScriptDir & "\load.ini","DoOnce")
        
    IF $DoOnce = 1 Then
        Action(@UserName)
        Exit
    Else
        Action("DoOnce")
        IniDelete (@ScriptDir & "\load.ini","DoOnce")
        Exit
    EndIf
    
Func Action($Section)

    $user = IniReadSection (@ScriptDir & "\load.ini",$Section)
    
    IF @error=1 THEN Exit
        For $n = 1 to $user [0] [0]
            $z = $user [$n] [1]
            $s = StringSplit ($z,",")
                IF $s[1] = "sleep" THEN
                    msgbox (64,"Pausing for "& $s[2] & " seconds","Click OK to abort the pause",$s[2])
                ELSEIF $s[1] == "<ChangeName>" THEN
                    ChangeName($s[2])
                ELSEIF StringInStr($z,"Chkdsk") THEN
                    Run (@ComSpec & " /c " & $z,"",$RunState)
                ELSEIF $z == "<Reboot>" THEN
                    IniDelete (@ScriptDir & "\load.ini","DoOnce")
                    Shutdown(2)
                Else
                    Run ($z,"",$RunState)
                    IF @error THEN $errormessage = MsgBox(54,"Error unable to run command", "Unable to run " & $s[1])
                    IF $errormessage = 2 THEN EXIT
                    IF $errormessage = 10 THEN $n = $n -1 
                Endif
        Next
ENDFUNC

Func ChangeName($ComputerName)
    
    IF $ComputerName == "*" Then $ComputerName = "TmpName" & Random (00000000,99999999,1)

    SplashTextOn ( "", ".....Please Wait..... Changing ComputerName",@DesktopWidth,140,-1,@DesktopHeight-140,1,"",18)
        Sleep(2000)     
            $strComputer = "."
            $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
            $colComputers = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
                For $objComputer in $colComputers
                    $ObjComputer.Rename($ComputerName)
                Next
    SplashOff()
Endfunc


Func Endloop()
    $x = 1
ENDFUNC
Link to comment
Share on other sites

  • Moderators

vickerps,

My instant thought is that the $s[2] value you use to set the timeout is coming up as 0, which will give you a MsgBox which waits for a click. If it were undefined you would get the same result.

Try adding a check to the code to see if that is the case - and if so, then set the value to something reasonable.

Top Tip: It is always a good idea to check that you have valid values after a StringSplit. :)

I hope that helps. :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...