Sign in to follow this  
Followers 0
krboun

help with UDFs

10 posts in this topic

hello

i am still quite new in autoit and also in programming ( i am autodidact wiht autoit help)

i want make some encryption scrip where private key is based on motherboard serial nuber, but that is not my point.

I found but i dont understand how to call that functions

there is a function:

_ComputerGetMotherboard

and i dont know how to call it in my script if i want to return DeviceID

many thanks

Share this post


Link to post
Share on other sites



krboun,

Download the CompInfo.au3 file from the topic and put it in the same folder as your script. Add #include "CompInfo.au3" to the top of your script and then call the function just like any other. :)

If you want to be really smart, you can create your own include folder. The Adding UDFs to AutoIt and SciTE tutorial in the Wiki shows you how. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

thakns but that is not what i need, i know i have to include CompInfo.au3. My problem is that i dont understand how to call function

;===============================================================================
; Description:    Returns the Motherboard information in an array.
; Parameter(s):  $aMotherboardInfo - By Reference - Motherboard Information array.
; Requirement(s):   None
; Return Value(s):  On Success - Returns array of Motherboard Information.
;     $aMotherboardInfo[$i][0] = Name
;     $aMotherboardInfo[$i][1] = Availability
;     $aMotherboardInfo[$i][2] = ConfigManagerErrorCode
;     $aMotherboardInfo[$i][3] = ConfigManagerUserConfig
;     $aMotherboardInfo[$i][4] = Description
;     $aMotherboardInfo[$i][5] = CreationClassName
;     $aMotherboardInfo[$i][6] = DeviceID
;     $aMotherboardInfo[$i][7] = ErrorCleared
;     $aMotherboardInfo[$i][8] = ErrorDescription
;     $aMotherboardInfo[$i][9] = LastErrorCode
;     $aMotherboardInfo[$i][10] = PNPDeviceID
;     $aMotherboardInfo[$i][11] = PowerManagementCapabilities
;     $aMotherboardInfo[$i][12] = PowerManagementSupported
;     $aMotherboardInfo[$i][13] = PrimaryBusType
;     $aMotherboardInfo[$i][14] = RevisionNumber
;     $aMotherboardInfo[$i][15] = SecondaryBusType
;     $aMotherboardInfo[$i][16] = Status
;     $aMotherboardInfo[$i][17] = StatusInfo
;     $aMotherboardInfo[$i][18] = SystemCreationClassName
;     $aMotherboardInfo[$i][19] = SystemName
;                  On Failure - @error = 1 and Returns 0
;       @extended = 1 - Array contains no information.
;          2 - $colItems isnt an object.
; Author(s):        Jarvis Stubblefield (support "at" vortexrevolutions "dot" com)
; Note(s):
;===============================================================================
Func _ComputerGetMotherboard(ByRef $aMotherboardInfo)
Local $colItems, $objWMIService, $objItem
Dim $aMotherboardInfo[1][20], $i = 1[/i]
[i]$objWMIService = ObjGet("winmgmts:" & $cI_Compname & "rootCIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_MotherboardDevice", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)[/i]
[i]If IsObj($colItems) Then
  For $objItem In $colItems
   ReDim $aMotherboardInfo[UBound($aMotherboardInfo) + 1][20]
   $aMotherboardInfo[$i][0] = $objItem.Name
   $aMotherboardInfo[$i][1] = $objItem.Availability
   $aMotherboardInfo[$i][2] = $objItem.ConfigManagerErrorCode
   $aMotherboardInfo[$i][3] = $objItem.ConfigManagerUserConfig
   $aMotherboardInfo[$i][4] = $objItem.Description
   $aMotherboardInfo[$i][5] = $objItem.CreationClassName
   $aMotherboardInfo[$i][6] = $objItem.DeviceID
   $aMotherboardInfo[$i][7] = $objItem.ErrorCleared
   $aMotherboardInfo[$i][8] = $objItem.ErrorDescription
   $aMotherboardInfo[$i][9] = $objItem.LastErrorCode
   $aMotherboardInfo[$i][10] = $objItem.PNPDeviceID
   $aMotherboardInfo[$i][11] = $objItem.PowerManagementCapabilities(0)
   $aMotherboardInfo[$i][12] = $objItem.PowerManagementSupported
   $aMotherboardInfo[$i][13] = $objItem.PrimaryBusType
   $aMotherboardInfo[$i][14] = $objItem.RevisionNumber
   $aMotherboardInfo[$i][15] = $objItem.SecondaryBusType
   $aMotherboardInfo[$i][16] = $objItem.Status
   $aMotherboardInfo[$i][17] = $objItem.StatusInfo
   $aMotherboardInfo[$i][18] = $objItem.SystemCreationClassName
   $aMotherboardInfo[$i][19] = $objItem.SystemName
   $i += 1
  Next
  $aMotherboardInfo[0][0] = UBound($aMotherboardInfo) - 1
  If $aMotherboardInfo[0][0] < 1 Then
   SetError(1, 1, 0)
  EndIf
