Is there a way to programmatically modify the properties of a Windows shortcut?

39 ビュー (過去 30 日間)
Matt
Matt 2017 年 11 月 9 日
回答済み: Brendan Gray 2017 年 11 月 10 日
I want to programmatically change properties like "Target" and "Start in," or create new shortcuts and define those properties, if necessary. I don't know the nature of Windows shortcuts, but the properties are just text. I imagine they are not accessible to MATLAB, however. Could you write a VB script to do this and run that from MATLAB?
Thanks,
Matt

回答 (1 件)

Brendan Gray
Brendan Gray 2017 年 11 月 10 日
You don't need to create a VB script. You can create a COM server using the actxserver function, and access most, if not all of the functionality you need directly from within MATLAB. Something like this should work:
wsh = actxserver('WScript.Shell');
shortcut = wsh.CreateShortcut('C:\folder\shortcut.lnk');
shortcut.TargetPath = 'C:\folder\program.exe';
shortcut.WorkingDirectory = 'C:\folder\';
shortcut.Save;
One thing that is confusing is that CreateShortcut is not only used to create a new shortcut, but also to open existing shortcuts.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by