Jump to content

Recommended Posts

Would the code provided be ideal, or are there ways that I can improve the structure of my script? I'd appreciate any advice. I am enjoying learning as I go on, but I'm starting to find it hard to manage variables and occasionally run into variables being used before being declared. 

 

#RequireAdmin
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>
#include <TabConstants.au3>

Example()

Func ComputerInfo()
    ;Get Serial Number
    $wmiSN = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $wmiSN = (Get-WmiObject win32_bios).SerialNumber; $wmiSN", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
    ;Get Vendor
    $wmiVENDOR = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $wmiVENDOR = (Get-WMIObject Win32_ComputerSystemProduct).Vendor; $wmiVENDOR", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
    ;Get Model
    $cimMODEL = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimMODEL = (Get-CimInstance Win32_ComputerSystem).Model; $cimMODEL", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
    ;Get Caption
    $cimCAPTION = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimCAPTION = (Get-CimInstance Win32_OperatingSystem).Caption; $cimCAPTION", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
    ;Get Arch
    $cimARCH = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimARCH = (Get-CimInstance Win32_OperatingSystem).OSArchitecture; $cimARCH", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
    ;Get Version
    $cimVERSION = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimVERSION = (Get-CimInstance Win32_OperatingSystem).Version; $cimVERSION", @ScriptDir, @SW_HIDE, $STDERR_MERGED)

    ProcessWaitClose($wmiSN)
    Global $wmiSN2 = StdoutRead($wmiSN)

    ProcessWaitClose($wmiVENDOR)
    Global $wmiVENDOR2 = StdoutRead($wmiVENDOR)

    ProcessWaitClose($cimMODEL)
    Global $cimMODEL2 = StdoutRead($cimMODEL)

    ProcessWaitClose($cimCAPTION)
    Global $cimCAPTION2 = StdoutRead($cimCAPTION)

    ProcessWaitClose($cimARCH)
    Global $cimARCH2 = StdoutRead($cimARCH)

    ProcessWaitClose($cimVERSION)
    Global $cimVERSION2 = StdoutRead($cimVERSION)

EndFunc   ;==>ComputerInfo

Func _UserExists($sUsername)
    Return IsObj( ObjGet("WinNT://./" & $sUsername & ", user"))
EndFunc   ;==>_UserExists

Func _Randomize($Length)
    $charactersets = "0123456789" & "abcdefghijklmnopqrstuvwxyz" & "{}[]()/\'`~,;:.<>" & "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & "!@#$%^&*<>" & Chr(34)

    $Array = StringSplit($charactersets, "")

    $Pass = ""
    For $X = 1 To $Length
        $Pass &= $Array[Random(1, $Array[0], 1)]
    Next
    Global $Test = $Pass
    Return $Pass

EndFunc   ;==>_Randomize

Func EasterEgg()

    GUICtrlCreateTabItem("Easter Eggys")

    ; Content Goes Here.

    GUICtrlCreateTabItem("")

EndFunc   ;==>EasterEgg

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
;~  GUISetBkColor(0xFFFFFF)
    Local $idOK = GUICtrlCreateButton("OK", 300, 370, 95, 25)
;~  $Read_Char = 16
;~  _Randomize($Read_Char)

    Call("ComputerInfo")
    GUICtrlCreateGraphic(0, 0, 400, 55, 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlCreateGraphic(0, 2, 400, 2, 0)
    GUICtrlSetBkColor(-1, 0xF4AA00)
    GUICtrlCreateInput("OS Version: " & $cimCAPTION2 & " (" & $cimARCH2 & "), " & $cimVERSION2, 5, 5, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    Opt("GUICoordMode", 0)
    GUICtrlCreateInput("Model:      " & $cimMODEL2 & ", " & $wmiVENDOR2, 0, 15, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    GUICtrlCreateInput("Serial Number:  " & $wmiSN2, 0, 15, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    Opt("GUICoordMode", 1)
    GUICtrlCreateGraphic(0, 51, 400, 2, 0)
    GUICtrlSetBkColor(-1, 0xF4AA00)

    GUICtrlCreateTab(5, 60, 391, 305)

    GUICtrlCreateTabItem("Users")
    GUICtrlCreateGroup("ADD NEW USER", 10, 85, 187.5, 155, $BS_CENTER)
    Opt("GUICoordMode", 0)
    $inputUSER = GUICtrlCreateInput("USERNAME", 5, 15, 177.5, 20, $ES_CENTER)
    GUICtrlSetFont(-1, 10.5, 800, 0, "Consolas")
    $inputPASS = GUICtrlCreateInput("PASSWORD", 0, 25, 177.5, 20, BitOR($ES_PASSWORD, $ES_CENTER))
    GUICtrlSetFont(-1, 10.5, 800, 0, "Consolas")
    $userADMIN = GUICtrlCreateCheckbox("Make New User Admin", 0, 25, 177.5)
    GUICtrlSetFont(-1, 10.5, 400, 0)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $clrINPUT = GUICtrlCreateButton("Clear", 0, 25, 177.5, 25)
    $submitUSER = GUICtrlCreateButton("Submit", 0, 30, 177.5, 25)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    Opt("GUICoordMode", 1)

    GUICtrlCreateGroup("ITCS ACCOUNT", 202.5, 85, 187.5, 155, $BS_CENTER)
    Opt("GUICoordMode", 0)
    $userITCS = GUICtrlCreateInput("ITCS2", 5, 15, 177.5, 20, $ES_CENTER) ;BitOR($ES_READONLY, $ES_CENTER)
    GUICtrlSetFont(-1, 10.5, 800, 0, "Consolas")
    $passITCS = GUICtrlCreateInput("PASSWORD", 0, 25, 177.5, 20, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    GUICtrlSetFont(-1, 10.5, 800, 0, "Consolas")
    $passLENGTH = GUICtrlCreateInput("16", 0, 25, 25, 20, $ES_CENTER)
    GUICtrlSetFont(-1, 10.5, 800, 0, "Consolas")
    GUICtrlSetLimit($passLENGTH, 2, 1)
    $Read_Char = GUICtrlRead($passLENGTH)
    _Randomize($Read_Char)
    GUICtrlSetData($passITCS, _Randomize($Read_Char))
    $genNEWPASS = GUICtrlCreateButton("Generate New Password", 0, 25, 177.5, 25)
    $submitITCS = GUICtrlCreateButton("Submit", 0, 30, 177.5, 25)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    Opt("GUICoordMode", 1)

    GUICtrlCreateTabItem("Tools")

    GUICtrlCreateGroup("DISM", 10, 85, 95, 140, $BS_CENTER)
    Opt("GUICoordMode", 0)
    Local $dismCH = GUICtrlCreateButton("CheckHealth", 5, 15, 85, 25)
    Local $dismSH = GUICtrlCreateButton("ScanHealth", -1, 30, 85, 25)
    Local $dismRH = GUICtrlCreateButton("RestoreHealth", -1, 30, 85, 25)
    Local $dismABT = GUICtrlCreateButton("About DISM", -1, 30, 85, 25)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    Opt("GUICoordMode", 1)

    GUICtrlCreateTabItem("")

    $easterEGG = GUICtrlCreateLabel("", 0, 390, 10, 10)
;~  GUICtrlSetBkColor(-1, 0xF4AA00)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop
            Case $dismCH
                Run(@ComSpec & " /c " & "DISM /Online /Cleanup-Image /CheckHealth" & " & ECHO. & ECHO Press any button to continue. & pause>nul", "")
            Case $dismSH
                Run(@ComSpec & " /c " & "DISM /Online /Cleanup-Image /ScanHealth" & " & ECHO. & ECHO Press any button to continue. & pause>nul", "")
            Case $dismRH
                Run(@ComSpec & " /c " & "DISM /Online /Cleanup-Image /RestoreHealth", "")
            Case $dismABT
                MsgBox(0, "About DISM", "DISM CheckHealth - The CheckHealth option with the Deployment Image Servicing and Management command tool allows you quickly determine if there are any corruptions inside the local Windows 10 image. However, the option does not perform any repairs." & @CRLF & @CRLF & "DISM ScanHealth - The ScanHealth option performs a more advanced scan to determine if the OS image has any problems." & @CRLF & @CRLF & "DISM RestoreHealth - If there are problems with the system image, you can use DISM with the RestoreHealth option to scan and repair common issues automatically.")
            Case $genNEWPASS
                $Read_Char = GUICtrlRead($passLENGTH)
                GUICtrlSetData($passITCS, _Randomize($Read_Char))
            Case $clrINPUT
                GUICtrlSetData($inputUSER, "")
                GUICtrlSetData($inputPASS, "")
                GUICtrlSetState($userADMIN, 1)
            Case $submitUSER
                Run(@ComSpec & "/c " & "net user " & GUICtrlRead($inputUSER) & ' "' & GUICtrlRead($inputPASS) & '" ' & "/add", "", @SW_HIDE)
                If GUICtrlRead($userADMIN) = $GUI_CHECKED Then
                    Run(@ComSpec & "/c " & "net localgroup administrators " & GUICtrlRead($inputUSER) & " /add" & " && " & "ping 127.0.0.1 -n 5 > nul", "", @SW_HIDE)
                EndIf
             Case $submitITCS
                If _UserExists(GUICtrlRead($userITCS)) Then
                    RunWait(@ComSpec & "/c " & "net user " & GUICtrlRead($userITCS) & ' "' & GUICtrlRead($passITCS) & '"', "", @SW_HIDE)
                Else
                    RunWait(@ComSpec & "/c " & "net user " & GUICtrlRead($userITCS) & ' "' & GUICtrlRead($passITCS) & '" ' & "/add", "", @SW_HIDE)
                    RunWait(@ComSpec & "/c " & "net localgroup administrators " & GUICtrlRead($userITCS) & " /add" & " && " & "ping 127.0.0.1 -n 5 > nul", "", @SW_HIDE)
                EndIf
            Case $GUI_EVENT_PRIMARYUP
                If _WinAPI_GetFocus() = GUICtrlGetHandle($inputUSER) And GUICtrlRead($inputUSER) = "USERNAME" Then
                    GUICtrlSetData($inputUSER, "")
                ElseIf _WinAPI_GetFocus() = GUICtrlGetHandle($inputPASS) And GUICtrlRead($inputPASS) = "PASSWORD" Then
                    GUICtrlSetData($inputPASS, "")
                EndIf
            Case $easterEGG
;~              GUICtrlCreateTabItem("Easter Egg")
                Call("EasterEgg")
                GUICtrlSetPos($easterEGG, -100, -100, 0, 0)
        EndSwitch

    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Link to post
Share on other sites

@ReconX

Use Opt("MustDeclareVars", 1) for the variables declaration, so you must declare every variable the script uses, or it will throw an error.

For the script improvements, in the function ComputerInfo() you could use WMI object instead of run powershell commands, so you delete the part of StdoutRead() and ProcessWaitClose().

For the function _Randomize(), you could use Chr() function in a For Loop instead of having a predefined subset of chars (and you did repeat <> as well).

You may use something like this (untested):

For $i = 1 To $intPasswordLenght Step 1
   $strPassword &= Chr(Random(33, 126, 1))
Next

Obviousely, in this case you include few more chars than you did in your chars subset, but it shorten the code a little bit :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to post
Share on other sites
3 hours ago, FrancescoDiMuro said:

For the script improvements, in the function ComputerInfo() you could use WMI object instead of run powershell commands ...

I agree :)

@ReconX : Take a look at the system-scan-report-tool made by @spudw2k . There you will find useful code parts regarding WMI.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * for other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-10-18

Link to post
Share on other sites
40 minutes ago, mLipok said:

Yes, that would be the hardcore option :lol:. Sometimes a bit annoying, but usually a good help.

@ReconX : You can find a complete description here:  https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/au3check.html

The parameter -d also sets the "MustDeclareVars" option to True

During development, however, I would leave out the parameter  -w 5  (gives a warning if a local variable is declared but not used). In an early stage it is not uncommon to declare local variables without using them immediately. The warnings can be a bit disturbing then. By the end of the project you can set the parameter to find and get rid of unused local variables.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
  • 4 weeks later...
Posted (edited)

I'm just recently seeing the responses. Thank you all so much for the advice. I've been super busy this past month. 

@Musashi It seems as if this is a bit outdated and not functioning as intended. The results in their example are shown as blank. I used PowerShell because I recently read that WMI is becoming obsolete. I cannot remember where I read this, but I did read it. 

@mLipok Are these the arguments that are ran when pressing Ctrl + F5? If not, I'm unsure what to do with this. I do see the file Au3Check in the AutoIt directory.  😅

Edited by ReconX
Link to post
Share on other sites
11 hours ago, ReconX said:

Are these the arguments that are ran when pressing Ctrl + F5? If not, I'm unsure what to do with this. I do see the file Au3Check in the AutoIt directory.

Yes.
It is used when you press CTRL+F5 but also when you use F5 or even F7

But you must use SciTE4AutoIt3

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * for other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-10-18

Link to post
Share on other sites

 

12 hours ago, ReconX said:

It seems as if this is a bit outdated and not functioning as intended.

You surely refer to the system-scan-report-tool made by @spudw2k , that I mentioned. It is true, that the tool throws various messages during compilation, such as : ! Obfuscator support has been discontinued and is replaced by Au3Stripper using "#Au3Stripper_" directives.

This can be easily prevented by commenting out or removing the compiler directives regarding the deprecated obfuscator.

[...]
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/cs=0 /cn=0 /cf=0 /cv=0 /sf=1 /sv=1
[...]

The tool itself works without problems on my system (Win7 SP1 64-bit). Since the last revision was on April 8, 2019, it should also work on Win10.

 

12 hours ago, ReconX said:

I used PowerShell because I recently read that WMI is becoming obsolete. I cannot remember where I read this, but I did read it. 

I'm sure, everything is fine with the WMI Classes (and this will remain so in the future).

Here is an interesting thread that probably sheds some light on the darkness : wmi-diagnosis-tool-no-more-available (the additional links are also worth reading).

I hope these Infos are helpful to you (and other users) :).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

Readable version of your script, without the changes suggested by others, and without how I would have written it.

#RequireAdmin
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>
#include <TabConstants.au3>

Example()

Func ComputerInfo()
    ;Get Serial Number
    $wmiSN = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe _
                  -Command $wmiSN = (Get-WmiObject win32_bios).SerialNumber; $wmiSN", _
                  @ScriptDir, _
                  @SW_HIDE, _
                  $STDERR_MERGED)
    ;Get Vendor
    $wmiVENDOR = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe _
                     -Command $wmiVENDOR = (Get-WMIObject Win32_ComputerSystemProduct).Vendor; $wmiVENDOR", _
                     @ScriptDir, _
                     @SW_HIDE, _
                     $STDERR_MERGED)
    ;Get Model
    $cimMODEL = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe _
                     -Command $cimMODEL = (Get-CimInstance Win32_ComputerSystem).Model; $cimMODEL", _
                     @ScriptDir, _
                     @SW_HIDE, _
                     $STDERR_MERGED)
    ;Get Caption
    $cimCAPTION = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe _
                     -Command $cimCAPTION = (Get-CimInstance Win32_OperatingSystem).Caption; $cimCAPTION", _
                     @ScriptDir, _
                     @SW_HIDE, _
                     $STDERR_MERGED)
    ;Get Arch
    $cimARCH = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe _
                     -Command $cimARCH = (Get-CimInstance Win32_OperatingSystem).OSArchitecture; $cimARCH", _
                     @ScriptDir, _
                     @SW_HIDE, _
                     $STDERR_MERGED)
    ;Get Version
    $cimVERSION = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe _
                     -Command $cimVERSION = (Get-CimInstance Win32_OperatingSystem).Version; $cimVERSION", _
                     @ScriptDir, _
                     @SW_HIDE, _
                     $STDERR_MERGED)

    ProcessWaitClose($wmiSN)
    Global $wmiSN2 = StdoutRead($wmiSN)

    ProcessWaitClose($wmiVENDOR)
    Global $wmiVENDOR2 = StdoutRead($wmiVENDOR)

    ProcessWaitClose($cimMODEL)
    Global $cimMODEL2 = StdoutRead($cimMODEL)

    ProcessWaitClose($cimCAPTION)
    Global $cimCAPTION2 = StdoutRead($cimCAPTION)

    ProcessWaitClose($cimARCH)
    Global $cimARCH2 = StdoutRead($cimARCH)

    ProcessWaitClose($cimVERSION)
    Global $cimVERSION2 = StdoutRead($cimVERSION)

