Bettylou

New Program

26 posts in this topic

#1 ·  Posted (edited)

Hello.

I am a beginner to scripting and a new member to this forum. All advise and suggestions will be very welcome as I learn.

I want to create a program for remote computers to produce a log similar to the log below. This log will print out to notepad on the desktop.

 

Windows 7 Service Pack 1 x86 (UAC is disabled!)  
 Internet Explorer 11  
 Windows Firewall Enabled!  
Panda Free Antivirus   
 WMI entry may not exist for antivirus; attempting automatic update.
 CCleaner     
 Java 8 Update 31 ---  Java version out of Date!
 Adobe Flash Player     17.0.0.188  
 Adobe Reader XI  
 Mozilla Firefox (38.0.5)
 Total Fragmentation on Drive C: 2%


I thought a series of steps.
Make each step a function that can be called in an end file.

STEP 1: OS
STEP 2: Browser
STEP 3: Firewall
...........
and so on.

So far I have done this:

#include <File.au3>

STEPS

$file = FileOpen("test.txt", 2)
FileWrite($file, "Result of test (x86)" & @CRLF)
FileWrite($file, "Running from:" & @DesktopDir & @CRLF)

FUNCTIONS

FileClose($file)


Am I on the right track? Comments? Suggestions?

Edited by Bettylou

Share this post


Link to post
Share on other sites



Hi, @Bettylou, welcome to the forum.  A lot of this you can get through AutoIt directly, or through WMI. First, I would suggest looking at the @ macros in the Help File. Macros such as @OSArch, @OSLang, etc. will help you immensely. Also search the forum for Script-o-Matic, which will help you use WMI to find things such as the state of the firewall, what applications are installed, etc.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Sorry if this a dumb question but how do you put a space between macros?

#include <File.au3>


$file = FileOpen("Test.txt", 2)
FileWrite($file, "Result of Test" & @CRLF)
FileWrite($file, "Running from:" & @DesktopDir & @CRLF)
FileWrite($file, "-------------------" & @CRLF)
FileWrite($file, @OSVersion & @OSArch & @OSServicePack)
FileClose($file)

 

Share this post


Link to post
Share on other sites

how do you put a space between macros?

FileWriteLine($file, @OSVersion & "  " & @OSArch & "  " & @OSServicePack)

Hope that helps

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Get Computer Infomation:

;#RequireAdmin
;#NoTrayIcon
Opt("TrayAutoPause", 0)
Opt('MustDeclareVars', 1)
#pragma compile(Console, True)
Global Const $Coder = "Dao Van Trong - Trong.CF"
Global Const $UBOUND_DIMENSIONS = 0
Global Const $UBOUND_COLUMNS = 2
Global Const $DT_ALL = "ALL"
Global Const $STR_REGEXPARRAYGLOBALMATCH = 3
Global Const $STR_ENDISSTART = 0
Global Const $STR_ENDNOTSTART = 1
Global Const $KF_EXTENDED = 0x0100
Global Const $KF_ALTDOWN = 0x2000
Global Const $KF_UP = 0x8000
; Service state
Global Const $SERVICE_STOPPED = 0x00000001
Global Const $SERVICE_START_PENDING = 0x00000002
Global Const $SERVICE_STOP_PENDING = 0x00000003
Global Const $SERVICE_RUNNING = 0x00000004
Global Const $SERVICE_CONTINUE_PENDING = 0x00000005
Global Const $SERVICE_PAUSE_PENDING = 0x00000006
Global Const $SERVICE_PAUSED = 0x00000007
Global $fwMgr, $profile
Global Const $SC_MANAGER_CONNECT = 0x0001
Global Const $SERVICE_QUERY_STATUS = 0x0004
Global Const $SC_STATUS_PROCESS_INFO = 0
Global Const $FO_OVERWRITE = 2 ; Write mode (erase previous contents)
Global Const $FO_CREATEPATH = 8 ; Create directory structure if it doesn't exist
Global Const $FO_UTF8 = 128 ; Read/Write mode UTF8 with BOM

