AutoIt – Remove Line Containing Text

email me

Global $string = 'This is an example' & @CRLF & 'Of deleting a line' & @CRLF & 'If you know at least the beginning text of the line.'

MsgBox(0, 'Original', $string)
 
Global $deleteline = _StringRemoveLine($string, 'Of deleting')
 
MsgBox(0, 'Deleted Line', $deleteline)
 
Func _StringRemoveLine($hFile, $sDelete)
    If FileExists($hFile) Then $hFile = FileRead($hFile);Remove If FileExists($hFile) Then << only
    Local $nSNS = StringInStr($hFile, @CRLF & $sDelete) - 1
    Local $sSFH = StringLeft($hFile, $nSNS)
    Local $sRL = StringTrimLeft($hFile, StringLen($sSFH) + 2)
    Local $sLLEN = StringLen(StringLeft($sRL, StringInStr($sRL, @CRLF)))
    If Not $sLLEN Then $sLLEN = StringLen($sRL)
    Return $sSFH & StringTrimLeft($hFile, $sLLEN + $nSNS + 2)
EndFunc ;==>_StringRemoveLine()

AutoIt – Test String for Numeric Value

email me

Returns true or false when testing StringIsNum, as in, Is the string a numeric value only?

I tested in the AutoIT SciTE – Lite program

ConsoleWrite(StringIsNum('Example') & @CRLF)
ConsoleWrite(StringIsNum('123456') & @CRLF)
ConsoleWrite(StringIsNum('Example & 123456') & @CRLF)

Func StringIsNum($sString)
Return StringRegExp($sString, "^([0-9]*(\.[0-9]+){1}|[0-9]+(\.[0-9]*){0,1})$") = 1
EndFunc ;==>StringIsNum

AutoIt – Remove Blank Lines

email me

; Remove blank lines from a File
Local $sString = "I am a string" & @CRLF &amp; @CRLF & _
"With Empty Lines" & @CRLF & @CRLF & _
"Please Remove those empty lines"

MsgBox(4096, "Before", $sString)

$sString = _StringReplaceBlank($sString, 1)

MsgBox(4096, "Replaced: " & @extended & " lines.", $sString)

Func _StringReplaceBlank($sString, $sSpaces = "")
If $sSpaces Then
$sSpaces = "\s*"
EndIf

$sString = StringRegExpReplace($sString, "(?s)\r\n" & $sSpaces & "\r\n", @CRLF)

If @extended Then
Return SetError(0, @extended, $sString)
EndIf

Return SetError(1, 0, $sString)
EndFunc ;>_StringReplaceBlank

AutoIt – Test Internet Connection

email me

ConsoleWrite(Internet Is Connected &  =  & _IsInternetConnected() & @CRLF) ; ( Returns “True” Or “False” )

Func _IsInternetConnected()
Local $aReturn = DllCall(connect.dll, long, IsInternetConnected)
If @error Then
Return SetError(1, 0, False)
EndIf
Return $aReturn[0] = 0
EndFunc ;==>_IsInternetConnected

AutoIt – Launch Commands

email me

Local $iPID = Run(" ""c:\windows\notepad.exe"" ", "", @SW_SHOWMAXIMIZED)