EndFunc   ;==>ComputerInfo

Func _UserExists($sUsername)
    Return IsObj( ObjGet("WinNT://./" & $sUsername & ", user"))
EndFunc   ;==>_UserExists

Func _Randomize($Length)
    $charactersets = "0123456789" & "abcdefghijklmnopqrstuvwxyz" & "{}[]()/\'`~,;:.<>" & "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & "!@#$%^&*<>" & Chr(34)

    $Array = StringSplit($charactersets, "")

    $Pass = ""
    For $X = 1 To $Length
        $Pass &= $Array[Random(1, $Array[0], 1)]
    Next
    Global $Test = $Pass
    Return $Pass

EndFunc   ;==>_Randomize

Func EasterEgg()

    GUICtrlCreateTabItem("Easter Eggys")

    ; Content Goes Here.

    GUICtrlCreateTabItem("")

EndFunc   ;==>EasterEgg

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
;~  GUISetBkColor(0xFFFFFF)
    Local $idOK = GUICtrlCreateButton("OK", 300, 370, 95, 25)
;~  $Read_Char = 16
;~  _Randomize($Read_Char)

    Call("ComputerInfo")
    GUICtrlCreateGraphic(0, 0, 400, 55, 0)
    GUICtrlSetBkColor   (-1, 0x660000)
    GUICtrlCreateGraphic(0, 2, 400, 2, 0)
    GUICtrlSetBkColor   (-1, 0xF4AA00)
    GUICtrlCreateInput  ("OS Version: " & $cimCAPTION2 & " (" & $cimARCH2 & "), " & $cimVERSION2, 5, 5, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor   (-1, 0x660000)
    GUICtrlSetColor     (-1, 0xFFFFFF)
    GUICtrlSetFont      (-1, 8.5, 800, 0)
    
    Opt("GUICoordMode", 0)
    GUICtrlCreateInput("Model:      " & $cimMODEL2 & ", " & $wmiVENDOR2, 0, 15, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor (-1, 0x660000)
    GUICtrlSetColor   (-1, 0xFFFFFF)
    GUICtrlSetFont    (-1, 8.5, 800, 0)
    GUICtrlCreateInput("Serial Number:  " & $wmiSN2, 0, 15, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor (-1, 0x660000)
    GUICtrlSetColor   (-1, 0xFFFFFF)
    GUICtrlSetFont    (-1, 8.5, 800, 0)
    
    Opt("GUICoordMode", 1)
    GUICtrlCreateGraphic(0, 51, 400, 2, 0)
    GUICtrlSetBkColor   (-1, 0xF4AA00)

    GUICtrlCreateTab(5, 60, 391, 305)

    GUICtrlCreateTabItem("Users")
    GUICtrlCreateGroup  ("ADD NEW USER", 10, 85, 187.5, 155, $BS_CENTER)
    
    Opt("GUICoordMode", 0)
    $inputUSER  = GUICtrlCreateInput   ("USERNAME", 5, 15, 177.5, 20, $ES_CENTER)
                  GUICtrlSetFont       (-1, 10.5, 800, 0, "Consolas")
    $inputPASS  = GUICtrlCreateInput   ("PASSWORD", 0, 25, 177.5, 20, BitOR($ES_PASSWORD, $ES_CENTER))
                  GUICtrlSetFont       (-1, 10.5, 800, 0, "Consolas")
    $userADMIN  = GUICtrlCreateCheckbox("Make New User Admin", 0, 25, 177.5)
                  GUICtrlSetFont       (-1, 10.5, 400, 0)
                  GUICtrlSetState      (-1, $GUI_CHECKED)
    $clrINPUT   = GUICtrlCreateButton  ("Clear", 0, 25, 177.5, 25)
    $submitUSER = GUICtrlCreateButton  ("Submit", 0, 30, 177.5, 25)
                  GUICtrlCreateGroup   ("", -99, -99, 1, 1) ;close group
                  
    Opt("GUICoordMode", 1)
    GUICtrlCreateGroup("ITCS ACCOUNT", 202.5, 85, 187.5, 155, $BS_CENTER)
    
    Opt("GUICoordMode", 0)
    $userITCS   = GUICtrlCreateInput("ITCS2", 5, 15, 177.5, 20, $ES_CENTER) ;BitOR($ES_READONLY, $ES_CENTER)
                  GUICtrlSetFont    (-1, 10.5, 800, 0, "Consolas")
    $passITCS   = GUICtrlCreateInput("PASSWORD", 0, 25, 177.5, 20, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
                  GUICtrlSetFont    (-1, 10.5, 800, 0, "Consolas")
    $passLENGTH = GUICtrlCreateInput("16", 0, 25, 25, 20, $ES_CENTER)
                  GUICtrlSetFont    (-1, 10.5, 800, 0, "Consolas")
                  GUICtrlSetLimit   ($passLENGTH, 2, 1)
    $Read_Char  = GUICtrlRead       ($passLENGTH)
    
    _Randomize($Read_Char)
    
                  GUICtrlSetData($passITCS, _Randomize($Read_Char))
    $genNEWPASS = GUICtrlCreateButton("Generate New Password", 0, 25, 177.5, 25)
    $submitITCS = GUICtrlCreateButton("Submit", 0, 30, 177.5, 25)
                  GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
                  
    Opt("GUICoordMode", 1)
    GUICtrlCreateTabItem("Tools")
    GUICtrlCreateGroup("DISM", 10, 85, 95, 140, $BS_CENTER)
    
    Opt("GUICoordMode", 0)
    Local $dismCH  = GUICtrlCreateButton("CheckHealth", 5, 15, 85, 25)
    Local $dismSH  = GUICtrlCreateButton("ScanHealth", -1, 30, 85, 25)
    Local $dismRH  = GUICtrlCreateButton("RestoreHealth", -1, 30, 85, 25)
    Local $dismABT = GUICtrlCreateButton("About DISM", -1, 30, 85, 25)
                     GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
                     
    Opt("GUICoordMode", 1)
    GUICtrlCreateTabItem("")

    $easterEGG = GUICtrlCreateLabel("", 0, 390, 10, 10)
;~  GUICtrlSetBkColor(-1, 0xF4AA00)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
           
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop
                
            Case $dismCH
                Run(@ComSpec & " /c " & "DISM /Online /Cleanup-Image /CheckHealth" & " & ECHO. & ECHO Press any button to continue. & pause>nul", "")
                
            Case $dismSH
                Run(@ComSpec & " /c " & "DISM /Online /Cleanup-Image /ScanHealth" & " & ECHO. & ECHO Press any button to continue. & pause>nul", "")
                
            Case $dismRH
                Run(@ComSpec & " /c " & "DISM /Online /Cleanup-Image /RestoreHealth", "")
                
            Case $dismABT
                MsgBox(0, "About DISM", "DISM CheckHealth - The CheckHealth option with the Deployment Image Servicing and Management command tool allows you quickly determine if there are any corruptions inside the local Windows 10 image. However, the option does not perform any repairs." & @CRLF & @CRLF & "DISM ScanHealth - The ScanHealth option performs a more advanced scan to determine if the OS image has any problems." & @CRLF & @CRLF & "DISM RestoreHealth - If there are problems with the system image, you can use DISM with the RestoreHealth option to scan and repair common issues automatically.")
                
            Case $genNEWPASS
                $Read_Char = GUICtrlRead($passLENGTH)
                GUICtrlSetData($passITCS, _Randomize($Read_Char))
                
            Case $clrINPUT
                GUICtrlSetData($inputUSER, "")
                GUICtrlSetData($inputPASS, "")
                GUICtrlSetState($userADMIN, 1)
                
            Case $submitUSER
                Run(@ComSpec & "/c " & "net user " & GUICtrlRead($inputUSER) & ' "' & GUICtrlRead($inputPASS) & '" ' & "/add", "", @SW_HIDE)
                If GUICtrlRead($userADMIN) = $GUI_CHECKED Then
                    Run(@ComSpec & "/c " & "net localgroup administrators " & GUICtrlRead($inputUSER) & " /add" & " && " & "ping 127.0.0.1 -n 5 > nul", "", @SW_HIDE)
                 EndIf
                 
             Case $submitITCS
                If _UserExists(GUICtrlRead($userITCS)) Then
                    RunWait(@ComSpec & "/c " & "net user " & GUICtrlRead($userITCS) & ' "' & GUICtrlRead($passITCS) & '"', "", @SW_HIDE)
                Else
                    RunWait(@ComSpec & "/c " & "net user " & GUICtrlRead($userITCS) & ' "' & GUICtrlRead($passITCS) & '" ' & "/add", "", @SW_HIDE)
                    RunWait(@ComSpec & "/c " & "net localgroup administrators " & GUICtrlRead($userITCS) & " /add" & " && " & "ping 127.0.0.1 -n 5 > nul", "", @SW_HIDE)
                 EndIf
                 
            Case $GUI_EVENT_PRIMARYUP
                If _WinAPI_GetFocus() = GUICtrlGetHandle($inputUSER) And GUICtrlRead($inputUSER) = "USERNAME" Then
                    GUICtrlSetData($inputUSER, "")
                ElseIf _WinAPI_GetFocus() = GUICtrlGetHandle($inputPASS) And GUICtrlRead($inputPASS) = "PASSWORD" Then
                    GUICtrlSetData($inputPASS, "")
                 EndIf
                 
            Case $easterEGG
;~              GUICtrlCreateTabItem("Easter Egg")
                Call("EasterEgg")
                GUICtrlSetPos($easterEGG, -100, -100, 0, 0)
                
        EndSwitch

    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Some guy's script + some other guy's script = my script!

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...