Link to home
Start Free TrialLog in
Avatar of cha0ticz
cha0ticz

asked on

Modify the working directory of a .lnk file (shortcut file)

I need to change the working directory for a massive amount of *.lnk files in sub directories from a root directory. Everything I've found concerning *.lnk files has been on how to create them using iShellLink and I can't seem to figure out how to simply open an existing shortcut, change its working directory (I know its SetWorkingDirectory, but just initializing the shortcut as a object is the problem I'm having), then saving the changes.

Any help will be greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cha0ticz
cha0ticz

ASKER

jkr,

Thank you for the code, however I'm getting a fail with

hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,IID_IShellLink, (LPVOID*)&psl);

I have objbase and shlobj included as well as ole32.lib and shell32.lib linked so I have no clue why that is failing.
What is the HRESULT value that is returned?
I see a return value of -2147221008 for it. No clue what that is, but it doesn't match S_OK, REGDB_E_CLASSNOTREG, or CLASS_E_NOAGGREGATION . Maybe I'm wrong on that though...
>>-2147221008

...aka 0x800401F0

//
// MessageId: CO_E_NOTINITIALIZED
//
// MessageText:
//
//  CoInitialize has not been called.
//
#define CO_E_NOTINITIALIZED              _HRESULT_TYPEDEF_(0x800401F0L)

I suspect you have not called 'CoInitialize()' :o)
Doh, duh. Thanks for your help!