AU3 "FAQ Book" Beginners must-see

AU3 "FAQ Book" Beginners must-see

 


Q1 How to debug a script?

MsgBox(0,"测试",$var)
ConsoleWrite("var=" & $var & @CRLF)

Q2 operating CMD command related to
how Q2.1 run DOS commands?

Run(@ComSpec & ' /c dir>d:\dir.txt',"", @SW_HIDE)

#include
$rc = _RunDos("start [url]Http://www.18883.com[/url]")

How to run DOS commands Q2.2 connection AU3 variable?

Local $var="d:\dir.txt"
Run(@ComSpec & ' /c dir>"'&$var&'"',"", @SW_HIDE)

How Q2.3 run DOS commands automatically answer? (Note: this is not a problem AU3, incidental talk about here.)

RunWait(@ComSpec & ' /c echo y|cacls %systemroot%\system32\wpcap.dll /d everyone',

@SystemDir, @SW_HIDE)

Q2.4 multi-layer DOS command How? As netsh, diskpart like.

DNS = $ "192.168.0.1"
RunWait (@ComSpec & '/ C the netsh -C SET DNS IP interface connected to the local source = static addr = "' & $ dns

&'" register=PRIMARY ',"", @SW_HIDE )

How to run DOS commands directly Q2.5 interception echo?

;注意:回显截取只支持Run而不是RunWait
#include
Opt("MustDeclareVars",1)
_test()
Func _test()
Local $foo,$line,$lines
$foo = Run(@ComSpec & " /c sc query Alerter", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
$lines = ""
While 1
$line = StdoutRead($foo)
If @error Then ExitLoop
$lines &= $line
Wend
MsgBox(0,"test",$lines)
EndFunc

Q3 How to prevent duplicate program run?

$g_szVersion = "test"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)

#include
_Singleton("test")

How Q4 direct file system runs the associated program? Such as [.txt, .msi, .pdf, .jpg, .lnk, .msc] and so on! ! !

ShellExecute("Notepad.exe")
ShellExecute("test.txt", "", @ScriptDir, "edit")
ShellExecute("http://www.autoit.net.cn")
ShellExecute("C:\boot.ini", "", "", "print")
ShellExecute("test.lnk","",@ScriptDir)
ShellExecute("gpedit.msc", "", "", "open", @SW_MAXIMIZE)
Q5 如何控制系统服务?

API control service
_StartService () to start the service
_StopService () to stop the service
_ServiceExists () testing services
_ServiceRunning () to run the service
_CreateService () establishing service
_DeleteService () to delete the service
WMI Control Service
_ServStart () to start the service
_ServStop () to stop the service
_ServDelete ( ) delete service
_ServGetDetails () service details
_ServGetState () service state
_ServListInstalled () service list
_ServPause () to suspend service
_ServResume () service renamed
_SerSetState () set the service status

 

Q6 How to operate the registry?

Q6.1 common registry settings

; Read the registry value specified by
$ var = RegRead ( "HKEY_LOCAL_MACHINE \ SOFTWARE \ in the Microsoft \ Windows \ CurrentVersion", "the ProgramFilesDir")
MsgBox (4096, "Program Files folder is located at:", $ var)
; create a primary key, sub-key or value entry.
RegWrite ( "HKEY_LOCAL_MACHINE \ SOFTWARE \ the Test", "TestKey", "REG_SZ", "the Hello the this the Test IS A")
; delete the registry specified value (note: this is the key to delete the item, rather than a key)
RegDelete ( "HKEY_LOCAL_MACHINE \ SOFTWARE", "TestKey")
; there are other RegEnumKey (), RegEnumVal (), detailed applications, please refer to the help.

Q6.2 registry permission settings

Some keys are required to set permissions. Setacl.exe can set permissions by external programs
example:
$ setacl = @ TempDir & "\ setacl.exe"

RunWait(@ComSpec & ' /c '&$setacl& ' MACHINE\SYSTEM\CurrentControlSet\Enum\Root\ACPI_HAL /registry /grant everyone /full', @TempDir, @SW_HIDE)

