Sign in to follow this  
Followers 0
r4b1dm0nk3y

Errors Running script and Compiling Code

6 posts in this topic

I am encountering errors when trying to run or compiling my code. The code is a mix of different examples I've found on the forums and modified to my needs. Generally I think the piece the is giving me trouble is the Switch @OSArch and following Case statements. Its not the most efficient code set to achieve my goals, but I'm learning.

Code:

;### change log --- Version 3.1 ###
    ;added Func _x86 and Func _x64 for the @OSArch to try to solve run issues
    ;added ;==> at end ofeach function
;### change log --- Version 3.0 ###
    ;added sections:
        ; ---- declare $service_# variables ----
        ; ---- declare $pid_# (Process) variables ----
        ; ---- declare Global $data_# variables ----
        ;check status of $service_0 and if running stop the service
        ;check status of $service_1 and if running stop the service
        ;check status of $service_2 and if running stop the service
        ;check status of $service_3 and if running stop the service
        ;check status of $service_4 and if running stop the service
        ;check status of $service_5 and if running stop the service
;### change log --- Version 2.0 ###
    ;added @OSArch to detect if OS is x86 or x64
    ;split out code for x86 and x64 OS'
;### change log --- Version 1.0 ###
;base code development
;--------end chagne log--------
; ---- Unregister Device with the Zone && Clear ZENworks Cache ----
; Unregister the device from the Zone and Clear ZENworks cache via command line
RunWait(@COMSPEC & ' /c "echo Unregistering Device and Clearing Unique Workstation Information && zac fsg -d && echo --------------- && echo Clearing ZENworks Agent Cache && zac cc && echo --------------- && echo *Please check for that the previous commands succeeded before continuing!* && echo If there is an error above exit this script by closing the window, do not press any keys! && echo . && pause"')

; ---- Declare $service_# variables ----
; Create variables for each service you want to run functions on. ZENworks services needed to be stopped are:
; Novell Identity Store, XTSvcMgr, Novell ZENworks Agent Service, Novell ZENworks Image-Safe Data Service, ZENPreAgent, nzwinvnc
$service_0 = "Novell Identity Store"
$service_1 = "XTSvcMgr"
$service_2 = "Novell ZENworks Agent Service"
$service_3 = "Novell ZENworks Image-Safe Data Service'"
$service_4 = "ZENPreAgent"
$service_5 = "nzwinvnc"

; ---- Declare $pid_# (Process) variables ----
; Create variables for the function to check the services status.
; Each service gets its own $pid_# variable. The $pid_# var is excuted in the function which runs the query string below
$pid_0 = Run('sc query "' & $service_0 & '"', '', @SW_HIDE, 2)
$pid_1 = Run('sc query "' & $service_1 & '"', '', @SW_HIDE, 2)
$pid_2 = Run('sc query "' & $service_2 & '"', '', @SW_HIDE, 2)
$pid_3 = Run('sc query "' & $service_3 & '"', '', @SW_HIDE, 2)
$pid_4 = Run('sc query "' & $service_4 & '"', '', @SW_HIDE, 2)
$pid_5 = Run('sc query "' & $service_5 & '"', '', @SW_HIDE, 2)

; ---- Declare Global $data_# variables ----
; Create variables for the function to check the services status.
; Each function gets its own $data_# variable. The $data_# var is excuted in the function which finds the state of the $service_#
Global $data_0
Global $data_1
Global $data_2
Global $data_3
Global $data_4
Global $data_5

;Check status of $service_0 and if running stop the service
Do
    $data_0 &= StdOutRead($pid_0)
Until @error

