LibreOffice Writer macro code samples

January 17th, 2024

Current file name, directory and full path

with help from a question I asked at https://ask.libreoffice.org/t/macro-function-regex-not-working/97425

Sub CurrentFileLocation
	sUrl = ThisComponent.getURL()
	
	'To get the full path
	sFullPath = ConvertFromURL(sUrl)
	
	'Then to get the full path but no the file name
	sParts = Split(sFullPath,"\")
	ReDim Preserve sParts(0 to UBound(sParts) - 1)
	 sDirectory = Join(sParts, "/")
	 
	'Then to get just the document name
	sParts = split(sUrl,"/")
	sName =convertfromurl(sParts(ubound(sParts)))
	'ubound returns the last item in the array sParts
	
	'Then to see the results
	msgbox(sName & Chr$(13) & sDirectory & Chr$(13) & sFullPath )
end sub

 

Bypass Windows 11 hardware check – new install and upgrade

January 15th, 2024

Hope this links sticks around.

https://www.tomshardware.com/how-to/bypass-windows-11-tpm-requirement

 

Win 10, 11 clean drive overwrite files with 0s

January 15th, 2024

To clear everything on a hard drive by writing zeros 3 times on all bytes. Approx 1 hour per 350 gb, but probably a lot longer? (Note: you will never get anything back after this)

  • Open cmd as administrator
  • Type: diskpart
  • Type: list disk
  • Note the number of the disk you are trying to wipe clean
  • Type: select disk [number]
  • Double check the disk number because this is going to be irreversible
  • Type: clean all

To securely overwrite the free space on your hard drive (where old files can be recovered) and never be able to recover them:

  • Open cmd as administrator. The following command cleans the c: drive
  • Type: cipher /w:c:

/W Removes data from available unused disk space on the entire
volume. If this option is chosen, all other options are ignored.
The directory specified can be anywhere in a local volume. If it
is a mount point or points to a directory in another volume, the
data on that volume will be removed.

End

Restore wrong icons on desktop Win10?-11

January 7th, 2024

When desktop icons have gone all screwy run this in regular cmd prompt

ie4uinit.exe -show
taskkill /IM explorer.exe /F
DEL /A /Q "%localappdata%\IconCache.db"
DEL /A /F /Q "%localappdata%\Microsoft\Windows\Explorer\iconcache*"
shutdown /r /f /t 00

Warning — that last line will immediately reboot the system. You have to use it though because you shut down explorer.ext

cmd line Change password and prevent password change

November 15th, 2023
I changed the password to "username" + the number 1 to get in
then:

wmic UserAccount where Name="Username" set PasswordExpires=False
then put password back with:
net user "username" password