Local $sPathLogFile = @TempDir & "\" & @ScriptName & ".log"
Global $hLogFile = FileOpen($sPathLogFile, $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8)
_WriteLog(@CRLF & "!> ***^*** " & @ScriptFullPath & " - " & @HOUR & "/" & @MIN & "/" & @SEC & " - " & @MDAY & "/" & @MON & "/" & @YEAR & "---------------------------------------------------------------" & @CRLF)
_WriteLog("!> System infomation" & @CRLF)
_WriteLog("!> ComputerName: " & @ComputerName & @CRLF)
_WriteLog("!> UserName: " & @UserName & @CRLF)
If _GetSidAccount(@UserName) <> "" Then _WriteLog("!> Account SID: " & _GetSidAccount(@UserName) & @CRLF)
_WriteLog("!> OSVersion: " & @OSVersion & @CRLF)
_WriteLog("!> OSType: " & @OSType & @CRLF)
_WriteLog("!> OSBuild: " & @OSBuild & @CRLF)
_WriteLog("!> OSArch: " & @OSArch & @CRLF)
_WriteLog("!> OSLang: " & @OSLang & @CRLF)
If @OSServicePack <> "" Then _WriteLog("!> OsServicePack: " & @OSServicePack & @CRLF)
_WriteLog(@CRLF & "!> IP Infomation: " & @CRLF)
If @IPAddress1 <> "" And @IPAddress1 <> "0.0.0.0" Then _WriteLog("!> Computer IP1: " & @IPAddress1 & @CRLF)
If @IPAddress2 <> "" And @IPAddress2 <> "0.0.0.0" Then _WriteLog("!> Computer IP2: " & @IPAddress2 & @CRLF)
If @IPAddress3 <> "" And @IPAddress2 <> "0.0.0.0" Then _WriteLog("!> Computer IP3: " & @IPAddress3 & @CRLF)
If @IPAddress4 <> "" And @IPAddress4 <> "0.0.0.0" Then _WriteLog("!> Computer IP4: " & @IPAddress4 & @CRLF)
;ConsoleWrite(@CRLF & "!> Get Internet IP..... " & @CRLF)
;Local $iNetIP = _GetIP()
;If $iNetIP <> "" And $iNetIP <> "0.0.0.0" Then _WriteLog("!> Internet IP: " & $iNetIP & @CRLF)
_WriteLog(@CRLF & "!> Screen Infomation: " & @CRLF)
_WriteLog("!> DesktopHeight: " & @DesktopHeight & @CRLF)
_WriteLog("!> DesktopWidth: " & @DesktopWidth & @CRLF)
_WriteLog("!> DesktopDepth: " & @DesktopDepth & @CRLF)
_WriteLog("!> DesktopRefresh: " & @DesktopRefresh & @CRLF)
_WriteLog(@CRLF & "!> System Path Infomation: " & @CRLF)
If @HomeDrive <> "" Then _WriteLog("!> HomeDrive: " & @HomeDrive & @CRLF)
If @HomePath <> "" Then _WriteLog("!> HomePath: " & @HomePath & @CRLF)
If @HomeShare <> "" Then _WriteLog("!> HomeShare: " & @HomeShare & @CRLF)
If @LogonDNSDomain <> "" Then _WriteLog("!> LogonDNSDomain: " & @LogonDNSDomain & @CRLF)
If @LogonDomain <> "" Then _WriteLog("!> LogonDomain: " & @LogonDomain & @CRLF)
If @LogonServer <> "" Then _WriteLog("!> LogonServer: " & @LogonServer & @CRLF)
If @SystemDir <> "" Then _WriteLog("!> SystemDir: " & @SystemDir & @CRLF)
If @WindowsDir <> "" Then _WriteLog("!> WindowsDir: " & @WindowsDir & @CRLF)
If @ProgramFilesDir <> "" Then _WriteLog("!> ProgramFilesDir: " & @ProgramFilesDir & @CRLF)
If @CommonFilesDir <> "" Then _WriteLog("!> CommonFilesDir: " & @CommonFilesDir & @CRLF)
If @TempDir <> "" Then _WriteLog("!> TempDir: " & @TempDir & @CRLF)
If @AppDataCommonDir <> "" Then _WriteLog("!> AppDataCommonDir: " & @AppDataCommonDir & @CRLF)
If @DesktopCommonDir <> "" Then _WriteLog("!> DesktopCommonDir: " & @DesktopCommonDir & @CRLF)
If @DocumentsCommonDir <> "" Then _WriteLog("!> DocumentsCommonDir: " & @DocumentsCommonDir & @CRLF)
If @FavoritesCommonDir <> "" Then _WriteLog("!> FavoritesCommonDir: " & @FavoritesCommonDir & @CRLF)
If @ProgramsCommonDir <> "" Then _WriteLog("!> ProgramsCommonDir: " & @ProgramsCommonDir & @CRLF)
If @StartMenuCommonDir <> "" Then _WriteLog("!> StartMenuCommonDir: " & @StartMenuCommonDir & @CRLF)
If @StartupCommonDir <> "" Then _WriteLog("!> StartupCommonDir: " & @StartupCommonDir & @CRLF)
If @AppDataDir <> "" Then _WriteLog("!> AppDataDir: " & @AppDataDir & @CRLF)
If @LocalAppDataDir <> "" Then _WriteLog("!> LocalAppDataDir: " & @LocalAppDataDir & @CRLF)
If @DesktopDir <> "" Then _WriteLog("!> DesktopDir: " & @DesktopDir & @CRLF)
If @MyDocumentsDir <> "" Then _WriteLog("!> MyDocumentsDir: " & @MyDocumentsDir & @CRLF)
If @FavoritesDir <> "" Then _WriteLog("!> FavoritesDir: " & @FavoritesDir & @CRLF)
If @ProgramsDir <> "" Then _WriteLog("!> ProgramsDir: " & @ProgramsDir & @CRLF)
If @StartMenuDir <> "" Then _WriteLog("!> StartMenuDir: " & @StartMenuDir & @CRLF)
If @StartupDir <> "" Then _WriteLog("!> StartupDir: " & @StartupDir & @CRLF)
If @UserProfileDir <> "" Then _WriteLog("!> UserProfileDir: " & @UserProfileDir & @CRLF)
If StringInStr(@OSArch, "64") And @ProgramFilesDir <> @ProgramFilesDir & " (x86)" And @ProgramFilesDir <> "" Then _WriteLog("!> ProgramFilesDir_x86: " & @ProgramFilesDir & " (x86)" & @CRLF)
_WriteLog(@CRLF & "!> Device Infomation: " & @CRLF)
Local $aArray = DriveGetDrive($DT_ALL)
If @error Then
    _WriteLog("!> Get device info error!" & @CRLF)
Else
    _WriteLog("!> Total " & $aArray[0] & " device!" & @CRLF)
    If IsAdmin() Then
        For $i = 1 To $aArray[0]
            Local $sDevice = StringUpper($aArray[$i])
            _WriteLog("!> Drive " & $i & " DriveType: " & DriveGetType($sDevice) & " - " & DriveGetType($sDevice, 3) & @CRLF)
            Local $sc = _DosRun('"' & @SystemDir & '\defrag.exe" -a ' & $sDevice & '')
            Local $cs = _StringBetween($sc, "Report:", "Note:")
            If IsArray($cs) Then _WriteLog("!> " & StringReplace($cs[0], @CRLF & @CRLF, @CRLF) & @CRLF)
        Next
    Else
        _WriteLog("!> Run this application with Administrator to Get device info!" & @CRLF)
    EndIf
EndIf
_WriteLog(@CRLF & "!> UAC Infomation: " & @CRLF)
Local $UAC = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLUA")
If $UAC <> 0 Then
    $UAC = "Enable!"
Else
    $UAC = "Disabled!"
EndIf
_WriteLog("!> UAC is " & $UAC & @CRLF & @CRLF)
_WriteLog(@CRLF & "!> Application installed Infomation: " & @CRLF)
Local $sListInstalledPrograms
_ComputerGetSoftware($sListInstalledPrograms)
_WriteLog("!> Total " & UBound($sListInstalledPrograms) - 1 & " programs installed !" & @CRLF)
_WriteLog("!> List installed programs: " & @CRLF)
For $i = 1 To UBound($sListInstalledPrograms) - 1
    _WriteLog("!> " & $i & ': ' & $sListInstalledPrograms[$i][0] & @CRLF)
Next

Local $sProcessList = ProcessList()
_WriteLog("!> Total " & UBound($sProcessList) - 1 & " programs running !" & @CRLF)
_WriteLog("!> List running programs: " & @CRLF)
For $p = 1 To UBound($sProcessList) - 1
    _WriteLog("!> " & $p & ': [' & $sProcessList[$p][1] & "] " & $sProcessList[$p][0] & @CRLF)
Next