$data_0 = StringSplit($data_0, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_0[0]
        ; Strip all whitespace
        $data_0[$i] = StringStripWS($data_0[$i], 8)
        If $data_0[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_0[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_0[$i] = StringTrimLeft(StringReplace($data_0[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_0[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_0 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_0[$i])
        EndIf
    Next
EndIf

;Check status of $service_1 and if running stop the service
Do
    $data_1 &= StdOutRead($pid_1)
Until @error

$data_1 = StringSplit($data_1, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_1[0]
        ; Strip all whitespace
        $data_1[$i] = StringStripWS($data_1[$i], 8)
        If $data_1[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_1[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_1[$i] = StringTrimLeft(StringReplace($data_1[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_1[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_1 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_1[$i])
        EndIf
    Next
EndIf

;Check status of $service_2 and if running stop the service
Do
    $data_2 &= StdOutRead($pid_2)
Until @error

$data_2 = StringSplit($data_2, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_2[0]
        ; Strip all whitespace
        $data_2[$i] = StringStripWS($data_2[$i], 8)
        If $data_2[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_2[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_2[$i] = StringTrimLeft(StringReplace($data_2[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_2[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_2 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_2[$i])
        EndIf
    Next
EndIf

;Check status of $service_3 and if running stop the service
Do
    $data_3 &= StdOutRead($pid_3)
Until @error

$data_3 = StringSplit($data_3, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_3[0]
        ; Strip all whitespace
        $data_3[$i] = StringStripWS($data_3[$i], 8)
        If $data_3[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_3[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_3[$i] = StringTrimLeft(StringReplace($data_3[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_3[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_3 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_3[$i])
        EndIf
    Next
EndIf

;Check status of $service_4 and if running stop the service
Do
    $data_4 &= StdOutRead($pid_4)
Until @error

$data_4 = StringSplit($data_4, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_4[0]
        ; Strip all whitespace
        $data_4[$i] = StringStripWS($data_4[$i], 8)
        If $data_4[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_4[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_4[$i] = StringTrimLeft(StringReplace($data_4[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_4[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_4 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_4[$i])
        EndIf
    Next
EndIf

;Check status of $service_5 and if running stop the service
Do
    $data_5 &= StdOutRead($pid_5)
Until @error

$data_5 = StringSplit($data_5, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_5[0]
        ; Strip all whitespace
        $data_5[$i] = StringStripWS($data_5[$i], 8)
        If $data_5[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_5[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_5[$i] = StringTrimLeft(StringReplace($data_5[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_5[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_5 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_5[$i])
        EndIf
    Next
EndIf

; ---- Detect System OS Architecture ----
; This section check if the OS is running x86 or x64 bit Windows. If the machine detect x86 or x64 OS it will execute
; commands for that Windows version. x86 will execute programs from C:\Program Files\ and x64 will execute
; programs from C:\Program Files (x86)\.
Switch @OSArch
    Case "x86"
          ; Do stuff for x86
        Func _x86()
            ; ---- Delete Image Safe Data ----
            ; This section will run ZISWIN.EXE to delete the Image Safe Data via program
            ; execution then using keyboard (ALT + <key>) or mouse clicks via cooridnates on the screen
            #region ---Au3Recorder generated code Start ---
            Opt("WinWaitDelay",100)
            Opt("WinDetectHiddenText",1)
            Opt("MouseCoordMode",0)


            Run('C:\Program Files\Novell\ZENworks\bin\preboot\ZISWIN.EXE')
            _WinWaitActivate("ZENworks Imaging Windows Agent","")
            Send("{ALTDOWN}ei{ALTUP}{ALTDOWN}fs{ALTUP}{ALTDOWN}fe{ALTUP}")
            ;--- commented out mouse clicks. alternate method of executing commands ---
            ;Run('C:\Program Files (x86)\Novell\ZENworks\bin\preboot\ZISWIN.EXE')
            ;_WinWaitActivate("ZENworks Imaging Windows Agent","The imaging agent is")
            ;MouseClick("left",58,40,1)
            ;MouseClick("left",91,87,1)
            ;_WinWaitActivate("ZENworks Imaging Windows Agent","Image-safe data (mod")
            ;MouseClick("left",28,38,1)
            ;MouseClick("left",65,83,1)
            ;_WinWaitActivate("ZENworks Imaging Windows Agent","The imaging agent is")
            ;MouseClick("left",21,39,1)
            ;MouseClick("left",54,167,1)

            #region --- Internal functions Au3Recorder Start ---
            Func _WinWaitActivate($title,$text,$timeout=0)
                WinWait($title,$text,$timeout)
                If Not WinActive($title,$text) Then WinActivate($title,$text)
                WinWaitActive($title,$text,$timeout)
            EndFunc ;==>_WinWaitActivate
            #endregion --- Internal functions Au3Recorder End ---

            #endregion --- Au3Recorder generated code End ---

            ;---- Delete Files ----
            ; The below commands will delete the files with unique identifying information
            If FileExists('C:\Program Files\Novell\ZENworks\conf\devicedata') Then FileDelete('C:\Program Files\Novell\ZENworks\conf\devicedata')
            If FileExists('C:\Program Files\Novell\ZENworks\conf\deviceguid') Then FileDelete('C:\Program Files\Novell\ZENworks\conf\deviceguid')
            If FileExists('C:\Program Files\Novell\ZENworks\conf\Guid.txt ') Then FileDelete('C:\Program Files\Novell\ZENworks\conf\Guid.txt ')
            If FileExists('C:\Program Files\Novell\ZENworks\conf\*.sav') Then FileDelete('C:\Program Files\Novell\ZENworks\conf\*.sav')

            ; ---- Rename File----
            ; Rename %programfiles%\Novell\Zenworks\conf\initial-web-service.bak to %programfiles%\Novell\Zenworks\conf\initial-web-service
            $sFileOld = "C:\Program Files\Novell\Zenworks\conf\initial-web-service.bak"
            $sFileRenamed = "C:\Program Files\Novell\Zenworks\conf\initial-web-service"
            FileMove($sFileOld, $sFileRenamed)

            Func _DirRemoveContents($folder)
                $folder = "C:\Program Files\Novell\Zenworks\cache\zmd\"
                Local $search, $file
                If StringRight($folder, 1) <> "\" Then $folder = $folder & "\"
                If NOT FileExists($folder) Then Return 0
                FileSetAttrib($folder & "*","-RSH")
                FileDelete($folder & "*.*")
                $search = FileFindFirstFile($folder & "*")
                If $search = -1 Then Return 0
                While 1
                    $file = FileFindNextFile($search)
                    If @error Then ExitLoop
                    If StringRight($file, 1) = "." Then ContinueLoop
                    DirRemove($folder & $file, 1)
                WEnd
                Return FileClose($search)
            EndFunc ;==>_DirRemoveContents
        EndFunc ;==>_x86

    Case "x64"
          ; Do stuff for x64
        Func _x64()
            ; ---- Delete Image Safe Data ----
            ; This section will run ZISWIN.EXE to delete the Image Safe Data via program
            ; execution then using keyboard (ALT + <key>) or mouse clicks via cooridnates on the screen
            #region ---Au3Recorder generated code Start ---
            Opt("WinWaitDelay",100)
            Opt("WinDetectHiddenText",1)
            Opt("MouseCoordMode",0)


            Run('C:\Program Files (x86)\Novell\ZENworks\bin\preboot\ZISWIN.EXE')
            _WinWaitActivate("ZENworks Imaging Windows Agent","")
            Send("{ALTDOWN}ei{ALTUP}{ALTDOWN}fs{ALTUP}{ALTDOWN}fe{ALTUP}")
            ;--- commented out mouse clicks. alternate method of executing commands ---
            ;Run('C:\Program Files (x86)\Novell\ZENworks\bin\preboot\ZISWIN.EXE')
            ;_WinWaitActivate("ZENworks Imaging Windows Agent","The imaging agent is")
                ;MouseClick("left",58,40,1)
            ;MouseClick("left",91,87,1)
            ;_WinWaitActivate("ZENworks Imaging Windows Agent","Image-safe data (mod")
            ;MouseClick("left",28,38,1)
            ;MouseClick("left",65,83,1)
            ;_WinWaitActivate("ZENworks Imaging Windows Agent","The imaging agent is")
            ;MouseClick("left",21,39,1)
            ;MouseClick("left",54,167,1)

            #region --- Internal functions Au3Recorder Start ---
            Func _WinWaitActivate($title,$text,$timeout=0)
                WinWait($title,$text,$timeout)
                If Not WinActive($title,$text) Then WinActivate($title,$text)
                WinWaitActive($title,$text,$timeout)
            EndFunc ;==>_WinWaitActivate
            #endregion --- Internal functions Au3Recorder End ---

            #endregion --- Au3Recorder generated code End ---

            ;---- Delete Files ----
            ; The below commands will delete the files with unique identifying information
            If FileExists('C:\Program Files (x86)\Novell\ZENworks\conf\devicedata') Then FileDelete('C:\Program Files (x86)\Novell\ZENworks\conf\devicedata')
            If FileExists('C:\Program Files (x86)\Novell\ZENworks\conf\deviceguid') Then FileDelete('C:\Program Files (x86)\Novell\ZENworks\conf\deviceguid')
            If FileExists('C:\Program Files (x86)\Novell\ZENworks\conf\Guid.txt ') Then FileDelete('C:\Program Files (x86)\Novell\ZENworks\conf\Guid.txt ')
            If FileExists('C:\Program Files (x86)\Novell\ZENworks\conf\*.sav') Then FileDelete('C:\Program Files (x86)\Novell\ZENworks\conf\*.sav')

            ; ---- Rename File----
            ; Rename %programfiles%\Novell\Zenworks\conf\initial-web-service.bak to %programfiles%\Novell\Zenworks\conf\initial-web-service
            $sFileOld = "C:\Program Files (x86)\Novell\Zenworks\conf\initial-web-service.bak"
            $sFileRenamed = "C:\Program Files (x86)\Novell\Zenworks\conf\initial-web-service"
            FileMove($sFileOld, $sFileRenamed)

            Func _DirRemoveContents($folder)
                $folder = "C:\Program Files (x86)\Novell\Zenworks\cache\zmd\"
                Local $search, $file
                If StringRight($folder, 1) <> "\" Then $folder = $folder & "\"
                If NOT FileExists($folder) Then Return 0
                FileSetAttrib($folder & "*","-RSH")
                FileDelete($folder & "*.*")
                $search = FileFindFirstFile($folder & "*")
                If $search = -1 Then Return 0
                While 1
                    $file = FileFindNextFile($search)
                    If @error Then ExitLoop
                    If StringRight($file, 1) = "." Then ContinueLoop
                    DirRemove($folder & $file, 1)
                WEnd
                Return FileClose($search)
            EndFunc ;==>_DirRemoveContents
        EndFunc ;==>_x64

    Case Else
          MsgBox(16, "Error", "Unhandled case: CPU architecture not recognized."& @CRLF& "Please seek assitance cleaning up ZENworks!")
          Exit
EndSwitch

If I try to run the script it tells me:

Line 234 (File "<script_location>\zen_agent_cleanup_v3.1.au3") :

Func _x86()

Error: Switch" statement is missing "EndSwitch" or"Case" statement.

I would imagine this would also be true for my _x64 function as well.

Obviously if the script can run then it won't compile, but maybe this will help in troubleshooting.

When I try to compile the script I get these errors:

<script_location>\zen_agent_cleanup_v3.1.au3(234,3) : ERROR: missing EndSwitch.

Func

^

<script_location>\zen_agent_cleanup_v3.1.au3(231,15) : REF: missing EndSwitch.

Switch @OSArch

~~~~~~~~~~~~~~^

<script_location>\zen_agent_cleanup_v3.1.au3(260,4) : ERROR: syntax error

Func

^

<script_location>\zen_agent_cleanup_v3.1.au3(245,56) : ERROR: _WinWaitActivate(): undefined function.

_WinWaitActivate("ZENworks Imaging Windows Agent","")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

<script_location>\zen_agent_cleanup_v3.1.au3 - 3 error(s), 0 warning(s)

I'm not really sure what is going on here. All of the syntax looks correct to me. Anyone have an idea?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is how a Switch...EndSwitch should look like...

Global $iCase = 1

Switch $iCase
    Case 1
        ; Something
        
    Case 2
        ; Something
        
    Case Else
        ; Something

EndSwitch

Basically the syntax you have used isn't correct and its bad coding. Double click on the error to take you to the line and correct as per the instructions.

Also look at how to create Functions correctly search Func...Return...EndFunc in the Help File.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Fixed AU3Check Errors. But please take some time to read the Help File as problems like these shouldn't really occur with the proper knowledge.

;### change log --- Version 3.1 ###
;added Func _x86 and Func _x64 for the @OSArch to try to solve run issues
;added ;==> at end ofeach function
;### change log --- Version 3.0 ###
;added sections:
; ---- declare $service_# variables ----
; ---- declare $pid_# (Process) variables ----
; ---- declare Global $data_# variables ----
;check status of $service_0 and if running stop the service
;check status of $service_1 and if running stop the service
;check status of $service_2 and if running stop the service
;check status of $service_3 and if running stop the service
;check status of $service_4 and if running stop the service
;check status of $service_5 and if running stop the service
;### change log --- Version 2.0 ###
;added @OSArch to detect if OS is x86 or x64
;split out code for x86 and x64 OS'
;### change log --- Version 1.0 ###
;base code development
;--------end chagne log--------
; ---- Unregister Device with the Zone && Clear ZENworks Cache ----
; Unregister the device from the Zone and Clear ZENworks cache via command line
RunWait(@ComSpec & ' /c "echo Unregistering Device and Clearing Unique Workstation Information && zac fsg -d && echo --------------- && echo Clearing ZENworks Agent Cache && zac cc && echo --------------- && echo *Please check for that the previous commands succeeded before continuing!* && echo If there is an error above exit this script by closing the window, do not press any keys! && echo . && pause"')

; ---- Declare $service_# variables ----
; Create variables for each service you want to run functions on. ZENworks services needed to be stopped are:
; Novell Identity Store, XTSvcMgr, Novell ZENworks Agent Service, Novell ZENworks Image-Safe Data Service, ZENPreAgent, nzwinvnc
$service_0 = "Novell Identity Store"
$service_1 = "XTSvcMgr"
$service_2 = "Novell ZENworks Agent Service"
$service_3 = "Novell ZENworks Image-Safe Data Service'"
$service_4 = "ZENPreAgent"
$service_5 = "nzwinvnc"

; ---- Declare $pid_# (Process) variables ----
; Create variables for the function to check the services status.
; Each service gets its own $pid_# variable. The $pid_# var is excuted in the function which runs the query string below
$pid_0 = Run('sc query "' & $service_0 & '"', '', @SW_HIDE, 2)
$pid_1 = Run('sc query "' & $service_1 & '"', '', @SW_HIDE, 2)
$pid_2 = Run('sc query "' & $service_2 & '"', '', @SW_HIDE, 2)
$pid_3 = Run('sc query "' & $service_3 & '"', '', @SW_HIDE, 2)
$pid_4 = Run('sc query "' & $service_4 & '"', '', @SW_HIDE, 2)
$pid_5 = Run('sc query "' & $service_5 & '"', '', @SW_HIDE, 2)

; ---- Declare Global $data_# variables ----
; Create variables for the function to check the services status.
; Each function gets its own $data_# variable. The $data_# var is excuted in the function which finds the state of the $service_#
Global $data_0
Global $data_1
Global $data_2
Global $data_3
Global $data_4
Global $data_5

;Check status of $service_0 and if running stop the service
Do
    $data_0 &= StdoutRead($pid_0)
Until @error

$data_0 = StringSplit($data_0, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_0[0]
        ; Strip all whitespace
        $data_0[$i] = StringStripWS($data_0[$i], 8)
        If $data_0[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_0[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_0[$i] = StringTrimLeft(StringReplace($data_0[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_0[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_0 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_0[$i])
        EndIf
    Next
EndIf

;Check status of $service_1 and if running stop the service
Do
    $data_1 &= StdoutRead($pid_1)
Until @error

$data_1 = StringSplit($data_1, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_1[0]
        ; Strip all whitespace
        $data_1[$i] = StringStripWS($data_1[$i], 8)
        If $data_1[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_1[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_1[$i] = StringTrimLeft(StringReplace($data_1[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_1[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_1 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_1[$i])
        EndIf
    Next
EndIf

;Check status of $service_2 and if running stop the service
Do
    $data_2 &= StdoutRead($pid_2)
Until @error

$data_2 = StringSplit($data_2, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_2[0]
        ; Strip all whitespace
        $data_2[$i] = StringStripWS($data_2[$i], 8)
        If $data_2[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_2[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_2[$i] = StringTrimLeft(StringReplace($data_2[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_2[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_2 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_2[$i])
        EndIf
    Next
EndIf

;Check status of $service_3 and if running stop the service
Do
    $data_3 &= StdoutRead($pid_3)
Until @error

$data_3 = StringSplit($data_3, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_3[0]
        ; Strip all whitespace
        $data_3[$i] = StringStripWS($data_3[$i], 8)
        If $data_3[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_3[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_3[$i] = StringTrimLeft(StringReplace($data_3[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_3[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_3 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_3[$i])
        EndIf
    Next
EndIf

;Check status of $service_4 and if running stop the service
Do
    $data_4 &= StdoutRead($pid_4)
Until @error

$data_4 = StringSplit($data_4, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_4[0]
        ; Strip all whitespace
        $data_4[$i] = StringStripWS($data_4[$i], 8)
        If $data_4[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_4[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_4[$i] = StringTrimLeft(StringReplace($data_4[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_4[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_4 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_4[$i])
        EndIf
    Next
EndIf

;Check status of $service_5 and if running stop the service
Do
    $data_5 &= StdoutRead($pid_5)
Until @error

$data_5 = StringSplit($data_5, @CRLF, 1)
If Not @error Then
    For $i = 1 To $data_5[0]
        ; Strip all whitespace
        $data_5[$i] = StringStripWS($data_5[$i], 8)
        If $data_5[$i] = '' Then
            ; Skip empty lines
            ContinueLoop
        ElseIf StringLeft($data_5[$i], 5) <> 'STATE' Then
            ; Skip lines that include no state
            ContinueLoop
        Else
            ; Remove "STATE:" and trim integer code
            $data_5[$i] = StringTrimLeft(StringReplace($data_5[$i], 'STATE:', ''), 1)
        EndIf
        ; Show compare to RUNNING and show result if True
        If $data_5[$i] = 'RUNNING' Then
            Run('sc stop "' & $service_5 & '"', '', @SW_HIDE, 2)
            ;MsgBox(0, '', $data_5[$i])
        EndIf
    Next
EndIf

; ---- Detect System OS Architecture ----
; This section check if the OS is running x86 or x64 bit Windows. If the machine detect x86 or x64 OS it will execute
; commands for that Windows version. x86 will execute programs from C:\Program Files\ and x64 will execute
; programs from C:\Program Files (x86)\.
Switch @OSArch
    Case "x86"
        ; Do stuff for x86
        _x86()

    Case "x64"
        ; Do stuff for x64
        _x64()

    Case Else
        MsgBox(16, "Error", "Unhandled case: CPU architecture not recognized." & @CRLF & "Please seek assitance cleaning up ZENworks!")
        Exit
EndSwitch

Func _x86()
    ; ---- Delete Image Safe Data ----
    ; This section will run ZISWIN.EXE to delete the Image Safe Data via program
    ; execution then using keyboard (ALT + <key>) or mouse clicks via cooridnates on the screen
    #Region ---Au3Recorder generated code Start ---
    Opt("WinWaitDelay", 100)
    Opt("WinDetectHiddenText", 1)
    Opt("MouseCoordMode", 0)


    Run('C:\Program Files\Novell\ZENworks\bin\preboot\ZISWIN.EXE')
    _WinWaitActivate("ZENworks Imaging Windows Agent", "")
    Send("{ALTDOWN}ei{ALTUP}{ALTDOWN}fs{ALTUP}{ALTDOWN}fe{ALTUP}")
    ;--- commented out mouse clicks. alternate method of executing commands ---
    ;Run('C:\Program Files (x86)\Novell\ZENworks\bin\preboot\ZISWIN.EXE')
    ;_WinWaitActivate("ZENworks Imaging Windows Agent","The imaging agent is")
    ;MouseClick("left",58,40,1)
    ;MouseClick("left",91,87,1)
    ;_WinWaitActivate("ZENworks Imaging Windows Agent","Image-safe data (mod")
    ;MouseClick("left",28,38,1)
    ;MouseClick("left",65,83,1)
    ;_WinWaitActivate("ZENworks Imaging Windows Agent","The imaging agent is")
    ;MouseClick("left",21,39,1)
    ;MouseClick("left",54,167,1)

    #Region --- Internal functions Au3Recorder Start ---
    #EndRegion --- Internal functions Au3Recorder Start ---

    #EndRegion ---Au3Recorder generated code Start ---

    ;---- Delete Files ----
    ; The below commands will delete the files with unique identifying information
    If FileExists('C:\Program Files\Novell\ZENworks\conf\devicedata') Then FileDelete('C:\Program Files\Novell\ZENworks\conf\devicedata')
    If FileExists('C:\Program Files\Novell\ZENworks\conf\deviceguid') Then FileDelete('C:\Program Files\Novell\ZENworks\conf\deviceguid')
    If FileExists('C:\Program Files\Novell\ZENworks\conf\Guid.txt ') Then FileDelete('C:\Program Files\Novell\ZENworks\conf\Guid.txt ')
    If FileExists('C:\Program Files\Novell\ZENworks\conf\*.sav') Then FileDelete('C:\Program Files\Novell\ZENworks\conf\*.sav')

    ; ---- Rename File----
    ; Rename %programfiles%\Novell\Zenworks\conf\initial-web-service.bak to %programfiles%\Novell\Zenworks\conf\initial-web-service
    $sFileOld = "C:\Program Files\Novell\Zenworks\conf\initial-web-service.bak"
    $sFileRenamed = "C:\Program Files\Novell\Zenworks\conf\initial-web-service"
    FileMove($sFileOld, $sFileRenamed)
EndFunc   ;==>_x86

Func _x64()
    ; ---- Delete Image Safe Data ----
    ; This section will run ZISWIN.EXE to delete the Image Safe Data via program
    ; execution then using keyboard (ALT + <key>) or mouse clicks via cooridnates on the screen
    #Region ---Au3Recorder generated code Start ---
    Opt("WinWaitDelay", 100)
    Opt("WinDetectHiddenText", 1)
    Opt("MouseCoordMode", 0)


    Run('C:\Program Files (x86)\Novell\ZENworks\bin\preboot\ZISWIN.EXE')
    _WinWaitActivate("ZENworks Imaging Windows Agent", "")
    Send("{ALTDOWN}ei{ALTUP}{ALTDOWN}fs{ALTUP}{ALTDOWN}fe{ALTUP}")
    ;--- commented out mouse clicks. alternate method of executing commands ---
    ;Run('C:\Program Files (x86)\Novell\ZENworks\bin\preboot\ZISWIN.EXE')
    ;_WinWaitActivate("ZENworks Imaging Windows Agent","The imaging agent is")
    ;MouseClick("left",58,40,1)
    ;MouseClick("left",91,87,1)
    ;_WinWaitActivate("ZENworks Imaging Windows Agent","Image-safe data (mod")
    ;MouseClick("left",28,38,1)
    ;MouseClick("left",65,83,1)
    ;_WinWaitActivate("ZENworks Imaging Windows Agent","The imaging agent is")
    ;MouseClick("left",21,39,1)
    ;MouseClick("left",54,167,1)

    #Region --- Internal functions Au3Recorder Start ---

    #EndRegion --- Internal functions Au3Recorder Start ---

    #EndRegion ---Au3Recorder generated code Start ---

    ;---- Delete Files ----
    ; The below commands will delete the files with unique identifying information
    If FileExists('C:\Program Files (x86)\Novell\ZENworks\conf\devicedata') Then FileDelete('C:\Program Files (x86)\Novell\ZENworks\conf\devicedata')
    If FileExists('C:\Program Files (x86)\Novell\ZENworks\conf\deviceguid') Then FileDelete('C:\Program Files (x86)\Novell\ZENworks\conf\deviceguid')
    If FileExists('C:\Program Files (x86)\Novell\ZENworks\conf\Guid.txt ') Then FileDelete('C:\Program Files (x86)\Novell\ZENworks\conf\Guid.txt ')
    If FileExists('C:\Program Files (x86)\Novell\ZENworks\conf\*.sav') Then FileDelete('C:\Program Files (x86)\Novell\ZENworks\conf\*.sav')

    ; ---- Rename File----
    ; Rename %programfiles%\Novell\Zenworks\conf\initial-web-service.bak to %programfiles%\Novell\Zenworks\conf\initial-web-service
    $sFileOld = "C:\Program Files (x86)\Novell\Zenworks\conf\initial-web-service.bak"
    $sFileRenamed = "C:\Program Files (x86)\Novell\Zenworks\conf\initial-web-service"
    FileMove($sFileOld, $sFileRenamed)
EndFunc   ;==>_x64

Func _DirRemoveContents($folder)
    $folder = "C:\Program Files\Novell\Zenworks\cache\zmd\"
    Local $search, $file
    If StringRight($folder, 1) <> "\" Then $folder = $folder & "\"
    If Not FileExists($folder) Then Return 0
    FileSetAttrib($folder & "*", "-RSH")
    FileDelete($folder & "*.*")
    $search = FileFindFirstFile($folder & "*")
    If $search = -1 Then Return 0
    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        If StringRight($file, 1) = "." Then ContinueLoop
        DirRemove($folder & $file, 1)
    WEnd
    Return FileClose($search)
EndFunc   ;==>_DirRemoveContents

Func _WinWaitActivate($title, $text, $timeout = 0)
    WinWait($title, $text, $timeout)
    If Not WinActive($title, $text) Then WinActivate($title, $text)
    WinWaitActive($title, $text, $timeout)
EndFunc   ;==>_WinWaitActivate

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

You have functions defined within functions as well. You put Functions inside of your Switch statements, and that's just not right. You should look at how to call a function as well, because you never actuall jump to those functions, you just define them there. Run Au3Check on the script to point out the mistakes, you can do that within SciTE by pressing CTRL-F5.


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

Thanks so much for all of your comments, suggestions! Posted Image

Share this post


Link to post
Share on other sites

You're Welcome!


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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