Jump to content

My First User Defined Function


Syed23
 Share

Recommended Posts

Hi Friends,

This is my first function which i have created for my own process.This will work on both Windows 7 and Vista machines. This is to retrive the status of Bitlocker. Please check it on Vista or Windows 7 machine and let me know how it works.. Also let me know if i have to update my function :mellow:

#include-once 
;=============================================================================== 
; Description: Returns the Bitlocker status of the machine. 
; Parameter(s): $strComputer - By Reference - Computer name. 
; Requirement(s): None 
; Return Value(s): On Success - Returns "YES" or "EncryptionPercentage" or "NO". 
; Author : Syed Ibrahim 
; 
;=============================================================================== 
Func Bitlock($strComputer) 
Global $objItem,$protection, $ConversionStatus,$protectionstatus,$colItems,$objWMIService 
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption") 
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume", "WQL", 48) 
$protectionstatus = "NO" 
If IsObj($colItems) Then 
For $objItem In $colItems 
$objItem.GetProtectionStatus($protection) 
$objItem.GetConversionStatus ($ConversionStatus) 

If $protection = 1 Then 
$protectionstatus = "YES" 
ElseIf $ConversionStatus > 0 Then 
$protectionstatus = "EncryptionPercentage" 

EndIf 

ExitLoop 
Next 
EndIf 
Return $protectionstatus 
EndFunc 
;=============================================================================== 
; Description: Returns the TPM PIN status of the machine. 
; Parameter(s): $strComputer - By Reference - Computer name. 
; Return Value(s): On Success - Returns TRUE or FALSE. 
; =============================================================================== 
Func Pin($strComputer) 
Global $objWMIService, $colItems,$Return 

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption") 
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume", "WQL",48) 
$Return = -1 ; Result will return either 0 or 1. To get the change value assigning 
If IsObj($colItems) Then 
For $objItem in $colItems 
$objItem.IsKeyProtectorAvailable(4, $Return) 
Next 
EndIf 
Return $Return 
EndFunc

Example Script:

#RequireAdmin
#include"Bit.au3"
MsgBox(0,"Bitlocker Status",Bitlock(@ComputerName))

Note:

#RequireAdmin is mandatory inorder to work! :)

Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

  • Moderators

I assume this was intended for the Example Script Forum.

Moving.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Not sure that a global variable can be declared in local scope.

Yes is can. Not advised of course in relation to good coding practice.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Hi Friends,

Thanks for the suggesstions... But i am facing an issue in this! If i add this function and if i run it on XP machine i am facing below error. Can someone tell me why?

Variable must be of type "Object"

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

Please re-read the requirements of Win32_EncryptableVolume Class and have a look at _WinAPI_OSVersion() in WinAPIEx.au3 by Yashied to check if the OS is greater or equal to 6.0 or look at @OSVersion.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

Please re-read the requirements of Win32_EncryptableVolume Class and have a look at _WinAPI_OSVersion() in WinAPIEx.au3 by Yashied to check if the OS is greater or equal to 6.0 or look at @OSVersion.

i have added the @OSVERSION check on my main program Guinness.... But the think is not even it reaches that point i am getting the same error message.

Also i tried to use OBfuscator... but it shows me lot of error message on MY "SQL" , "WINAPI" and some other UDF's...... :mellow: i am going mad what going wron on my machine...

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

Here >> I'm using IsObj() to check it's an Object and you should've put @OSVersion at the start of the function.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include-once
;===============================================================================
; Description: Returns the Bitlocker status of the machine.
; Parameter(s): $sComputerName - By Reference - Computer name.
; Requirement(s): None
; Return Value(s): On Success - Returns "YES" or "EncryptionPercentage" or "NO".
; Author : Syed Ibrahim
;
;===============================================================================
Func Bitlock($sComputerName)
    Local $iConversionStatus, $iProtection, $oColItems, $oItem, $oWMIService, $sProtectionStatus
    $oWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\CIMV2\Security\MicrosoftVolumeEncryption")
    If IsObj($oWMIService) = 0 Then
        Return SetError(1, 0, -1)
    EndIf
    $oColItems = $oWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume", "WQL", 48)
    $sProtectionStatus = "NO"
    If IsObj($oColItems) Then
        For $oItem In $oColItems
            $oItem.GetProtectionStatus($iProtection)
            $oItem.GetConversionStatus($iConversionStatus)

            If $iProtection = 1 Then
                $sProtectionStatus = "YES"
            ElseIf $iConversionStatus > 0 Then
                $sProtectionStatus = "EncryptionPercentage"

            EndIf

            ExitLoop
        Next
    EndIf
    Return $sProtectionStatus
EndFunc   ;==>Bitlock

;===============================================================================
; Description: Returns the TPM PIN status of the machine.
; Parameter(s): $sComputerName - By Reference - Computer name.
; Return Value(s): On Success - Returns TRUE or FALSE.
; ===============================================================================
Func Pin($sComputerName)
    Local $oColItems, $oWMIService, $sReturn

    $oWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\CIMV2\Security\MicrosoftVolumeEncryption")
    If IsObj($oWMIService) = 0 Then
        Return SetError(1, 0, -1)
    EndIf
    $oColItems = $oWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume", "WQL", 48)
    $sReturn = -1 ; Result will return either 0 or 1. To get the change value assigning
    If IsObj($oColItems) Then
        For $oItem In $oColItems
            $oItem.IsKeyProtectorAvailable(4, $sReturn)
        Next
    EndIf
    Return $sReturn
EndFunc   ;==>Pin
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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