Local $WindowsFireWallName = "MpsSvc"
If StringInStr(@OSVersion, "XP") Then $WindowsFireWallName = "sharedaccess"
Local $sFWRun = _Service_QueryStatus($WindowsFireWallName)
If IsArray($sFWRun) Then
    If $sFWRun[1] > 3 And $sFWRun[1] < 6 Then
        _WriteLog(@CRLF & "!> Windows Firwall is Enable!" & @CRLF)
        Local $sListAP = _ListAuthorizedApps()
        If IsArray($sListAP) Then
            _WriteLog("!> List of allowed programs: " & @CRLF)
            For $i = 1 To UBound($sListAP) - 1
                _WriteLog("!> " & $i & ": " & $sListAP[$i][0] & "|" & $sListAP[$i][3] & @CRLF)
            Next
        EndIf
    Else
        _WriteLog(@CRLF & "!> Windows Firwall is Disabled!" & @CRLF)
    EndIf
EndIf

ShellExecute($sPathLogFile)

Func _WriteLog($sString)
    ConsoleWrite($sString)
    Return FileWrite($hLogFile, $sString)
EndFunc   ;==>_WriteLog
Func _DosRun($xCMD)
    Local $sOutput, $hOutput = Run($xCMD, "", @SW_HIDE, 0x8);$STDERR_MERGED (0x8)
    Do
        Sleep(10)
        $sOutput &= StdoutRead($hOutput)
    Until @error
    Return $sOutput
EndFunc   ;==>_DosRun
Func _GetSidAccount($sAccount, $sSystem = "")
    If $sAccount = "" Then $sAccount = @UserName
    Local $tData = DllStructCreate("byte SID[256]")
    Local $sCall = DllCall("advapi32.dll", "bool", "LookupAccountNameW", "wstr", $sSystem, "wstr", $sAccount, "struct*", $tData, "dword*", DllStructGetSize($tData), "wstr", "", "dword*", DllStructGetSize($tData), "int*", 0)
    If @error Or Not $sCall[0] Then Return SetError(@error, @extended, "")
    Local $pSID = DllStructGetPtr($tData, "SID")
    Local $iCall = DllCall("advapi32.dll", "bool", "IsValidSid", "struct*", $pSID)
    If @error Or Not $iCall[0] Then Return SetError(@error, @extended, "")
    Local $dCall = DllCall("advapi32.dll", "bool", "ConvertSidToStringSidW", "struct*", $pSID, "ptr*", 0)
    If @error Or Not $dCall[0] Then Return SetError(@error, @extended, "")
    Local $pStringSid = $dCall[2]
    Local $aLen = DllCall("kernel32.dll", "int", "lstrlenW", "struct*", $pStringSid)
    Local $sSID = DllStructGetData(DllStructCreate("wchar Text[" & $aLen[0] + 1 & "]", $pStringSid), "Text")
    DllCall("kernel32.dll", "handle", "LocalFree", "handle", $pStringSid)
    Return SetError(0, 0, $sSID)
EndFunc   ;==>_GetSidAccount
Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
    Local Const $UnInstKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $i = 1
    Dim $aSoftwareInfo[1][4]
    Local $AppKey, $Reg, $string, $input = 'ALL'
    If $input = 'ALL' Then
        For $j = 1 To 500
            $AppKey = RegEnumKey($UnInstKey, $j)
            If @error <> 0 Then ExitLoop
            If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop
            ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4]
            $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
            $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3)
            $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3)
            $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3)
            $i = $i + 1
        Next
        $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
        If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0)
        Return _ArraySort($aSoftwareInfo, 0, 1)
    Else
        For $j = 1 To 500
            $AppKey = RegEnumKey($UnInstKey, $j)
            If @error <> 0 Then ExitLoop
            $Reg = RegRead($UnInstKey & "\" & $AppKey, "DisplayName")
            $string = StringInStr($Reg, $input)
            If $string = 0 Then ContinueLoop
            ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4]
            $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
            $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3)
            $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3)
            $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3)
            $i = $i + 1
        Next
        $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
        If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0)
        Return _ArraySort($aSoftwareInfo, 0, 1)
    EndIf
EndFunc   ;==>_ComputerGetSoftware
Func _Service_QueryStatus($sServiceName, $sComputerName = "")
    ; $Array[1] - The current state of the service. Can be one of the following values:
    ; $SERVICE_STOPPED - The service has stopped.
    ; $SERVICE_START_PENDING - The service is starting.
    ; $SERVICE_STOP_PENDING - The service is stopping.
    ; $SERVICE_RUNNING - The service is running.
    ; $SERVICE_CONTINUE_PENDING - The service is about to continue.
    ; $SERVICE_PAUSE_PENDING - The service is pausing.
    ; $SERVICE_PAUSED - The service is paused.
    Local $hSC, $hService, $tSERVICE_STATUS_PROCESS, $avQSSE, $iQSSE, $aiStatus[9]
    $hSC = OpenSCManager($sComputerName, $SC_MANAGER_CONNECT)
    $hService = OpenService($hSC, $sServiceName, $SERVICE_QUERY_STATUS)
    CloseServiceHandle($hSC)
    $tSERVICE_STATUS_PROCESS = DllStructCreate("dword[9]")
    $avQSSE = DllCall("advapi32.dll", "int", "QueryServiceStatusEx", "hwnd", $hService, "dword", $SC_STATUS_PROCESS_INFO, "ptr", DllStructGetPtr($tSERVICE_STATUS_PROCESS), "dword", DllStructGetSize($tSERVICE_STATUS_PROCESS), "dword*", 0)
    If $avQSSE[0] = 0 Then $iQSSE = GetLastError()
    CloseServiceHandle($hService)
    For $i = 0 To 8
        $aiStatus[$i] = DllStructGetData($tSERVICE_STATUS_PROCESS, 1, $i + 1)
    Next
    Return SetError($iQSSE, 0, $aiStatus)
EndFunc   ;==>_Service_QueryStatus
Func CloseServiceHandle($hSCObject)
    Local $avCSH = DllCall("advapi32.dll", "int", "CloseServiceHandle", "hwnd", $hSCObject)
    Return $avCSH[0]
EndFunc   ;==>CloseServiceHandle
Func GetLastError()
    Local $aiE = DllCall("kernel32.dll", "dword", "GetLastError")
    Return $aiE[0]
EndFunc   ;==>GetLastError
Func OpenSCManager($sComputerName, $iAccess)
    Local $avOSCM = DllCall("advapi32.dll", "hwnd", "OpenSCManager", "str", $sComputerName, "str", "ServicesActive", "dword", $iAccess)
    Return $avOSCM[0]