Else
  SetError(1, 2, 0)
EndIf
EndFunc ;_ComputerGetMotherboard

i have to call something like

$xxx =  _ComputerGetMotherboard(.....) ;i do not understand which paramete i should use if i want deviceID
msgbox(0,"",$xxx)

i am still quite confused with so sophisticated scripts :)

Edited by krboun

Share this post


Link to post
Share on other sites

krboun,

Apologies - I did think it a bit strange that you were asking such a simple question! ;)

As I read the function, you need to declare an array beforehand which is then filled by the functions - just like _FileReadToArray. So I think you need to to do this:

; Declare the array
Global $aMotherboardInfo

; Call the function telling it which array to use
_ComputerGetMotherboard($aMotherboardInfo)

; Now the array is filled and you can see it
_ArrayDisplay($aMotherboardInfo)

Give that a try. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

perfect #Include <Array.au3> must be there ;)

i see this is not what i was looking for, but i learned new thing :)

by teh way, coul you explain me the difference

func a()
func b(byref)
func c(const)

sometimes i understand complicated stuff but siple stuff i don´t see, i should start to learn systematicaly

Share this post


Link to post
Share on other sites

Melba, your array declaration statement isn't right, it has to be declared as an array first before sending it to the function, you have it declared as a standard variable, not an array.


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

krboun,

When you call a function in AutoIt, you can pass parameters to the function by including them in the parentheses following the function name like this - Function(Parameter_1, Parameter_2). Note that the parameters are automatically declared as Local variables within the called function and so do not need to be declared again in the code.

Variables can be passed as parameters to a function in 2 ways:

By Value - This is the default. The parameter is treated as a Local variable within the function to which it is passed and any changes made to it are lost when the function ends. So no changes are made to the original variable if it happens to have the same name.

By Reference - This is used when ByRef is added BEFORE the variable name in the parameter list of the function declaration. Now any changes to the variable made in the function to which it is passed also affect the original variable.

I have never seen Func(const) and cannot imagine why you would want to use it. :)

You might find it useful to read the Variables - using Global, Local and ByRef tutorial in the Wiki. I cut and pasted part of it above and there are several examples to help you understand. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

BrewManNH,

Have you tried my code? Obviously not, as it works perfectly - I do test things before posting you know. :D

If you look at the _ComputerGetMotherboard function inside CompInfo.au3, one of the first things it does is:

Dim $aMotherboardInfo[1][20]

which declares that variable as an array. So there is no need to declare the variable as an array beforehand. ;)

Personally I prefer functions which return an array that you can assign to a variable, but both approaches are valid. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

My apologies, I missed the Dim statement, I only saw the ReDim a few lines later in the function.


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

BrewManNH,

No problem. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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