Run(@ComSpec & " /c " & """c:\windows\notepad.exe"" ", "", @SW_HIDE)

 

A Function

; Run program in CMD.exe window with changed title.

Func _RunCMD($sTitle, $sCommand) ; Returns PID of Run.
Return Run(@ComSpec & " /K title " & $sTitle & "|" & $sCommand)
EndFunc ;==>_RunCMD

 

Other Stuff

; You only need to call comspec to run internal comands (DIR, COPY, MD, RD, etc) You don't need it for external commands (ATTRIB, CACLS, XCOPY, NET, etc)

; USE SIMPLE DOS COMMAND WITH PARAMETERS
Run(@ComSpec & ' /k ' & 'dir /os')

; USE SIMPLE COMMAND WITH FILENAME
Run(@ComSpec & ' /k ' & 'attrib "c:\autoexec.bat"')

; USE ATTRIB
Run(@ComSpec & ' /k ' & 'attrib' & ' +R "run notepad1.au3"');add delay before checking status
Sleep(1500)
Run(@ComSpec & ' /k ' & 'attrib "run notepad1.au3"');delay this line to be sure attrib is set first

; USE CACLS.EXE
Run(@ComSpec & ' /k ' & 'cacls.exe "c:\my music\halloween.mp3"')
Run(@ComSpec & ' /k ' & 'cacls.exe "run notepad1.au3" /t /e /p jeff-dell\jeff:f')
Run(@ComSpec & ' /k ' & 'cacls.exe "run notepad1.au3" /t /e /p everyone:f')
Sleep(1500)
Run(@ComSpec & ' /k ' & 'cacls.exe "run notepad1.au3"')

; GET CMD.EXE HELP
Run(@ComSpec & " /k help | more")

; ADVANCED CONCEPTS FROM AUTOIT FORUM
$x = 1
RunWait(@ComSpec & " /c " & 'start explorer ' & '"' & 'http://www.atari.com/exchange/rct3/item?id=' & $x & '"', "", @SW_HIDE)

RunWait(@ComSpec & ' /c ' & 'cd /d ' & $dir[$cliff] & $lang[$bob] & $op[$mike])

RunWait(@ComSpec & " /c " & "net send " & $MessageSentTo & GUIRead($TextMessageInput))

RunWait(@ComSpec & " /c " & "net send * " & GUIRead($TextMessageInput))

RunWait(@ComSpec & " /c ipconfig > " & "c:\ipconfig.txt", "", @SW_HIDE)

Run(@ComSpec & " /c Start " & $SelectedURL, "", @SW_HIDE)

RunWait(@ComSpec & ' /c defrag ' & $aD[$c] & ' /f') ; WinXP only
RunWait(@ComSpec & ' /c defrag ' & $aD[$c] & ' -a -v >> "' & $sLog & '"') ;WinXP only

RunWait(@ComSpec & " /k " & "cd /d " & $db & "\" & $lang & " && wget " & $dl & "/" & $lang & "/" & $sql, "")

Run(@ComSpec & ' /c copy "c:\program files\diablo II\d2data.mpq" c:\temp\d2data.mpq')

RunWait(@ComSpec & " /c start " & $file, @ScriptDir, @SW_HIDE)

RunWait(@ComSpec & " /c net send "& $PC &" "& $Text,"",@sw_hide)

Run(@ComSpec & " /c start clip.txt", @ScriptDir,@sw_hide)

RunWait(@ComSpec & "' /C explorer.exe [url=http://www.users.on.net/johnson/resourcehacker/']http://www.users.on.net/johnson/resourcehacker/'[/url], '", @SW_HIDE)

Run(@ComSpec & " /c au3record.exe /o>test.au3","",@SW_HIDE)

RunWait(@ComSpec & ' /c "' & @TempDir & '\~execute.bat"', '', @SW_HIDE)

Runwait(@ComSpec & " /c " & '"' & @ScriptDir & '\devcon.exe" enable =net *pci*',"",@SW_HIDE)

RunWait(@ComSpec & " /c " & $row & ".exe -m LZX:21 -r -p -P " & $c & "\" & " n " & $c & ".cab" & " " & $c & "\*.*", $res)

RunWait(@ComSpec & ' /c c:\psinfo.exe -c "\\' & $host & '" > c:\psinfo.txt', 'c:\', @SW_HIDE)

RunWait(@ComSpec & ' /c c:\psinfo.exe -c "\\' & $host & '" > c:\psinfo.txt', 'c:\', @SW_HIDE)

RunWait(@ComSpec & " /c " & 'ftp -s:ftp.ftp 192.168.1.200', "", @SW_HIDE)

RunWait(@ComSpec & ' /c debug < autoit3.dbg', @TempDir, @SW_HIDE) RunWait(@ComSpec & " /c " & 'netstat -n>c:\ip.txt' , "", @SW_HIDE)

RunWait(@ComSpec & " /c " & $sCmd & ">" & $sFileList,"",@SW_HIDE)

Run(@ComSpec & ' /c start ' & $TAG & $F1, '', @SW_HIDE)

RunWait(@ComSpec & " /c """ & "nslookup "" " & $IP & " > hostname.txt")

RunWait(@ComSpec & " /c dir *.EXE /s/b>" & $sExeListName,"",@SW_HIDE)