EndFunc   ;==>OpenSCManager
Func OpenService($hSC, $sServiceName, $iAccess)
    Local $avOS = DllCall("advapi32.dll", "hwnd", "OpenService", "hwnd", $hSC, "str", $sServiceName, "dword", $iAccess)
    Return $avOS[0]
EndFunc   ;==>OpenService
Global $fwMgr, $profile
Func _ListAuthorizedApps()
    _createFWMgrObject()
    Local $aApps = $profile.AuthorizedApplications
    If @error <> 0 Then Return SetError(1, 3, "")
    Local $appCount = $aApps.Count
    If $appCount < 1 Then Return SetError(1, 4, "")
    Local $appsArray[$aApps.Count][6]
    Local $iIndex = 0
    For $app In $aApps
        $appsArray[$iIndex][0] = $app.Name
        $appsArray[$iIndex][1] = $app.Enabled
        $appsArray[$iIndex][2] = $app.IPVersion
        $appsArray[$iIndex][3] = $app.ProcessImageFileName
        $appsArray[$iIndex][4] = $app.RemoteAddresses
        $appsArray[$iIndex][5] = $app.Scope
        $iIndex = $iIndex + 1
    Next
    Return $appsArray
EndFunc   ;==>_ListAuthorizedApps
Func _createFWMgrObject()
    $fwMgr = ObjCreate("HNetCfg.FwMgr")
    If Not IsObj($fwMgr) Or @error <> 0 Then Return SetError(1, 1, 0)
    $profile = $fwMgr.LocalPolicy.CurrentProfile
    If @error <> 0 Then Return SetError(1, 2, "")
EndFunc   ;==>_createFWMgrObject
Func _StringBetween($sString, $sStart, $sEnd, $iMode = $STR_ENDISSTART, $bCase = False)
    $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A"
    If $iMode <> $STR_ENDNOTSTART Then $iMode = $STR_ENDISSTART
    If $iMode = $STR_ENDISSTART Then
        $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z"
    Else
        $sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z"
    EndIf
    If $bCase = Default Then
        $bCase = False
    EndIf
    Local $aReturn = StringRegExp($sString, "(?s" & (Not $bCase ? "i" : "") & ")" & $sStart & "(.*?)" & $sEnd, $STR_REGEXPARRAYGLOBALMATCH)
    If @error Then Return SetError(1, 0, 0)
    Return $aReturn
EndFunc   ;==>_StringBetween
Func _GetIP()
    Local Const $GETIP_TIMER = 300000
    Local Static $hTimer = 0
    Local Static $sLastIP = 0
    If TimerDiff($hTimer) < $GETIP_TIMER And Not $sLastIP Then
        Return SetExtended(1, $sLastIP)
    EndIf
    Local $aGetIPURL[] = ["http://checkip.dyndns.org", "http://www.myexternalip.com/raw", "http://bot.whatismyipaddress.com"], $aReturn = 0, $sReturn = ""
    For $i = 0 To UBound($aGetIPURL) - 1
        $sReturn = InetRead($aGetIPURL[$i])
        If @error Or $sReturn == "" Then ContinueLoop
        $aReturn = StringRegExp(BinaryToString($sReturn), "((?:\d{1,3}\.){3}\d{1,3})", $STR_REGEXPARRAYGLOBALMATCH)
        If Not @error Then
            $sReturn = $aReturn[0]
            ExitLoop
        EndIf
        $sReturn = ""
    Next
    $hTimer = TimerInit()
    $sLastIP = $sReturn
    If $sReturn == "" Then Return SetError(1, 0, -1)
    Return $sReturn
EndFunc   ;==>_GetIP
Func _ArrayReverse(ByRef $aArray, $iStart = 0, $iEnd = 0)
    If $iStart = Default Then $iStart = 0
    If $iEnd = Default Then $iEnd = 0
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If UBound($aArray, $UBOUND_DIMENSIONS) <> 1 Then Return SetError(3, 0, 0)
    If Not UBound($aArray) Then Return SetError(4, 0, 0)
    Local $vTmp, $iUBound = UBound($aArray) - 1
    If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound
    If $iStart < 0 Then $iStart = 0
    If $iStart > $iEnd Then Return SetError(2, 0, 0)
    For $i = $iStart To Int(($iStart + $iEnd - 1) / 2)
        $vTmp = $aArray[$i]
        $aArray[$i] = $aArray[$iEnd]
        $aArray[$iEnd] = $vTmp
        $iEnd -= 1
    Next
    Return 1
EndFunc   ;==>_ArrayReverse
Func _ArraySort(ByRef $aArray, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0, $iPivot = 0)
    If $iDescending = Default Then $iDescending = 0
    If $iStart = Default Then $iStart = 0
    If $iEnd = Default Then $iEnd = 0
    If $iSubItem = Default Then $iSubItem = 0
    If $iPivot = Default Then $iPivot = 0
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    Local $iUBound = UBound($aArray) - 1
    If $iUBound = -1 Then Return SetError(5, 0, 0)
    If $iEnd = Default Then $iEnd = 0
    If $iEnd < 1 Or $iEnd > $iUBound Or $iEnd = Default Then $iEnd = $iUBound
    If $iStart < 0 Or $iStart = Default Then $iStart = 0
    If $iStart > $iEnd Then Return SetError(2, 0, 0)
    If $iDescending = Default Then $iDescending = 0
    If $iPivot = Default Then $iPivot = 0
    If $iSubItem = Default Then $iSubItem = 0
    Switch UBound($aArray, $UBOUND_DIMENSIONS)
        Case 1
            If $iPivot Then
                __ArrayDualPivotSort($aArray, $iStart, $iEnd)
            Else
                __ArrayQuickSort1D($aArray, $iStart, $iEnd)
            EndIf
            If $iDescending Then _ArrayReverse($aArray, $iStart, $iEnd)
        Case 2
            If $iPivot Then Return SetError(6, 0, 0)
            Local $iSubMax = UBound($aArray, $UBOUND_COLUMNS) - 1
            If $iSubItem > $iSubMax Then Return SetError(3, 0, 0)
            If $iDescending Then
                $iDescending = -1
            Else
                $iDescending = 1
            EndIf
            __ArrayQuickSort2D($aArray, $iDescending, $iStart, $iEnd, $iSubItem, $iSubMax)
        Case Else
            Return SetError(4, 0, 0)
    EndSwitch
    Return 1
EndFunc   ;==>_ArraySort
Func __ArrayQuickSort1D(ByRef $aArray, Const ByRef $iStart, Const ByRef $iEnd)
    If $iEnd <= $iStart Then Return
    Local $vTmp
    If ($iEnd - $iStart) < 15 Then
        Local $vCur
        For $i = $iStart + 1 To $iEnd
            $vTmp = $aArray[$i]
            If IsNumber($vTmp) Then
                For $j = $i - 1 To $iStart Step -1
                    $vCur = $aArray[$j]
                    If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur) >= 0) Then ExitLoop
                    $aArray[$j + 1] = $vCur
                Next
            Else
                For $j = $i - 1 To $iStart Step -1
                    If (StringCompare($vTmp, $aArray[$j]) >= 0) Then ExitLoop
                    $aArray[$j + 1] = $aArray[$j]
                Next
            EndIf
            $aArray[$j + 1] = $vTmp
        Next
        Return
    EndIf
    Local $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)], $bNum = IsNumber($vPivot)
    Do
        If $bNum Then
            While ($aArray[$L] < $vPivot And IsNumber($aArray[$L])) Or (Not IsNumber($aArray[$L]) And StringCompare($aArray[$L], $vPivot) < 0)
                $L += 1
            WEnd
            While ($aArray[$R] > $vPivot And IsNumber($aArray[$R])) Or (Not IsNumber($aArray[$R]) And StringCompare($aArray[$R], $vPivot) > 0)
                $R -= 1
            WEnd
        Else
            While (StringCompare($aArray[$L], $vPivot) < 0)
                $L += 1
            WEnd
            While (StringCompare($aArray[$R], $vPivot) > 0)
                $R -= 1
            WEnd
        EndIf
        If $L <= $R Then
            $vTmp = $aArray[$L]
            $aArray[$L] = $aArray[$R]
            $aArray[$R] = $vTmp
            $L += 1
            $R -= 1
        EndIf
    Until $L > $R
    __ArrayQuickSort1D($aArray, $iStart, $R)
    __ArrayQuickSort1D($aArray, $L, $iEnd)
EndFunc   ;==>__ArrayQuickSort1D
Func __ArrayQuickSort2D(ByRef $aArray, Const ByRef $iStep, Const ByRef $iStart, Const ByRef $iEnd, Const ByRef $iSubItem, Const ByRef $iSubMax)
    If $iEnd <= $iStart Then Return
    Local $vTmp, $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)][$iSubItem], $bNum = IsNumber($vPivot)
    Do
        If $bNum Then
            While ($iStep * ($aArray[$L][$iSubItem] - $vPivot) < 0 And IsNumber($aArray[$L][$iSubItem])) Or (Not IsNumber($aArray[$L][$iSubItem]) And $iStep * StringCompare($aArray[$L][$iSubItem], $vPivot) < 0)
                $L += 1
            WEnd
            While ($iStep * ($aArray[$R][$iSubItem] - $vPivot) > 0 And IsNumber($aArray[$R][$iSubItem])) Or (Not IsNumber($aArray[$R][$iSubItem]) And $iStep * StringCompare($aArray[$R][$iSubItem], $vPivot) > 0)
                $R -= 1
            WEnd
        Else
            While ($iStep * StringCompare($aArray[$L][$iSubItem], $vPivot) < 0)
                $L += 1
            WEnd
            While ($iStep * StringCompare($aArray[$R][$iSubItem], $vPivot) > 0)
                $R -= 1
            WEnd
        EndIf
        If $L <= $R Then
            For $i = 0 To $iSubMax
                $vTmp = $aArray[$L][$i]
                $aArray[$L][$i] = $aArray[$R][$i]
                $aArray[$R][$i] = $vTmp
            Next
            $L += 1
            $R -= 1
        EndIf
    Until $L > $R
    __ArrayQuickSort2D($aArray, $iStep, $iStart, $R, $iSubItem, $iSubMax)
    __ArrayQuickSort2D($aArray, $iStep, $L, $iEnd, $iSubItem, $iSubMax)
