system_management_functions

package
v2.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2025 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add_to_path

func Add_to_path(path_to_add string) error

Add_to_path adds the given path to the top of the system PATH (HKLM) if not already present. It broadcasts the environment change so apps like Explorer pick it up.

func Add_to_ps_module_path added in v2.7.0

func Add_to_ps_module_path(input_path string) error

Add_to_ps_module_path resolves the appropriate parent directory based on a given file or folder path and adds it to the system-wide PSModulePath

Supported input: - .psm1 or .psd1 file => adds the grandparent directory - folder with only .psm1 or .psd1 files => adds parent of that folder - otherwise adds folder itself

func Choco_install

func Choco_install(package_name string) error

Choco_install installs the given Chocolatey package and checks if it was installed successfully.

func Convert_blob_to_raw_github_url added in v2.6.0

func Convert_blob_to_raw_github_url(blob_url string) (string, error)

Convert_blob_to_raw_github_url transforms a GitHub "blob" URL into a "raw" content URL.

GitHub's web interface often shows files using a URL like:

https://github.com/{user}/{repo}/blob/{branch}/{path/to/file}

But to access the raw file directly through GitHub (still using the github.com domain), the equivalent raw content URL is:

https://github.com/{user}/{repo}/raw/{branch}/{path/to/file}

This function performs the necessary transformation by replacing the "/blob/" segment in the URL with "/raw/".

For example:

Input:
  https://github.com/user/repo/blob/main/script.ps1
Output:
  https://github.com/user/repo/raw/main/script.ps1

Parameters:

  • blob_url: the GitHub "blob" URL to convert

Returns:

  • The corresponding "raw" content URL
  • An error if the input does not contain the expected "/blob/" segment

func Create_desktop_shortcut

func Create_desktop_shortcut(target_path, shortcut_name, description string, window_style int, all_users bool) error

Create_desktop_shortcut creates a .lnk shortcut on the desktop. It accepts the target path, shortcut name (optional), description (optional), window style (3 = maximized), and allUsers flag.

func Do_not_hide_search_box(restartExplorer bool) error

Do_not_hide_search_box sets SearchboxTaskbarMode = 2 to show the full search box on the taskbar. If restartExplorer is true, Explorer will be restarted to apply the change.

func Do_not_show_file_extensions

func Do_not_show_file_extensions(restartExplorer bool) error

Do_not_show_file_extensions sets HideFileExt = 1 to hide file extensions. If restartExplorer is true, Explorer is restarted to apply the change immediately.

func Do_not_show_hidden_files

func Do_not_show_hidden_files(restartExplorer bool) error

Do_not_show_hidden_files sets Hidden = 2 to hide hidden files in File Explorer. If restartExplorer is true, Explorer will be restarted to apply the change immediately.

func Do_not_use_24_hour_format added in v2.4.0

func Do_not_use_24_hour_format() error

Do_not_use_24_hour_format configures Windows to use 12-hour time by setting iTime = 0.

func Download_file

func Download_file(destination_path string, url string) error

Download_file downloads a file from the given URL and saves it to the specified destination path.

Parameters:

  • destination_path: The full file path (including filename) where the downloaded content will be saved.
  • url: The HTTP or HTTPS URL from which to download the file.

Returns:

  • An error if the download, file creation, or writing fails; otherwise, nil.

Example:

err := Download_file("C:\\downloads\\example.exe", "https://example.com/file.exe")
if err != nil {
    log.Fatalf("Download failed: %v", err)
}

func Enable_SSH added in v2.9.0

func Enable_SSH() error

Enable_SSH ensures the "sshd" service is set to Automatic and Running.

func Exclude_from_Microsoft_Windows_Defender

func Exclude_from_Microsoft_Windows_Defender(path_to_exclude string) error

Exclude_from_Microsoft_Windows_Defender excludes the given file or folder from Microsoft Defender.

If a file is given, its parent folder is excluded instead. This requires administrator privileges.

Parameters:

  • path_to_exclude: Absolute path to a file or folder to exclude.

Returns:

  • An error if exclusion fails; nil otherwise.

func Extract_password_protected_zip

func Extract_password_protected_zip(src, dest, password string) error

Extract_password_protected_zip extracts a password-protected ZIP archive using AES or ZipCrypto.

Parameters:

  • src: full path to the .zip archive
  • dest: directory where the files should be extracted
  • password: the password used to decrypt the archive

Returns:

  • error if extraction fails, otherwise nil

func Extract_zip

func Extract_zip(src, dest string) error

Extract_zip extracts a ZIP archive specified by src into the destination directory dest.

It protects against Zip Slip attacks by ensuring all extracted paths are within dest.

Parameters:

  • src: Full path to the ZIP archive.
  • dest: Destination directory where the contents will be extracted.

Returns:

  • An error if extraction fails, or nil on success.

func File_exists

func File_exists(path string) bool

File_exists checks if a file exists and is not a directory.

func Hide_search_box(restartExplorer bool) error

Hide_search_box sets SearchboxTaskbarMode = 0 to hide the taskbar search box. If restartExplorer is true, Explorer will be restarted to apply the change.

func Install_Java

func Install_Java() error

