Question:
Setting the boot start of a specified application is not the result I want, it lacks a lot of selectivity. Trying to implement a small daily feature myself using powershell, window laptop boots up and quickly opens the specified apps.
Most of the other apps open perfectly, but there are three apps (tailscale, vscode, obsidian) that always appear to shut down when powershell is turned off after execution.
I’m wondering if anyone has any ideas on how to do this?
The script I use is as follows:
- get the location of the shortcut files in the specified directory, so that you can choose which ones you want to customize the quick step2. according to the result of step 1, pick which apps you want to customize.
getDesktopAllShortPath.ps1
# Define the directory to be searched
$targetDirectory = "d:\desktop"
# Get the current directory of the script
$currentDirectory = Get-Location
# Define the output file path
$outputFile = Join-Path -Path $currentDirectory -ChildPath "colShorts.txt"
# Find all .lnk files
$shortcuts = Get-ChildItem -Path $targetDirectory -Recurse -Filter *.lnk
# Save the shortcut file path to a file
$shortcuts.FullName | Out-File -FilePath $outputFile -Encoding UTF8
Write-Host "The shortcut file path has been saved to $outputFile"
- According to the result of step 1, I deleted all the normal apps, and only kept the three apps that are doubtful in the following code.
getStartProcess.ps1
$shortcutFiles = @(
"D:\desktop\Obsidian.lnk",
"D:\desktop\Visual Studio Code.lnk",
"D:\desktop\Tailscale.lnk"
)
# Iterate through each shortcut file
foreach ($shortcutFile in $shortcutFiles) {
# Get the path to the application to which the shortcut file points
$appPath = (New-Object -ComObject WScript.Shell).CreateShortcut($shortcutFile).TargetPath
# Check if the application is already running
if (-not (Get-Process | Where-Object { $_.MainModule.FileName -eq $appPath })) {
# If the application is not running, start the application
Start-Process $appPath
} else {
Write-Host "The application $appPath is already running and does not need to be opened again."
}
}
The error log is as follows:
PowerShell 7.4.2
PS C:\Program Files\PowerShell\7> cd
PS C:\Users\auggie> .\getStartProcess.ps1
***
The application C:\Program Files\Mozilla Firefox\firefox.exe is already running and does not need to be opened again.
***
2024-06-04 01:17:42 Loading updated app package C:\Users\auggie\AppData\Roaming\obsidian\obsidian-1.5.12.asar
2024-06-04 01:17:42 Checking for update using Github
The application C:\Program Files\VanDyke Software\Clients\SecureCRT.exe is already running and does not need to be opened again.
2024-06-04 01:17:43 Success.
2024-06-04 01:17:43 Latest version is 1.5.12
2024-06-04 01:17:43 App is up to date.
[main 2024-06-04T01:17:44.749Z] update#setState idle
logtail started
Program starting: v1.66.4-t067defc64-g49481b7d0, Go 1.22.3: []string{"C:\\Program Files\\Tailscale\\tailscale-ipn.exe"}
LogID: be7ecdf60303c188bdfa054d60f440ac53f0e0b9c28194df8d9bff586956ba8b
logpolicy: using LocalAppData dir C:\Users\auggie\AppData\Local\Tailscale
stdout ok.
stderr ok.
log ok.
Running UI client...
ui: creating mainWindow
ui: creating tray
ui: watchBackend: connected.
ui: Handle: logs: be:995e1c9d41456dae3bfe7252f5a4ab263ce0cd646c9e975c27b0df6be3efd01b fe:be7ecdf60303c188bdfa054d60f440ac53f0e0b9c28194df8d9bff586956ba8b
ui: ui: latest version check: "1.66.4", <nil>
PS C:\Users\auggie> [24928:0604/091747.329:ERROR:jump_list.cc(300)] Failed to append custom category 'Recently used folders' to Jump List due to system privacy settings.
[main 2024-06-04T01:17:47.349Z] updateWindowsJumpList#setJumpList unexpected result: customCategoryAccessDeniedError
ui: ui: Notify: running latest version
ui: ui: setLatestVersion("1.66.4", "", false)
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: started taildrive file server at: d6b3b148de9819bec747ca414a56dd46e46c10a0298f2cd50162abdc85ae0b95|127.0.0.1:9810
ui: setting taildrive file server address
ui: set taildrive file server address
ui: Beginning to watch engine updates
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
^C
PS C:\Users\auggie>
PS C:\Users\auggie> ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
PS C:\Users\auggie> ^C
PS C:\Users\auggie>
PS C:\Users\auggie>
PS C:\Users\auggie> ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
PS C:\Users\auggie>
PS C:\Users\auggie> ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
^C
PS C:\Users\auggie>
PS C:\Users\auggie>
PS C:\Users\auggie> ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
[main 2024-06-04T01:18:14.759Z] update#setState checking for updates
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
[main 2024-06-04T01:18:16.219Z] update#setState idle
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later
ui: cacheExitNodeInfo: getSuggestedExitNode failed: unable to suggest an exit node, try again later