EndFunc   ;==>__ArrayQuickSort2D
Func __ArrayDualPivotSort(ByRef $aArray, $iPivot_Left, $iPivot_Right, $bLeftMost = True)
    If $iPivot_Left > $iPivot_Right Then Return
    Local $iLength = $iPivot_Right - $iPivot_Left + 1
    Local $i, $j, $k, $iAi, $iAk, $iA1, $iA2, $iLast
    If $iLength < 45 Then
        If $bLeftMost Then
            $i = $iPivot_Left
            While $i < $iPivot_Right
                $j = $i
                $iAi = $aArray[$i + 1]
                While $iAi < $aArray[$j]
                    $aArray[$j + 1] = $aArray[$j]
                    $j -= 1
                    If $j + 1 = $iPivot_Left Then ExitLoop
                WEnd
                $aArray[$j + 1] = $iAi
                $i += 1
            WEnd
        Else
            While 1
                If $iPivot_Left >= $iPivot_Right Then Return 1
                $iPivot_Left += 1
                If $aArray[$iPivot_Left] < $aArray[$iPivot_Left - 1] Then ExitLoop
            WEnd
            While 1
                $k = $iPivot_Left
                $iPivot_Left += 1
                If $iPivot_Left > $iPivot_Right Then ExitLoop
                $iA1 = $aArray[$k]
                $iA2 = $aArray[$iPivot_Left]
                If $iA1 < $iA2 Then
                    $iA2 = $iA1
                    $iA1 = $aArray[$iPivot_Left]
                EndIf
                $k -= 1
                While $iA1 < $aArray[$k]
                    $aArray[$k + 2] = $aArray[$k]
                    $k -= 1
                WEnd
                $aArray[$k + 2] = $iA1
                While $iA2 < $aArray[$k]
                    $aArray[$k + 1] = $aArray[$k]
                    $k -= 1
                WEnd
                $aArray[$k + 1] = $iA2
                $iPivot_Left += 1
            WEnd
            $iLast = $aArray[$iPivot_Right]
            $iPivot_Right -= 1
            While $iLast < $aArray[$iPivot_Right]
                $aArray[$iPivot_Right + 1] = $aArray[$iPivot_Right]
                $iPivot_Right -= 1
            WEnd
            $aArray[$iPivot_Right + 1] = $iLast
        EndIf
        Return 1
    EndIf
    Local $iSeventh = BitShift($iLength, 3) + BitShift($iLength, 6) + 1
    Local $iE1, $iE2, $iE3, $iE4, $iE5, $t
    $iE3 = Ceiling(($iPivot_Left + $iPivot_Right) / 2)
    $iE2 = $iE3 - $iSeventh
    $iE1 = $iE2 - $iSeventh
    $iE4 = $iE3 + $iSeventh
    $iE5 = $iE4 + $iSeventh
    If $aArray[$iE2] < $aArray[$iE1] Then
        $t = $aArray[$iE2]
        $aArray[$iE2] = $aArray[$iE1]
        $aArray[$iE1] = $t
    EndIf
    If $aArray[$iE3] < $aArray[$iE2] Then
        $t = $aArray[$iE3]
        $aArray[$iE3] = $aArray[$iE2]
        $aArray[$iE2] = $t
        If $t < $aArray[$iE1] Then
            $aArray[$iE2] = $aArray[$iE1]
            $aArray[$iE1] = $t
        EndIf
    EndIf
    If $aArray[$iE4] < $aArray[$iE3] Then
        $t = $aArray[$iE4]
        $aArray[$iE4] = $aArray[$iE3]
        $aArray[$iE3] = $t
        If $t < $aArray[$iE2] Then
            $aArray[$iE3] = $aArray[$iE2]
            $aArray[$iE2] = $t
            If $t < $aArray[$iE1] Then
                $aArray[$iE2] = $aArray[$iE1]
                $aArray[$iE1] = $t
            EndIf
        EndIf
    EndIf
    If $aArray[$iE5] < $aArray[$iE4] Then
        $t = $aArray[$iE5]
        $aArray[$iE5] = $aArray[$iE4]
        $aArray[$iE4] = $t
        If $t < $aArray[$iE3] Then
            $aArray[$iE4] = $aArray[$iE3]
            $aArray[$iE3] = $t
            If $t < $aArray[$iE2] Then
                $aArray[$iE3] = $aArray[$iE2]
                $aArray[$iE2] = $t
                If $t < $aArray[$iE1] Then
                    $aArray[$iE2] = $aArray[$iE1]
                    $aArray[$iE1] = $t
                EndIf
            EndIf
        EndIf
    EndIf
    Local $iLess = $iPivot_Left
    Local $iGreater = $iPivot_Right
    If (($aArray[$iE1] <> $aArray[$iE2]) And ($aArray[$iE2] <> $aArray[$iE3]) And ($aArray[$iE3] <> $aArray[$iE4]) And ($aArray[$iE4] <> $aArray[$iE5])) Then
        Local $iPivot_1 = $aArray[$iE2]
        Local $iPivot_2 = $aArray[$iE4]
        $aArray[$iE2] = $aArray[$iPivot_Left]
        $aArray[$iE4] = $aArray[$iPivot_Right]
        Do
            $iLess += 1
        Until $aArray[$iLess] >= $iPivot_1
        Do
            $iGreater -= 1
        Until $aArray[$iGreater] <= $iPivot_2
        $k = $iLess
        While $k <= $iGreater
            $iAk = $aArray[$k]
            If $iAk < $iPivot_1 Then
                $aArray[$k] = $aArray[$iLess]
                $aArray[$iLess] = $iAk
                $iLess += 1
            ElseIf $iAk > $iPivot_2 Then
                While $aArray[$iGreater] > $iPivot_2
                    $iGreater -= 1
                    If $iGreater + 1 = $k Then ExitLoop 2
                WEnd
                If $aArray[$iGreater] < $iPivot_1 Then
                    $aArray[$k] = $aArray[$iLess]
                    $aArray[$iLess] = $aArray[$iGreater]
                    $iLess += 1
                Else
                    $aArray[$k] = $aArray[$iGreater]
                EndIf
                $aArray[$iGreater] = $iAk
                $iGreater -= 1
            EndIf
            $k += 1
        WEnd
        $aArray[$iPivot_Left] = $aArray[$iLess - 1]
        $aArray[$iLess - 1] = $iPivot_1
        $aArray[$iPivot_Right] = $aArray[$iGreater + 1]
        $aArray[$iGreater + 1] = $iPivot_2
        __ArrayDualPivotSort($aArray, $iPivot_Left, $iLess - 2, True)
        __ArrayDualPivotSort($aArray, $iGreater + 2, $iPivot_Right, False)
        If ($iLess < $iE1) And ($iE5 < $iGreater) Then
            While $aArray[$iLess] = $iPivot_1
                $iLess += 1
            WEnd
            While $aArray[$iGreater] = $iPivot_2
                $iGreater -= 1
            WEnd
            $k = $iLess
            While $k <= $iGreater
                $iAk = $aArray[$k]
                If $iAk = $iPivot_1 Then
                    $aArray[$k] = $aArray[$iLess]
                    $aArray[$iLess] = $iAk
                    $iLess += 1
                ElseIf $iAk = $iPivot_2 Then
                    While $aArray[$iGreater] = $iPivot_2
                        $iGreater -= 1
                        If $iGreater + 1 = $k Then ExitLoop 2
                    WEnd
                    If $aArray[$iGreater] = $iPivot_1 Then
                        $aArray[$k] = $aArray[$iLess]
                        $aArray[$iLess] = $iPivot_1
                        $iLess += 1
                    Else
                        $aArray[$k] = $aArray[$iGreater]
                    EndIf
                    $aArray[$iGreater] = $iAk
                    $iGreater -= 1
                EndIf
                $k += 1
            WEnd
        EndIf
        __ArrayDualPivotSort($aArray, $iLess, $iGreater, False)
    Else
        Local $iPivot = $aArray[$iE3]
        $k = $iLess
        While $k <= $iGreater
            If $aArray[$k] = $iPivot Then
                $k += 1
                ContinueLoop
            EndIf
            $iAk = $aArray[$k]
            If $iAk < $iPivot Then
                $aArray[$k] = $aArray[$iLess]
                $aArray[$iLess] = $iAk
                $iLess += 1
            Else
                While $aArray[$iGreater] > $iPivot
                    $iGreater -= 1
                WEnd
                If $aArray[$iGreater] < $iPivot Then
                    $aArray[$k] = $aArray[$iLess]
                    $aArray[$iLess] = $aArray[$iGreater]
                    $iLess += 1
                Else
                    $aArray[$k] = $iPivot
                EndIf
                $aArray[$iGreater] = $iAk
                $iGreater -= 1
            EndIf
            $k += 1
        WEnd
        __ArrayDualPivotSort($aArray, $iPivot_Left, $iLess - 1, True)
        __ArrayDualPivotSort($aArray, $iGreater + 1, $iPivot_Right, False)
    EndIf