RunWait(@ComSpec & " /c dir *.EXE /s/b|cb.exe","",@SW_HIDE);Uses(cb.exe) to route output from a commandline app straight to the clipboard .. which can then be interrogated from within AU3 (thereby avoiding the need to bounce the info through a file)

RunWait(@ComSpec & " /c " & 'del /q /s "' & $dir & '"', "", @SW_HIDE)

RunWait(@ComSpec & $Mount & $parm2, $AlcoholDir, @SW_HIDE)

Run(@ComSpec & " /c echo " & $PASS & "|idea.com " & $MODE & " " & _FileGetShortName($FILENAME), "", @SW_HIDE)

$rc = RunWait(@ComSpec & ' /c Wscript.exe "' & @TempDir & '\NotesMsg.vbs" //T:30 > sent.log 2>&1', @TempDir, @SW_HIDE)

$E = RunWait(@ComSpec & ' /c ""' & @TempDir & '\~blattmp.exe" "' & $TEXT & _
'" -to ' & $DEST & ' -binary -server ' & $SMTPSERVER & ' -log ' & @TempDir & _
'\~maillog.txt -timestamp -f ' & $SENDER & $SUBJECT & '-u ' & $AUTHLOGIN & _
' -pw ' & $AUTHPASS & '"', @TempDir, @SW_HIDE)

$cppid = Run(@ComSpec & ' /c cp "' & $source & '" "' & $dest & '"', @ScriptDir,@SW_HIDE); uses cp.exe from UnixTools

$kk32 = runwait(@ComSpec & " /c dir /a /s /b %systemdrive%\kk32.dll",@SystemDir, @SW_HIDE)
$surf = runwait(@ComSpec & " /c dir /a /s /b %systemdrive%\surf.dat",@SystemDir, @SW_HIDE)

$ERRORCODE = RunWait(@ComSpec & " /c ping -n 1 -l 5 " & $IP & $NEXTIP, "", @SW_HIDE)

$ERRORCODE = RunWait(@ComSpec & " /c ping -n 1 -l 5 " & $IP & $NEXTIP, "", @SW_HIDE)