[attach=275]

Q7 How not to refresh the registry restart to take effect immediately?

Do
ProcessClose("explorer.exe")
Until Not ProcessExists("explorer.exe")
Run("gpupdate /force","",@SW_HIDE)

; Keep pushing strongly applied this
DllCall ( "user32.dll", "int ", "SendMessageTimeout", "hwnd", 65535, "int", 26, "int", 0, "int", 0, "int", 0, "int", 1000, "str", "dwResult")
Q8 AU3 programs written arguments on how to run?

IF $ cmdline [0] <> 0 the Then
$ filename = $ cmdline [. 1]
MsgBox (4096, "Test", 'command you enter line parameters "' & $ filename & '' ')
Else
MsgBox (64," test ", 'please run this program with parameters')
EndIf

StringInStr IF ($ CmdLineRaw "/ Help") the Then
MsgBox (64-, "Help", "This is to help the program's")
EndIf

Q9 How to delete the script itself?

; Delete script itself
Run (@ ComSpec & '/ c the ping 127.0.0.1 -n 3 & del / q "' & @ ScriptFullPath & '"', @ SCRIPTDIR, @ SW_HIDE)
; delete the script directory of all things
Run (@ ComSpec & '/ of ping 127.0.0.1. 3 -n & C RD / Q / S " 'SCRIPTDIR @ & &'" ', SCRIPTDIR @, @ SW_HIDE)
QlO AU3 how encryption string and file checksums?

; The RC4 encryption (AU3 built-in function)
#include
Opt ( "MustDeclareVars",. 1)
the Local $ var
; encrypted string
$ _StringEncrypt var = (. 1, "sanhen", @ ComputerName,. 1)
MsgBox (0, "Test", $ var)
; decrypt the string
$ _StringEncrypt var = (0, var $, @ ComputerName,. 1)
MsgBox (0, "Test", $ var)

; MD5 encryption string
AU3 how to call MD5 encryption issues.
In fact, the official has been out a long time ago had UDF MD5, but not very good at searching some friends nothing more.
Now offers two official MD5 UDF to those in need of a friend to download the application.
It is a C language format is a format of VBscript UDF, in fact, the role is the same.
Personal preference, below is an example of the application.

#include
#include

$c_md5=md5("sanhen")
$vb_md5=MD5_String("sanhen")

MsgBox (64, "MD5 encrypted format C", $ c_md5)
MsgBox (64, "MD5 encryption Vbscript script format", $ vb_md5)

 

; The MD5 file efficacy

= MD5Hash #compiler_plugin_funcs
; top of the sentence can not be less. Otherwise, debugging errors in Scite in. Run directly on top of the sentence can be omitted.
File & SystemDir = @ $ "\ userinit.exe"
$ = PluginOpen PLH ( "2-\\ Server \ Update \ Tools \ MD5Hash.dll")
$ MD5Hash = MD5 ($ File,. 1, True)
the If MD5 $ <> "7BD70EC53CB7398246C84D25BFF33AA8" the Then
; filled with Shanghai government original XP SP2, MD5 is that, DLL with a different attachment system on top of reading it.
FileWriteLine ( "\\ server-2 \ log $ \ log.txt", @ ComputerName & " number of machines infected !!!")
EndIf
PluginClose ($ PLH)

; Ha Hey algorithm

1.
Function Name: FSHash
Author: JSThePatriot
Updated: 8-28-2006
function function: MD5, SHA-1 algorithm


2.
Function Name: StringHash
Author: SolidSnake
Update Date: 12-12-2006
function function: to generate MD5, SHA1, SHA256, Tiger and WhirlPool
verification string

3.
Function Name: FileHash
Author: SolidSnake
Update Date: 12-12-2006
function function: to generate MD5, SHA1, SHA256, Tiger and WhirlPool
verification file

4.
Function Name: Blowfish
Author: piccaso
Updated: 5-3-2007
function function: blowfish encryption / decryption functions

Q11 How to modify the screen resolution / refresh rate / color depth?
Save as: ChangeScreenRes.AU3 (arbitrary)

Once the include-#
; ============================================= ==================================
;
; function name: _ChangeScreenRes ()
; More information: modify the screen resolution , the refresh rate.
; version: 1.0.0.1
; parameters: $ i_Width - width of the screen (e.g., 1024 in 1024X768)
; $ I_height - screen height (e.g., in 1024X768 768)
; $ i_BitsPP - Desktop color depth (e.g. 32BIT, 32 bit)
; $ i_RefreshRate - screen refresh rate (such as MHZ 75).
; demand AutoIt beta> 3.1 above
; return value: success, screen updates, @ ERROR = 0
; failure, the screen does not update, @ERROR = 1
; == ================================================== ===========================
Func _ChangeScreenRes ($ i_Width = @DesktopWidth, $ I_height = @DesktopHeight, $ i_BitsPP = @DesktopDepth, $ i_RefreshRate @DesktopRefresh =)
Local Const $ DM_PELSWIDTH = 0x00080000
Local Const $DM_PELSHEIGHT = 0x00100000
Local Const $DM_BITSPERPEL = 0x00040000
Local Const $DM_DISPLAYFREQUENCY = 0x00400000
Local Const $CDS_TEST = 0x00000002
Local Const $CDS_UPDATEREGISTRY = 0x00000001
Local Const $DISP_CHANGE_RESTART = 1
Local Const $DISP_CHANGE_SUCCESSFUL = 0
Local Const $HWND_BROADCAST = 0xffff
Local Const $WM_DISPLAYCHANGE = 0x007E
If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth ; default to current setting
If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight ; default to current setting
If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth ; default to current setting
If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh ; default to current setting
Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")
Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DllStructGetPtr($DEVMODE))
If @error Then
$B = 0
SetError(1)
Return $B
Else
$B = $B[0]
EndIf
If $B <> 0 Then
DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5)
DllStructSetData($DEVMODE, 4, $i_Width, 2)
DllStructSetData($DEVMODE, 4, $i_Height, 3)
DllStructSetData($DEVMODE, 4, $i_BitsPP, 1)
DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5)
$B = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_TEST)
If @error Then
$B = -1
Else
$B = $B[0]
EndIf
Select
Case $B = $DISP_CHANGE_RESTART
$DEVMODE = ""
Return 2
Case $B = $DISP_CHANGE_SUCCESSFUL
DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_UPDATEREGISTRY)
DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
"int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width)
$DEVMODE = ""
Return 1
Case Else
$DEVMODE = ""
SetError(1)
Return $B
EndSelect
EndIf
EndFunc ;==>_ChangeScreenRes

Example:
------------------------------------------------ --------------------
#include
; 800X600 32-bit color set, @ 75MHZ
_ChangeScreenRes (800,600,32,75)
---------- -------------------------------------------------- --------

This will very good use.
For example: _ChangeScreenRes (1024, 768, 32 , 85)
below me a refresh rate locked it. Of course, you can also be implemented in software.
The following is AU3 to achieve. Lock the three resolution.
MonitorClass = $ 'the HKLM \ the SYSTEM \ CurrentControlSet \ Control \ Class \ {4D36E96E-E325-11CE-BFC1-08002BE10318}'
$ I =. 1
the While $ I> 0
$ = Ver the RegEnumKey (MonitorClass $, $ I)
the If the Then @error ExitLoop
$ & MonitorClass the MODES = $ '\' & $ Ver
$ = the DriverDesc the RegRead ($ the MODES, "the DriverDesc")
the If the DriverDesc $ <> '' the Then
the RegWrite (the MODES $ & '\ the MODES \ 1024,768', "Mode1" , "REG_SZ", '2.0-254.0,85.0-85.0, +, +')
the RegWrite (the MODES $ & '\ the MODES \ 640,480', "Mode1", "REG_SZ", '2.0-254.0,85.0-85.0, +, + '

$i = $i + 1
Else
RegDelete ( $MODES )
EndIf
WEnd

Guess you like

Origin blog.csdn.net/jiewu001/article/details/84037766
Recommended