Install_Java ensures Java is installed by checking Is_Java_installed(). If not found, it installs the temurin21 JDK via Chocolatey. You could use Is java installed after choco_install(java). Install_Java ensures Java is installed by checking Is_Java_installed(). If not found, it installs the temurin21 JDK via Chocolatey and verifies the result.

func Install_choco

func Install_choco() error

Install_choco installs Chocolatey using the official PowerShell script. It takes no arguments and logs output to the standard logger. You could have Install_Choco check if choco is installed before installing. Then you could just call Install_Choco, and it would handle the details of whether Choco was installed or not. Install_choco installs Chocolatey if it is not already installed. It logs all steps to the standard logger.

func Is_Choco_installed

func Is_Choco_installed() bool

Is_Choco_installed checks if Chocolatey is installed. It returns true if choco.exe is found in PATH or at the default location.

func Is_Java_installed

func Is_Java_installed() bool

Is_Java_installed checks if both java.exe and javac.exe are available in PATH, or in the default Eclipse Adoptium installation directory.

func Remove_from_path

func Remove_from_path(path_to_remove string) error

Remove_from_path removes the given path from the system PATH if present. It normalizes the path, modifies HKLM registry, and broadcasts environment changes.

func Remove_from_ps_module_path added in v2.7.0

func Remove_from_ps_module_path(input_path string) error

Remove_from_ps_module_path resolves the appropriate parent directory based on a given file or folder path and removes it from the system-wide PSModulePath.

func Reset_long_date_pattern

func Reset_long_date_pattern() error

Reset_long_date_pattern resets the long date pattern to the default "dddd, MMMM d, yyyy" and broadcasts the change to the system.

func Reset_short_date_pattern

func Reset_short_date_pattern() error

Reset_short_date_pattern resets the short date pattern to "M/d/yyyy" and broadcasts the change to the system.

func Reset_time_pattern added in v2.3.0

func Reset_time_pattern() error

Reset_time_pattern resets long/short time format and separator to system defaults.

func Seconds_in_taskbar

func Seconds_in_taskbar(restartExplorer bool) error

Seconds_in_taskbar enables seconds on the taskbar clock by setting ShowSecondsInSystemClock = 1. If restartExplorer is true, Explorer will be restarted to apply the change.

func Set_24_hour_format added in v2.4.0

func Set_24_hour_format() error

Set_24_hour_format configures Windows to use 24-hour time by setting iTime = 1.

func Set_dark_mode

func Set_dark_mode(restartExplorer bool) error

Set_dark_mode sets Windows to dark mode for both system and apps. If restartExplorer is true, it restarts Explorer to apply the change.

func Set_first_day_of_week_Monday added in v2.5.0

func Set_first_day_of_week_Monday() error

Set_first_day_of_week_Monday sets Monday as the first day of the week in Windows regional settings.

func Set_first_day_of_week_Sunday added in v2.5.0

func Set_first_day_of_week_Sunday() error

Set_first_day_of_week_Sunday sets Sunday as the first day of the week in Windows regional settings.

func Set_light_mode

func Set_light_mode(restartExplorer bool) error

Set_light_mode sets Windows to light mode for both system and apps. If restartExplorer is true, it restarts Explorer to apply the change.

func Set_long_date_pattern

func Set_long_date_pattern() error

Set_long_date_pattern sets the long date pattern to "yyyy-MM-dd-dddd" and broadcasts the change to the system.

func Set_short_date_pattern

func Set_short_date_pattern() error

Set_short_date_pattern sets the short date pattern to "yyyy-MM-dd-dddd" and broadcasts the change to the system.

func Set_start_menu_to_center

func Set_start_menu_to_center() error

Set_start_menu_to_center sets the Windows 11 taskbar alignment to the center by writing TaskbarAl=1 in the registry and restarting Explorer.

func Set_start_menu_to_left

func Set_start_menu_to_left() error

Set_start_menu_to_left sets the Windows 11 taskbar alignment to the left by writing TaskbarAl=0 in the registry and restarting Explorer.

func Set_time_pattern added in v2.3.0

func Set_time_pattern() error

Set_time_pattern sets custom time patterns and separator: - Long time: "HH.mm.ss" - Short time: "HH.mm.ss" - Separator: "."

func Show_file_extensions

func Show_file_extensions(restartExplorer bool) error

Show_file_extensions sets HideFileExt = 0 to make file extensions visible. If restartExplorer is true, Explorer is restarted to apply the change immediately.

func Show_hidden_files

func Show_hidden_files(restartExplorer bool) error

Show_hidden_files sets Hidden = 1 to show hidden files in File Explorer. If restartExplorer is true, Explorer will be restarted to apply the change immediately.

func Take_seconds_out_of_taskbar

func Take_seconds_out_of_taskbar(restartExplorer bool) error

Take_seconds_out_of_taskbar disables seconds on the taskbar clock by setting ShowSecondsInSystemClock = 0. If restartExplorer is true, Explorer will be restarted to apply the change.

func Winget_install

func Winget_install(package_name string, package_id string) error

Winget_install installs the specified package using winget with standard flags. Example: Winget_install("Visual Studio Code", "Microsoft.VisualStudioCode")

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL