Jump to content

Recommended Posts

Posted (edited)

Edit: Not sure if this is an SCCM question or an AutoIt question, but I assume it's something to do with my code, which is why I'm posting it here.

I have some code that runs great outside of an SCCM task sequence, but won't work in the task sequence. This is just a snippet of the whole code because this is what's breaking the program. What I have below is a countdown that is displayed in a GUI when mouse movement is not detected. Once time has run out (when mouse is not active for 30 seconds), the code checks for the computer name that a technician has entered and if the computer name is not something to be accepted, a message box pops up telling them to enter a new name. This will happen until an acceptable name is chosen, otherwise, once time runs out, the computer name will be assigned and the program exits (function CheckName()). btnOK() is just a function for a button to be pressed and isn't really relevant to my problem, I just included it because it's relevant to the code. All of that works, but below is the code that is making it not run in the task sequence because it worked before I added this in:

If (TimerDiff($timer)>= $ms) Then
               CheckName()
            EndIf

As I said before, the code below worked in the task sequence until I added the 3 lines of code above. It works outside the TS. Can anyone help me figure this out?

Global $ms=30000
Global $lastMousePos = MouseGetPos()
Global $timer = TimerInit()

While (GUIGetMsg() <> $btnOK)
   $curMousePos = MouseGetPos()
   If ($lastMousePos[0] == $curMousePos[0] And $lastMousePos[1] == $curMousePos[1]) Then 
        If (TimerDiff($timer) < $ms) AND (GUIGetMsg() <> $btnOK) Then
            Global $seconds, $minutes, $diff, $secondsRem, $time
            $seconds = TimerDiff($timer)/1000
            $diff = $seconds - ($ms/1000)
            $minutes = Int($diff / 60)
            $secondsRem = $diff - ($minutes * 60)
            $minutes = $minutes * -1
            $secondsRem = $secondsRem * -1
            $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)
            GUICtrlSetData($Input, $time)
            If (TimerDiff($timer)>= $ms) Then
               CheckName()
            EndIf
        EndIf
   Else
      $lastMousePos = $curMousePos
      $timer = TimerInit()
   EndIf
WEnd

Func btnOK()
   CheckName()
EndFunc

Func CheckName()
   If ((StringInStr($computerName, "invalid") OR StringInStr($computerName, "minint") OR StringInStr($computerName, "desktop-") OR StringInStr($computerName, "laptop-")) <> 0) OR ($computerName == "") Then
      MsgBox($MB_SYSTEMMODAL, "Error", "Computer name '" & $computerName & "' is not accepted. Please try a different name.")
   Else
      Output()
      Exit
   EndIf
EndFunc

 

Edited by taypatte

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
×
×
  • Create New...