Documentation
¶
Index ¶
- func Add_to_path(path_to_add string) error
- func Add_to_ps_module_path(input_path string) error
- func Are_long_file_paths_enabled() (bool, error)
- func Bring_back_the_right_click_menu() error
- func Choco_install(package_name string) error
- func Clean_path() error
- func Convert_blob_to_raw_github_url(blob_url string) (string, error)
- func Create_desktop_shortcut(target_path, shortcut_name, description string, window_style int, ...) error
- func Do_not_hide_search_box(restartExplorer bool) error
- func Do_not_show_file_extensions(restartExplorer bool) error
- func Do_not_show_hidden_files(restartExplorer bool) error
- func Do_not_use_24_hour_format() error
- func Download_file(destination_path string, url string) error
- func Enable_SSH() error
- func Enable_SSH_through_firewall() error
- func Enable_long_file_paths() error
- func Exclude_from_Microsoft_Windows_Defender(path_to_exclude string) error
- func Expand_windows_env(input string) string
- func Extract_password_protected_zip(src, dest, password string) error
- func Extract_zip(src, dest string) error
- func File_exists(path string) bool
- func Get_file_size(path string) (int64, error)
- func Get_file_size_human_readable(path string) (string, error)
- func Get_primary_ipv4_address() (string, error)
- func Hide_search_box(restartExplorer bool) error
- func Install_Java() error
- func Install_choco() error
- func Is_Choco_installed() bool
- func Is_Java_installed() bool
- func Remove_from_path(path_to_remove string) error
- func Remove_from_ps_module_path(input_path string) error
- func Reset_long_date_pattern() error
- func Reset_short_date_pattern() error
- func Reset_time_pattern() error
- func Restart_file_explorer() error
- func Seconds_in_taskbar(restartExplorer bool) error
- func Set_24_hour_format() error
- func Set_dark_mode(restartExplorer bool) error
- func Set_first_day_of_week_Monday() error
- func Set_first_day_of_week_Sunday() error
- func Set_light_mode(restartExplorer bool) error
- func Set_long_date_pattern() error
- func Set_short_date_pattern() error
- func Set_start_menu_to_center() error
- func Set_start_menu_to_left() error
- func Set_system_environment_variable(variable_name string, variable_value string) error
- func Set_time_pattern() error
- func Show_file_extensions(restartExplorer bool) error
- func Show_hidden_files(restartExplorer bool) error
- func Take_seconds_out_of_taskbar(restartExplorer bool) error
- func Use_Windows_11_right_click_menu() error
- func Winget_install(package_name string, package_id string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add_to_path ¶
Add_to_path adds the given path to the top of the system PATH (HKLM) if not already present. It expands environment variables, removes redundant entries (like %SystemRoot%), avoids duplicates, and broadcasts the environment change to Explorer. It also prints PowerShell instructions to refresh the session.
func Add_to_ps_module_path ¶
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 Are_long_file_paths_enabled ¶
Are_long_file_paths_enabled checks if long file path support is currently enabled. It returns true if LongPathsEnabled == 1, false otherwise. Returns an error if the registry cannot be read (e.g., due to insufficient privileges).
func Bring_back_the_right_click_menu ¶
func Bring_back_the_right_click_menu() error
Bring_back_the_right_click_menu enables the classic Windows 10-style context menu in Windows 11 by setting a specific registry key.
It creates the following key in the current user registry hive:
HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32
and sets its default value to an empty string.
After applying the registry modification, the function restarts Windows File Explorer using the Restart_file_explorer function to apply the change.
Returns an error if the registry key cannot be written or Explorer fails to restart.
func Choco_install ¶
Choco_install installs the given Chocolatey package and checks if it was installed successfully.
func Clean_path ¶
func Clean_path() error
Clean_path cleans the system PATH (HKLM) by removing duplicates and expanding environment variables. It updates the registry and broadcasts the environment change to Explorer.
func Convert_blob_to_raw_github_url ¶
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. It retries up to 100 times.
func Do_not_hide_search_box ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func Enable_SSH() error
Enable_SSH ensures the "sshd" service is set to Automatic and Running.
func Enable_SSH_through_firewall ¶
func Enable_SSH_through_firewall() error
Enable_SSH_through_firewall ensures that TCP port 22 is allowed in the firewall for all profiles.
func Enable_long_file_paths ¶
func Enable_long_file_paths() error
Enable_long_file_paths enables long file path support in Windows by setting LongPathsEnabled=1 under HKLM\SYSTEM\CurrentControlSet\Control\FileSystem. It first checks the current value using Are_long_file_paths_enabled() and only modifies the registry if needed. Administrator privileges are required.
func Exclude_from_Microsoft_Windows_Defender ¶
Exclude_from_Microsoft_Windows_Defender attempts to exclude the specified file or folder from Microsoft Defender's real-time protection.
This function first checks whether the Microsoft Defender Antivirus service (WinDefend) is currently running. If it is not running (e.g., disabled by policy or replaced by another antivirus solution), the function skips the exclusion step without error.
If the provided path refers to a file, its parent directory is excluded instead. If the path refers to a directory, it is used directly.
This operation requires administrative privileges if Microsoft Defender is enabled.
Parameters:
- path_to_exclude: The absolute or relative path to a file or folder to exclude.
Returns:
- nil if the exclusion was successful, unnecessary (because Defender is not running), or if the path was already excluded.
- An error if any part of the exclusion process fails (e.g., bad path, PowerShell failure).
Example:
err := Exclude_from_Microsoft_Windows_Defender("C:\\downloads\\nirsoft") if err != nil { log.Fatalf("Failed to exclude: %v", err) }
func Expand_windows_env ¶
Expand_windows_env expands environment variables using the Windows API. For example, %SystemRoot% becomes C:\Windows.
func Extract_password_protected_zip ¶
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 ¶
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 ¶
File_exists checks if a file exists and is not a directory.
func Get_file_size ¶
Get_file_size returns the size in bytes of the specified path. If the path is a regular file, its size is returned directly. If the path is a directory, the function walks through all files and returns the cumulative size of all non-directory files within it.
Parameters:
- path: The path to the file or directory.
Returns:
- int64: Total size in bytes.
- error: Any error encountered while accessing the file system.
Example:
size, err := Get_file_size("C:\\Users\\Administrator\\Desktop") if err != nil { log.Fatal(err) } fmt.Println("Total size:", size)
func Get_file_size_human_readable ¶
Get_file_size_human_readable returns the size of a file or directory at the given path in a human-readable string format with three decimal places of precision.
The function supports size units in ascending order: - bytes - KB (Kilobytes) - MB (Megabytes) - GB (Gigabytes) - TB (Terabytes)
For files, the function directly returns the file size in the most appropriate unit. For directories, it recursively calculates the total size of all non-directory files inside.
Parameters:
- path: The file or directory path as a string.
Returns:
- string: A formatted string representing the human-readable size (e.g., "123.456 MB").
- error: An error if the path does not exist or cannot be read.
Example:
sizeStr, err := Get_file_size_human_readable("C:\\Users\\Administrator\\Desktop") if err != nil { log.Fatal(err) } fmt.Println("Size:", sizeStr)
func Get_primary_ipv4_address ¶
Get_primary_ipv4_address returns the most appropriate local IPv4 address from the available network interfaces.
It prioritizes interfaces whose names contain preferred keywords such as "Wi-Fi", "Ethernet", or "Tailscale", and excludes interfaces that are likely virtual, loopback, or otherwise irrelevant, such as those containing "VMware", "Virtual", "Bluetooth", "Loopback", "OpenVPN", or "Disconnected".
The function performs the following steps:
- Lists all active, non-loopback interfaces.
- Filters out interfaces matching any excluded keywords.
- Searches for an interface whose name contains a preferred keyword.
- Falls back to any remaining valid interface if no preferred one is found.
- Returns the first usable IPv4 address found.
Returns the IPv4 address as a string, or an empty string if none are found. If an error occurs while listing interfaces, it is returned.
func Hide_search_box ¶
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, verifies the result, and sets JAVA_HOME to the default installation path using PowerShell.
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 ¶
Remove_from_path removes the given path from the system PATH if present. It normalizes the path, modifies HKLM registry, broadcasts environment changes, and advises the user to refresh the session if 'refreshenv' is available.
func Remove_from_ps_module_path ¶
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 ¶
func Reset_time_pattern() error
Reset_time_pattern resets long/short time format and separator to system defaults.
func Restart_file_explorer ¶
func Restart_file_explorer() error
Restart_file_explorer uses PowerShell to stop and restart Windows File Explorer, and waits until explorer.exe is running again.
func Seconds_in_taskbar ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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_system_environment_variable ¶
Set_system_environment_variable sets a system-wide environment variable in the registry under HKLM. It also broadcasts the environment change so that Explorer and other processes recognize the update.
func Set_time_pattern ¶
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 ¶
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 ¶
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 ¶
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 Use_Windows_11_right_click_menu ¶
func Use_Windows_11_right_click_menu() error
Use_Windows_11_right_click_menu restores the default Windows 11-style right-click context menu by removing a specific registry override.
It deletes the following keys from the current user registry hive:
HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2} HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32
These keys are used to force the classic Windows 10-style context menu in Windows 11. Removing them reverts Explorer to its default behavior.
After deleting the registry keys, the function restarts Windows File Explorer via Restart_file_explorer to apply the change.
Returns an error if any key deletion fails (unless the key doesn't exist), or if restarting Explorer fails.
func Winget_install ¶
Winget_install installs the specified package using winget with standard flags. Example: Winget_install("Visual Studio Code", "Microsoft.VisualStudioCode")
Types ¶
This section is empty.