### LNK File Creation Examples Source: https://github.com/strayge/pylnk/blob/master/README.md Examples demonstrating the creation of .lnk files using the CLI. Shows basic creation, creation with specific window modes, and adding descriptions. ```sh pylnk3 p filename.lnk ``` ```sh pylnk3 c c:\prog.exe shortcut.lnk ``` ```sh pylnk3 c \\192.168.1.1\share\file.doc doc.lnk ``` ```sh pylnk3 create c:\1.txt text.lnk -m Minimized -d "Description" ``` -------------------------------- ### Create Shortcut with All Options (CLI) Source: https://context7.com/strayge/pylnk/llms.txt Uses the PyLnk3 CLI tool to create a shortcut with various options including arguments, description, icon, working directory, and window mode. ```bash # Create shortcut with all options pylnk3 create C:\\app.exe app.lnk \ --arguments "-config settings.ini" \ --description "My Application" \ --icon "C:\\app.ico" \ --icon-index 0 \ --workdir "C:\\AppData" \ --mode Maximized ``` -------------------------------- ### Create Simple Local File Shortcut (CLI) Source: https://context7.com/strayge/pylnk/llms.txt Uses the PyLnk3 CLI tool to create a simple shortcut to a local file. ```bash # Create a simple shortcut to a local file pylnk3 create C:\\Windows\\notepad.exe notepad.lnk pylnk3 c C:\\folder\\file.txt shortcut.lnk ``` -------------------------------- ### Create LNK File CLI Source: https://github.com/strayge/pylnk/blob/master/README.md Use this command to create a new .lnk file. Requires the target path and the desired shortcut filename. Various optional arguments control shortcut properties like arguments, description, icon, working directory, and window mode. ```sh pylnk3 create [-h] [--arguments [ARGUMENTS]] [--description [DESCRIPTION]] [--icon [ICON]] [--icon-index [ICON_INDEX]] [--workdir [WORKDIR]] [--mode [{Maximized,Normal,Minimized}]] target name ``` -------------------------------- ### Parse and Display Shortcut Information (CLI) Source: https://context7.com/strayge/pylnk/llms.txt Uses the PyLnk3 CLI tool to parse and display all information from a shortcut file. ```bash # Parse and display all information from a shortcut pylnk3 parse shortcut.lnk pylnk3 p shortcut.lnk ``` -------------------------------- ### Create Network Path Shortcut (CLI) Source: https://context7.com/strayge/pylnk/llms.txt Uses the PyLnk3 CLI tool to create a shortcut to a network path. ```bash # Create a shortcut to a network path pylnk3 create \\192.168.1.1\\share\\file.doc doc.lnk ``` -------------------------------- ### Short Form Create Shortcut with Options (CLI) Source: https://context7.com/strayge/pylnk/llms.txt Uses the short form of the PyLnk3 CLI tool to create a shortcut with options like window mode and description. ```bash # Short form with options pylnk3 c C:\\1.txt text.lnk -m Minimized -d "Text file shortcut" ``` -------------------------------- ### Create UWP App Shortcuts Source: https://context7.com/strayge/pylnk/llms.txt Use build_uwp to create shortcuts for Universal Windows Platform applications and parse their specific shell item structures. ```python from pylnk3 import build_uwp, Lnk, ROOT_UWP_APPS # Create a shortcut to Windows Calculator lnk = build_uwp( package_family_name='Microsoft.WindowsCalculator_8wekyb3d8bbwe', target='Microsoft.WindowsCalculator_8wekyb3d8bbwe!App', location='C:\\Program Files\\WindowsApps\\Microsoft.WindowsCalculator_10.1910.0.0_x64__8wekyb3d8bbwe', logo44x44='Assets\\CalculatorAppList.png', lnk_name='calculator.lnk' ) # Parse an existing UWP shortcut lnk = Lnk('uwp_app.lnk') uwp_root = lnk.shell_item_id_list.items[0] if uwp_root.root == ROOT_UWP_APPS: uwp_segment = lnk.shell_item_id_list.items[1] for main_block in uwp_segment._blocks: for sub_block in main_block._blocks: print(f"{sub_block.name}: {sub_block.value}") ``` -------------------------------- ### Low-Level Lnk Object Creation Source: https://context7.com/strayge/pylnk/llms.txt Creates shortcuts with full manual control using the `Lnk` class directly, allowing configuration of link flags, file attributes, shell item ID lists, and link information. ```python from pylnk3 import ( Lnk, create, LinkTargetIDList, LinkInfo, RootEntry, DriveEntry, PathSegmentEntry, ROOT_MY_COMPUTER, TYPE_FOLDER, TYPE_FILE, DRIVE_FIXED ) # Create empty Lnk object lnk = create('manual.lnk') # Configure link flags lnk.link_flags.IsUnicode = True lnk.link_flags.HasLinkTargetIDList = True lnk.link_flags.HasLinkInfo = True lnk.link_flags.HasName = True lnk.link_flags.HasWorkingDir = True # Set file attributes lnk.file_flags.archive = True # Build shell item ID list manually lnk.shell_item_id_list = LinkTargetIDList() lnk.shell_item_id_list.items = [ RootEntry(ROOT_MY_COMPUTER), DriveEntry('C:'), PathSegmentEntry.create_for_path('C:\\Windows', TYPE_FOLDER), PathSegmentEntry.create_for_path('C:\\Windows\\notepad.exe', TYPE_FILE) ] # Configure link info for local path lnk.link_info = LinkInfo() lnk.specify_local_location( path='C:\\Windows\\notepad.exe', drive_type=DRIVE_FIXED, drive_serial=12345678, volume_label='System' ) # Set string data lnk.description = 'Notepad text editor' lnk.work_dir = 'C:\\Windows' # Save lnk.save() ``` -------------------------------- ### Create Shortcuts to Network Paths Source: https://context7.com/strayge/pylnk/llms.txt Use UNC paths to create shortcuts for network shares and access remote-specific link information. ```python from pylnk3 import for_file # Create a shortcut to a network file lnk = for_file( target_file='\\\\192.168.1.100\\share\\documents\\report.docx', lnk_name='network_doc.lnk', description='Shared document on network drive' ) # Create a shortcut to a network folder lnk = for_file( target_file='\\\\server\\projects\\current', lnk_name='projects.lnk', work_dir='\\\\server\\projects' ) # Access network-specific information after parsing from pylnk3 import Lnk lnk = Lnk('network_shortcut.lnk') link_info = lnk._link_info if link_info.remote: print(f"Network share: {link_info.network_share_name}") print(f"Base name: {link_info.base_name}") ``` -------------------------------- ### Parse Existing LNK Files Source: https://context7.com/strayge/pylnk/llms.txt Use the Lnk class to load a shortcut file and access its metadata, timestamps, and target information. ```python from pylnk3 import Lnk # Parse an existing shortcut file lnk = Lnk('C:\\Users\\user\\Desktop\\shortcut.lnk') # Access shortcut properties print(f"Target path: {lnk.path}") print(f"Working directory: {lnk.work_dir}") print(f"Arguments: {lnk.arguments}") print(f"Description: {lnk.description}") print(f"Icon location: {lnk.icon}") print(f"Icon index: {lnk.icon_index}") print(f"Window mode: {lnk.window_mode}") # Normal, Maximized, or Minimized print(f"Hotkey: {lnk.hot_key}") # Access file timestamps print(f"Created: {lnk.creation_time}") print(f"Modified: {lnk.modification_time}") print(f"Accessed: {lnk.access_time}") print(f"File size: {lnk.file_size}") # Print full details print(lnk) ``` -------------------------------- ### Create Shortcuts to Local Files Source: https://context7.com/strayge/pylnk/llms.txt Use the for_file convenience function to generate shortcuts for local files or folders, with options for arguments, icons, and window modes. ```python from pylnk3 import for_file, WINDOW_NORMAL, WINDOW_MAXIMIZED, WINDOW_MINIMIZED # Create a simple shortcut to an executable lnk = for_file( target_file='C:\\Windows\\System32\\notepad.exe', lnk_name='notepad.lnk' ) # Create a shortcut with all options lnk = for_file( target_file='C:\\Program Files\\MyApp\\app.exe', lnk_name='MyApp.lnk', arguments='--config settings.ini', description='Launch MyApp with custom settings', icon_file='C:\\Program Files\\MyApp\\icon.ico', icon_index=0, work_dir='C:\\Program Files\\MyApp', window_mode=WINDOW_MAXIMIZED # or WINDOW_NORMAL, WINDOW_MINIMIZED ) # Create shortcut without saving (to modify before saving) lnk = for_file( target_file='C:\\folder\\file.txt', lnk_name=None # Don't save yet ) lnk.description = 'My custom description' lnk.save('custom_shortcut.lnk') ``` -------------------------------- ### Duplicate Shortcut (CLI) Source: https://context7.com/strayge/pylnk/llms.txt Uses the PyLnk3 CLI tool to duplicate an existing shortcut to a new file. ```bash # Duplicate (read and write) a shortcut pylnk3 duplicate original.lnk copy.lnk pylnk3 d original.lnk copy.lnk ``` -------------------------------- ### Parse Specific Shortcut Properties (CLI) Source: https://context7.com/strayge/pylnk/llms.txt Uses the PyLnk3 CLI tool to parse and display specific properties of a shortcut file. ```bash # Parse and display specific properties pylnk3 parse shortcut.lnk path pylnk3 parse shortcut.lnk description work_dir arguments ``` -------------------------------- ### Create Shortcuts from Segment Lists Source: https://context7.com/strayge/pylnk/llms.txt Use from_segment_list for advanced control over path segments and metadata. ```python from pylnk3 import from_segment_list, TYPE_FOLDER, TYPE_FILE from datetime import datetime ``` -------------------------------- ### Check and Change Window Mode of Existing Shortcut Source: https://context7.com/strayge/pylnk/llms.txt Load an existing shortcut file and inspect or modify its window mode. Changes are saved to a new file. ```python # Check window mode of existing shortcut lnk = Lnk('shortcut.lnk') if lnk.window_mode == WINDOW_MINIMIZED: print("Shortcut opens minimized") # Change window mode lnk.window_mode = WINDOW_NORMAL lnk.save('updated.lnk') ``` -------------------------------- ### Set Window Mode When Creating Shortcut Source: https://context7.com/strayge/pylnk/llms.txt Specify the desired window state (normal, maximized, or minimized) when creating a new shortcut using the `for_file` function. ```python from pylnk3 import \ WINDOW_NORMAL, # Normal window\ WINDOW_MAXIMIZED, # Maximized window\ WINDOW_MINIMIZED, # Minimized to taskbar\ for_file, Lnk # Set window mode when creating lnk = for_file('C:\\app.exe', 'app.lnk', window_mode=WINDOW_MAXIMIZED) ``` -------------------------------- ### Parse LNK File CLI Source: https://github.com/strayge/pylnk/blob/master/README.md Use this command to parse an existing .lnk file and optionally specify properties to read. Requires the filename as a positional argument. ```sh pylnk3 parse [-h] filename [props [props ...]] ``` -------------------------------- ### Specify Local Location with Drive Type Source: https://context7.com/strayge/pylnk/llms.txt Manually define the local path, drive type, drive serial number, and volume label when creating a shortcut. Useful for ensuring correct path resolution. ```python from pylnk3 import \ DRIVE_UNKNOWN, DRIVE_NO_ROOT_DIR, DRIVE_REMOVABLE, # USB drives, floppies\ DRIVE_FIXED, # Hard disks, SSDs\ DRIVE_REMOTE, # Network drives\ DRIVE_CDROM, # CD/DVD drives\ DRIVE_RAMDISK, # RAM disks Lnk # Create shortcut with specific drive type lnk = Lnk() lnk.specify_local_location( path='D:\\Projects\\file.txt', drive_type=DRIVE_FIXED, drive_serial=0xABCD1234, volume_label='Data' ) ``` -------------------------------- ### Modify and Save Shortcuts Source: https://context7.com/strayge/pylnk/llms.txt Loads an existing shortcut, modifies its properties such as description, arguments, working directory, and timestamps, then saves it to a new file or overwrites the original. ```python from pylnk3 import Lnk, WINDOW_MINIMIZED from datetime import datetime # Load existing shortcut lnk = Lnk('existing.lnk') # Modify properties lnk.description = 'Updated description' lnk.arguments = '--new-arg value' lnk.work_dir = 'C:\\NewWorkingDir' lnk.icon = 'C:\\icons\\new_icon.ico' lnk.icon_index = 2 lnk.window_mode = WINDOW_MINIMIZED lnk.hot_key = 'CONTROL+ALT+N' # Update timestamps lnk.creation_time = datetime(2024, 1, 1, 0, 0, 0) lnk.modification_time = datetime.now() # Save to new file lnk.save('modified.lnk') # Or overwrite original (if lnk.file is set) lnk.save() # Save with forced .lnk extension lnk.save('shortcut', force_ext=True) # Creates 'shortcut.lnk' ``` -------------------------------- ### Define Path Segments with Metadata Source: https://context7.com/strayge/pylnk/llms.txt Defines a list of path segments, including drive entries and folder/file metadata, to be used for creating a shortcut. ```python segments = [ 'C:\\', # Drive entry { 'type': TYPE_FOLDER, 'size': 0, 'name': 'Projects', 'created': datetime(2023, 1, 15, 10, 30, 0), 'modified': datetime(2024, 3, 20, 14, 45, 0), 'accessed': datetime(2024, 3, 20, 14, 45, 0) }, { 'type': TYPE_FOLDER, 'size': 0, 'name': 'MyProject', 'created': datetime(2023, 6, 1, 9, 0, 0), 'modified': datetime(2024, 3, 19, 16, 30, 0), 'accessed': datetime(2024, 3, 20, 8, 0, 0) }, { 'type': TYPE_FILE, 'size': 15360, 'name': 'document.txt', 'created': datetime(2024, 1, 10, 11, 0, 0), 'modified': datetime(2024, 3, 15, 9, 30, 0), 'accessed': datetime(2024, 3, 20, 10, 0, 0) } ] # Create and save the shortcut lnk = from_segment_list(segments, 'document.lnk') ``` -------------------------------- ### Check if File is a Valid LNK Source: https://context7.com/strayge/pylnk/llms.txt Checks if a file or file-like object is a valid Windows shortcut by examining its signature using `is_lnk`. ```python from pylnk3 import is_lnk, assert_lnk_signature, FormatException # Check if file is a valid .lnk with open('file.lnk', 'rb') as f: if is_lnk(f): print("Valid .lnk file") else: print("Not a .lnk file") # Strict validation with exception try: with open('file.lnk', 'rb') as f: assert_lnk_signature(f) print("Valid .lnk signature") except FormatException as e: print(f"Invalid file: {e}") # Works with BytesIO too from io import BytesIO data = open('shortcut.lnk', 'rb').read() buf = BytesIO(data) print(f"Is valid: {is_lnk(buf)}") ``` -------------------------------- ### Check Drive Type of Parsed Shortcut Source: https://context7.com/strayge/pylnk/llms.txt After parsing a shortcut file, you can access the drive type information from the internal link info structure to determine the type of media the target resides on. ```python # Check drive type of parsed shortcut lnk = Lnk('shortcut.lnk') if lnk._link_info.drive_type == DRIVE_REMOVABLE: print("Target is on removable media") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.