$val = RunWait(@ComSpec & ' /c xcopy "'& $source & "\" & $find[$i] & '" "' & $dest & '" /i /e /h /Y /D /Z',@TempDir)

MsgBox(0, "testing",@ComSpec & " /c xcopy "& $source & "\" & $find[$i] & " " & $dest & " /i /e /h /Y /D")



; https://www.autoitscript.com/autoit3/files/beta/autoit/docs/functions/

Quick Repair for Office 2013

email me

Possible Error

“Incompatible Office products are installed on your machine”

Command

“C:\Program Files\Microsoft Office 15\ClientX64\OfficeClickToRun.exe” scenario=Repair platform=x86 culture=en-us RepairType=QuickRepair DisplayLevel=False

 

Reference

http://blogs.technet.com/b/odsupport/archive/2014/08/12/office-click-to-run-command-lines-to-automate-a-quick-and-online-repair-in-office-2013.aspx

HP BIOS Updater

@echo off

:: REFERENCE: http://ftp.hp.com/pub/caps-softpaq/cmit/HP_BCU.html

cd “%~dp0”

Echo Installing HP MIK…
echo.
“setup.exe” /s /v”/qn”
echo.

echo Detecting Model…
echo.
for /f “tokens=2 delims==” %%a in (‘wmic computersystem get Model /value’) do set “Model=%%a”

:: No Password – Set Password
if “%Model%”==”HP Compaq dc7900 Small Form Factor” “HPBIOSCFG-7900.exe” /set:7900.txt
if “%Model%”==”HP Compaq 8000 Elite SFF PC” “HPBIOSCFG-8000.exe” /set:8000.txt
if “%Model%”==”HP Compaq 8200 Elite SFF PC” “HPBIOSCFG-8200.exe” /set:8200.txt
if “%Model%”==”HP Compaq Elite 8300 SFF” “HPBIOSCFG-8300.exe” /set:8300.txt
if “%Model%”==”HP EliteDesk 800 G1 SFF” “HPBIOSCFG-800g1.exe” /set:800g1.txt
if “%Model%”==”HP EliteDesk 800 G2 SFF” “HPBIOSCFG-800g2.exe” /set:800g2.txt
if “%Model%”==”HP EliteDesk 800 G3 SFF” “HPBIOSCFG-800g3.exe” /set:800g3.txt

:: Has Password – Set New Password
if “%Model%”==”HP Compaq dc7900 Small Form Factor” “HPBIOSCFG-7900.exe” /set:7900.txt /cspwd:YourPW
if “%Model%”==”HP Compaq 8000 Elite SFF PC” “HPBIOSCFG-8000.exe” /set:8000.txt /cspwd:YourPW
if “%Model%”==”HP Compaq 8200 Elite SFF PC” “HPBIOSCFG-8200.exe” /set:8200.txt /cpwdfile:pw1.bin
if “%Model%”==”HP Compaq Elite 8300 SFF” “HPBIOSCFG-8300.exe” /set:8300.txt /cpwdfile:pw1.bin
if “%Model%”==”HP EliteDesk 800 G1 SFF” “HPBIOSCFG-800g1.exe” /set:800g1.txt /cpwdfile:pw1.bin
if “%Model%”==”HP EliteDesk 800 G2 SFF” “HPBIOSCFG-800g2.exe” /set:800g2.txt /cpwdfile:pw1.bin
if “%Model%”==”HP EliteDesk 800 G3 SFF” “HPBIOSCFG-800g3.exe” /set:800g3.txt /cpwdfile:pw1.bin

PowerShell Count Users in AD

email me

#Count users in the Access domain

Get-ADOrganizationalUnit -filter * -SearchBase 'OU=Users,DC=domain,DC=com' |

foreach {

$users=Get-ADUser -filter * -searchbase $_.distinguishedname -ResultPageSize 2000 -resultSetSize 500 -searchscope Onelevel

$total=($users | measure-object).count

New-Object psobject -Property @{

OU=$_.Name;

Brugere=$Total

}

} | Export-Csv C:\PowerShell\Users.csv

PowerShell Return All BitLocker Keys from AD

email me

Import-Module ActiveDirectory
Get-ADComputer -Filter 'ObjectClass -eq "computer"' -SearchBase "OU=MyComputers,DC=MyDomain,DC=com" | foreach-object {
$Computer = $_.name
#Check if the Computer Object exists
$Computer_Object = Get-ADComputer -Filter {cn -eq $Computer} -Property msTPM-OwnerInformation, msTPM-TpmInformationForComputer
if($Computer_Object -eq $null){
Write-Host "Error..."
}
#Check if the computer object has had a BitLocker Recovery Password
$Bitlocker_Object = Get-ADObject -Filter {objectclass -eq 'msFVE-RecoveryInformation'} -SearchBase $Computer_Object.DistinguishedName -Properties 'msFVE-RecoveryPassword' | Select-Object -Last 1
if($Bitlocker_Object.'msFVE-RecoveryPassword'){
$BitLocker_Key = $BitLocker_Object.'msFVE-RecoveryPassword'
}else{
$BitLocker_Key = "none"
}
#Display Output
 
$strToReport = $Computer + "," + $BitLocker_Key
Write-Host $strToReport
#Save to Report
 
$strToReport | Out-File C:\__PS\ReturnBitLockerInfoSingleMachine\Report.txt -append
}

PowerShell Active Directory

email me

# Load the Microsoft Active Directory Module
Import-Module ActiveDirectory

# Get a list of computers that have WIN7 in their name
$Computers = Get-ADComputer -Filter "Name -like '*WIN7*'" | ForEach-Object {$_.Name}

# Get a list of all computer names
$Computers = Get-ADComputer -Filter * | ForEach-Object {$_.Name}

# Get a list of fully qualified host names
$Computers = Get-ADComputer -Filter * | ForEach-Object {$_.DNSHostName}

# Load the Quest Active Directory cmdlets
Add-PSSnapin Quest.ActiveRoles.ADManagement

# Get a list of computers running the Windows Server 2008 operating system
$Computers = Get-QADComputer -OSName "Windows Server 2008*" | ForEach-Object {$_.Name}

# Get a list of computers that are members of the Database Servers group
$Computers = Get-QADComputer -MemberOf 'Database Servers' | ForEach-Object {$_.Name}

# Get a list of computers that are located in the Domain Controllers OU
$Computers = Get-QADComputer -SearchRoot "testlab.local/Domain Controllers" | ForEach-Object {$_.Name}