EndFunc   ;==>__ArrayDualPivotSort

 

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites

FileWriteLine($file, @OSVersion & "  " & @OSArch & "  " & @OSServicePack)

Hope that helps

Thank you. With filewrite I was getting a syntax error. I need to go back and read the help file again and again as I experiment.

To Trong

Thank you. I'll be back in a few weeks after I have studied each line in your script. I sure have a long way to go.

 

expandpopup

Share this post


Link to post
Share on other sites

@Trong we try to follow the "Teach a man to fish" motto on this forum, especially for new users; usually more helpful to point someone to the solution, allowing them to learn along the way, rather than blasting someone with 700 lines of convoluted code on their third day..


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Just the example script only. I think it would be helpful for learning quickly.
I will pay attention. :blink: 

 

Local $hLogFile = FileOpen("Logs.txt", 2 + 8 + 128) ;$FO_OVERWRITE = 2 / $FO_CREATEPATH = 8 / $FO_UTF8 = 128
FileWriteLine($hLogFile, "+System infomation:")
FileWrite($hLogFile, " - ComputerName: " & @ComputerName & @CRLF)
FileWriteLine($hLogFile, " - UserName: " & @UserName)
FileWriteLine($hLogFile, " > OSVersion: " & @OSVersion & " - OSArch: " & @OSArch)
FileClose($hLogFile)

 


Regards,
 

Share this post


Link to post
Share on other sites

Am I heading in the right direction? I'm using a message box for the output ATM because I don't know how to create a temp dir yet.

Dim $OS = @OSVersion
Dim $arch = @OSArch
Dim $SP = @OSServicePack
Dim $text = ""
Switch $OS
Case "WIN_XP"
$OS = "Windows XP"
Case "WIN_VISTA"
$OS = "Windows Vista"
Case "WIN_7"
$OS = "Windows 7"
Case "WIN_8"
$OS = "Windows 8"
Case "WIN_8.1"
$OS = "Windows 8.1"
Case "WIN_10"
$OS = "Windows 10"
EndSwitch

$text &= "" & $OS & "  " & $arch & "  " & $SP
MsgBox (0, "Computer Information", $text)

 

Share this post


Link to post
Share on other sites

DirCreate ( "path" )


Regards,
 

Share this post


Link to post
Share on other sites

Okay my next feeble effort. It is not exactly what I want but I'm slowly getting there. So far I haven't been able to figure out how to get it to print out the Arch without showing "bit" and how to get it to print out "Service Pack" instead of 1.

$wbemFlagReturnImmediately = 0x10

$wbemFlagForwardOnly = 0x20

$colItems = ""
$sComputer = "Localhost"

$Output=""
$Output = $Output & "Computer: " & $sComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\root\CIMV2")
$colItems = $oWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
   For $objItem In $colItems
      $Output = $Output & "" & $objItem.Caption
      $Output = $Output & "" & $objItem.OSArchitecture
      $Output = $Output & "" & $objItem.ServicePackMajorVersion & @CRLF


 If MsgBox(1,"WMI Output",$Output) = 2 Then ExitLoop
      $Output=""
   Next
Else
   MsgBox(0,"WMI Output","Not a Win32_OperatingSystem" )
EndIf

 

My question now is am I better off using WMI or macros?

 

Share this post


Link to post
Share on other sites

I guess you need to answer that question for yourself. Would you rather write 20 lines of code, or two?

MsgBox(0, "", @OSArch)
MsgBox(0, "", @OSServicePack)

Regarding your other question about removing part of the string returned, look at the String functions in the help file (StringTrimLeft, StringTrimRight, StringLeft and StringRight)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Eventually, when I learn how, I intend to create a temp dir for the data and send the output to notepad on the desktop. I'm only using msgbox now to check that my script works because so far msgbox is all I've learned to do.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I "borrowed" some of Trong's script.

Obviously this is not finished but am I on the right track? Should the functions go before if-then lines or after them?

 

#Include <LogFile.au3>

Global Const $FO_OVERWRITE = 2 ; Write mode (erase previous contents)
Global Const $FO_CREATEPATH = 8 ; Create directory structure if it doesn't exist
Global Const $FO_UTF8 = 128 ; Read/Write mode UTF8 with BOM

Local $sPathLogFile = @TempDir & "\" & @ScriptName & ".log"
Global $hLogFile = FileOpen($sPathLogFile, $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8)
_WriteLog(@CRLF & "Result of Test " & @CRLF
_WriteLog(@CRLF & "Running from " & @ScriptFullPath  & @CRLF)
If @OSVersion = WIN_XP then _XP()
If @OSVersion = WIN_7 Then _W7()
EndIf

Func _XP()
    If @OSServicePack < 3 then WriteLog( "Windows XP " & @OSArch &  "!Service Pack is out of date!") Else
    WriteLog("Windows XP " & @OSArch & " " & @OSServicePack & CRLF)  

EndIf

EndFunc

 

 

Edited by Bettylou

Share this post


Link to post
Share on other sites

Hi Bettylou, welcome to AutoIt.

Generally you can create your functions just about anywhere, so long as you don't create one function inside another, and any variables that are shared have been declared previously, along with all #Include files. The typical arrangement though, is to have your main code come first after all #Includes and Global variables have been declared, then your functions last, one after the other. I also find it helps to order your functions by name alphabetically.

You can of course call one function from within another.

When you post code, it helps all involved if you use the code button in the Post or Reply Editor (9th from left - angle brackets).

Like so -

#Include <LogFile.au3>

Global Const $FO_OVERWRITE = 2 ; Write mode (erase previous contents)
Global Const $FO_CREATEPATH = 8 ; Create directory structure if it doesn't exist
Global Const $FO_UTF8 = 128 ; Read/Write mode UTF8 with BOM

Local $sPathLogFile = @TempDir & "\" & @ScriptName & ".log"
Global $hLogFile = FileOpen($sPathLogFile, $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8)
_WriteLog(@CRLF & "Result of Test " & @CRLF
_WriteLog(@CRLF & "Running from " & @ScriptFullPath  & @CRLF)
If @OSVersion = WIN_XP Then
    _XP()
ElseIf @OSVersion = WIN_7 Then
    _W7()
EndIf

Func _XP()
    If @OSServicePack < 3 then
        WriteLog( "Windows XP " & @OSArch &  "!Service Pack is out of date!")
    Else
        WriteLog("Windows XP " & @OSArch & " " & @OSServicePack & CRLF)
    EndIf
EndFunc

Func _W7()
EndFunc

I have done some minor corrections to your code, but it probably needs more, especially where you have declared Local for something that is then part of a Global declaration. They are two very different scopes, but not having your complete code I am not about to suppose anything, so just bear what I said in mind, and perhaps do some research on them.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Hello TheSaint

Thank you for that. I "borrowed" the (Local $sPathLogFile) script from post #5. Obviously, I will be better off if I create my own directory. At the moment my knowledge doesn't extend that far. Um---at the moment that is my complete code. I'm sorry, I didn't think to enclose it in code tags.

Okay, this is all my own work and it is dismal to say the least. :sweating:

This works!

#include <File.au3>


$file = FileOpen("Scan.txt", 2)
FileWrite($file, "Result of Scan" & @CRLF)
FileWrite($file, "Running from:" & @DesktopDir & @CRLF)
FileWrite($file, "-------------------" & @CRLF)
FileWriteline($file, @OSVersion & " " & @OSArch & " " & @OSServicePack)
FileClose($file)

But this doesn't!

#Include <File.au3>

; create text file
$file = FileOpen("Scan.txt", 2)
FileWrite($file, "Result of Scan" & @CRLF)
FileWrite($file, "Running from:" & @DesktopDir & @CRLF)
FileWrite($file, "-------------------" & @CRLF)
; OS Versions,Arch,ServicePack
If @OSVersion = WIN_XP Then
    _OSXP()
ElseIf @OSVersion = WIN_Vista Then
    _OSVista()
ElseIf @OSVersion = WIN_7 Then
    _OS7()
ElseIf @OSVersion = WIN_8 Then
    FileWriteLine( $File, "Windows 8 " & @OSArch & CRLF)
ElseIf @OSVersion = WIN_8.1 Then
    FileWriteLine( $File, "Windows 8.1 " & @OSArch & CRLF)
ElseIf @OSVersion = WIN_10 Then
    FileWriteLine( $File, "Windows 10 " & @OSArch & CRLF)

EndIf
; UAC on or off
Local $UAC = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLUA")
If $UAC <> 0 Then
    $UAC = "Enable!"
Else
    $UAC = "Disabled!"
EndIf
 FileWrite($File, "UAC is " & $UAC & @CRLF)

Func _OSXP()
    If @OSServicePack < 3 Then
        FileWriteLine( $File, "Windows XP " & @OSArch &  "!Service Pack is out of date!")
    Else
        FileWriteLine( $File, "Windows XP " & @OSArch & " " & @OSServicePack & CRLF)
EndIf
EndFunc
Func _OSVista()
    If @OSServicePack < 2 Then
        FileWritewLine( $File, "Windows Vista " & @OSArch &  "!Service Pack is out of date!")
    Else
        fileWriteLine( $File, "Windows Vista " & @OSArch & " " & @OSServicePack & CRLF)
EndIf
EndFunc
Func _OS7()
    If @OSServicePack < 1 Then
        FileWriteLine( $File, "Windows 7 " & @OSArch &  "!Service Pack is out of date!")
    Else
        FileWriteLine( $File, "Windows 7 " & @OSArch & " " & @OSServicePack & CRLF)
EndIf
EndFunc

FileClose($file)

 

Edited by Bettylou

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Three quick things you could fix (there are more issues but this will get you started):

1. The macros you are testing produce a string so you need to use quotes

"WIN_7"

2. The carriage return line feed is a macro so it needs to start with @ as in @CRLF

3. Vista function contains

FileWritewLine

which should be:

FileWriteLine
Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

Hello jfish

Thank you for the help. I fixed the 3 items and the Service pack that was printing out as "out of date" whether it was or not.

My corrected code.

#Include <File.au3>

; create text file
$file = FileOpen("Scan.txt", 2)
FileWrite($file, "Result of Scan" & @CRLF)
FileWrite($file, "Running from:" & @DesktopDir & @CRLF)
FileWrite($file, "-------------------" & @CRLF)
; OS Versions,Arch,ServicePack
If @OSVersion = "WIN_XP" Then
    _OSXP()
ElseIf @OSVersion = "WIN_Vista" Then
    _OSVista()
ElseIf @OSVersion = "WIN_7" Then
    _OS7()
ElseIf @OSVersion = "WIN_8" Then
    FileWriteLine( $File, "Windows 8 " & @OSArch & @CRLF)
ElseIf @OSVersion = "WIN_8.1" Then
    FileWriteLine( $File, "Windows 8.1 " & @OSArch & @CRLF)
ElseIf @OSVersion = "WIN_10" Then
    FileWriteLine( $File, "Windows 10 " & @OSArch & @CRLF)

EndIf
; UAC on or off
Local $UAC = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLUA")
If $UAC <> 0 Then
    $UAC = "Enabled!"
Else
    $UAC = "Disabled!"
EndIf
 FileWrite($File, "UAC is " & $UAC & @CRLF)

Func _OSXP()
    If @OSServicePack <> "Service pack 3" Then
        FileWriteLine( $File, "Windows XP " & @OSArch &  "!Service Pack is out of date!")
    Else
        FileWriteLine( $File, "Windows XP " & @OSArch & " " & @OSServicePack & @CRLF)
EndIf
EndFunc
Func _OSVista()

    If @OSServicePack <> "Service pack 2" Then
        FileWriteLine( $File, "Windows Vista " & @OSArch &  "!Service Pack is out of date!")
    Else
        fileWriteLine( $File, "Windows Vista " & @OSArch & " " & @OSServicePack & @CRLF)
EndIf
EndFunc
Func _OS7()
    If @OSServicePack <> "Service pack 1"  Then
        FileWriteLine( $File, "Windows 7 " & @OSArch & " " & "!Service Pack is out of date!")
    Else
        FileWriteLine( $File, "Windows 7 " & @OSArch & " " & " " & @OSServicePack & @CRLF)
EndIf
EndFunc

FileClose($file)

 

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Another quick item ... I think "WIN_8.1" should be "WIN_81"

Returns one of the following: "WIN_81", "WIN_8", "WIN_7", "WIN_VISTA", "WIN_XP", "WIN_XPe",
    for Windows servers: "WIN_2012R2", "WIN_2012", "WIN_2008R2", "WIN_2008", "WIN_2003"".

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

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