'Get "Start In" field using batch
I am writing a program that looks at current plugged-in status, whether there's an external graphics card plugged in, and does a handful of things based on the results.
One of which, I am hoping to start programs using Shortcuts that are placed in one of a handful of folders.
This is all well and good. However, one of the programs that needs to be started also needs to have a .ini file replaced in the original location (e.g. C:\Folder\Shortcut.ini) at the time of startup.
SO. I need to get the "Start In" field (e.g. C:\Folder) from the shortcut/.lnk.
How would I go about doing this?
My google-fu is struggling here, because "start in" and "shortcut" all seem to lead to how to create a shortcut to start a batch file in a specific folder or to pass the location you run a batch file from to the program.
:StartPrograms
if "%Mode%" EQU "Docked" for %%a in ("%RunPath%StartPrograms\Docked\*.lnk") do (start "" %%a)
if "%Mode%" EQU "EGPU" for %%a in ("%RunPath%StartPrograms\EGPU\*.lnk") do (start "" %%a)
if "%Mode%" EQU "Handheld" for %%a in ("%RunPath%StartPrograms\Handheld\*.lnk") do (start "" %%a)
for %%a in ("%RunPath%StartPrograms\Always\*.lnk") do (start "" %%a)
exit /b
I want the "Start In" field here; or the full path of the shortcut as a string.
Solution 1:[1]
You can call out to WMIC in a batch file as pointed out in this answer.
But you could also call out to Powershell as well within a batch file.
FOR /F "usebackq delims=" %%G IN (`"powershell $sh = New-Object -COM WScript.Shell; $sh.CreateShortcut('C:\Users\Public\Desktop\WinSCP.lnk').WorkingDirectory"`) DO @ECHO %%G
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Squashman |
