Computer Inventory with AutoIT - Inventory Page 3

Article Index


func checkinternet()
    $x = 0
    While $x = 0
        ;--------------------------------------------------------------------------------------------
        ;check $ret[0] for trueness, and $ret[1] for type of connection according to variables provided...
        ;--------------------------------------------------------------------------------------------
        $INTERNET_CONNECTION_MODEM          = 0x1
        $INTERNET_CONNECTION_LAN            = 0x2
        $INTERNET_CONNECTION_PROXY          = 0x4
        $INTERNET_CONNECTION_MODEM_BUSY     = 0x8
        $INTERNET_RAS_INSTALLED             = 0x10
        $INTERNET_CONNECTION_OFFLINE        = 0x20
        $INTERNET_CONNECTION_CONFIGURED     = 0x40
 
        $ret = DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)
 
        If $ret[0] then
            ;check type of connection
            $sX = "Connected !" & @LF & "------------------" & @LF
            If BitAND($ret[1], $INTERNET_CONNECTION_MODEM)      Then $sX = $sX & "MODEM" & @LF
            If BitAND($ret[1], $INTERNET_CONNECTION_LAN)        Then $sX = $sX & "LAN" & @LF
            If BitAND($ret[1], $INTERNET_CONNECTION_PROXY)      Then $sX = $sX & "PROXY" & @LF
            If BitAND($ret[1], $INTERNET_CONNECTION_MODEM_BUSY) Then $sX = $sX & "MODEM_BUSY" & @LF
            If BitAND($ret[1], $INTERNET_RAS_INSTALLED)         Then $sX = $sX & "RAS_INSTALLED" & @LF
            If BitAND($ret[1], $INTERNET_CONNECTION_OFFLINE)    Then $sX = $sX & "OFFLINE" & @LF
            If BitAND($ret[1], $INTERNET_CONNECTION_CONFIGURED) Then $sX = $sX & "CONFIGURED" & @LF
        Else
            $x = 0
            MsgBox(0,"Not Connected","Please connect to the internet before continuing.")
            ;$sX = "Not Connected"
            ContinueLoop
 
        Endif
 
        ;SplashTextOn("Connected...","Connection Detected",200,100)
        ;sleep (1000)
        ;SplashOff()
        $x=1
        ;MsgBox(4096,$ret[0] & ":" & $ret[1],$sX)
 
     WEnd
 
EndFunc
 
func calcgb($pathtxt,$str2src)
    if $str2src = 1 Then
        $str2srcname = "TotalPhysicalMemory="
        $str2len = 20
        $str2dec = 3
    Else
        $str2srcname = "Size="
        $str2len = 5
        $str2dec = 0
    EndIf
 
    $filepk=($pathtxt)
    $fopnpk = FileOpen($filepk,$FO_APPEND)
    ; ---------MAYBE------------
    ; Check the drive type for C:\
    $sInfo = DriveGetType("C:\")
    if $sInfo <> "" Then
        ;MsgBox($MB_SYSTEMMODAL, "", "Drive Type: " & $sInfo)
        ;write a line
        FileWrite ($fopnpk,@CRLF&@CRLF&"Drive Type="&$sInfo&@CRLF&@CRLF&@CRLF)
    EndIf
    ; Check the SSD status for C:\
    $sInfo = DriveGetType("C:\", $DT_SSDSTATUS)
    if $sInfo <> "" Then
        ;MsgBox($MB_SYSTEMMODAL, "", "Drive SSD: " & $sInfo)
        ;write a line
        FileWrite ($fopnpk,@CRLF&@CRLF&"Drive Type (SSD)="&$sInfo&@CRLF&@CRLF&@CRLF)
    EndIf
    ; Check the SSD status for disk 0
    $sInfo = DriveGetType(0, $DT_SSDSTATUS)
    if $sInfo <> "" Then
        ;MsgBox($MB_SYSTEMMODAL, "", "Drive SSD: " & $sInfo)
        ;write a line
        FileWrite ($fopnpk,@CRLF&@CRLF&"Drive Status (SSD)="&$sInfo&@CRLF&@CRLF&@CRLF)
    EndIf
    ; Check the bus type status for disk 0
    $sInfo = DriveGetType(0, $DT_BUSTYPE)
    if $sInfo <> "" Then
        ;MsgBox($MB_SYSTEMMODAL, "", "Drive Bus: " & $sInfo)
        ;write a line
        FileWrite ($fopnpk,@CRLF&@CRLF&"Drive Bus="&$sInfo&@CRLF&@CRLF&@CRLF)
    EndIf
 
    Local $iTotalSpace = DriveSpaceTotal(@HomeDrive & "\") ; Find the total disk space of the home drive, generally this is the C:\ drive.
    $TotalSpace = round($iTotalSpace/1000,$str2dec)
    ; MsgBox(0, "", "Total Space: " & $TotalSpace &"GB")
    FileWrite ($fopnpk,@CRLF&@CRLF&"Total Disk Space="&$TotalSpace&" GB"&@CRLF&@CRLF&@CRLF)
 
    Local $RAMARR = MemGetStats()
    $TotalRAM = round($RAMARR[1]/1000000,$str2dec)
    ;MsgBox(0, "", "Total physical RAM (GB): " & $TotalRAM)
    FileWrite ($fopnpk,@CRLF&@CRLF&"Total RAM="&$TotalRAM&" GB"&@CRLF&@CRLF&@CRLF)
 
    FileClose($fopnpk)
 
EndFunc
 
func addproductid($pathtxt)
    $productkey = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS\","SystemSKU")
    ;MsgBox (0,"TTT",$productkey)
    if $productkey = "" Then
        $productkey = "Not Found"
    EndIf
    $filepk=($pathtxt)
    $fopnpk = FileOpen($filepk,$FO_APPEND)
    FileWrite ($fopnpk,@CRLF&@CRLF&"Product Key="&$productkey&@CRLF&@CRLF&@CRLF)
    FileClose($fopnpk)
EndFunc
 
; The UDF
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
;~          ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/senduasing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
EndFunc   ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc