"Start in" field for win_shortcut

Hi,
Im making a shortcut in shell:startup, which works.
BUT:
It does not work properly. I have found the reason for this is when you right click the shortcut, the “Start In” field is empty.
When I do it manually, the start in field IS populated with the directory I want.

Is there any way to populate this field? I tried args but it does not work.
Would I be better off having a script do this? If so, any examples?

Thanks!

Not sure I follow.

Can you share your playbook step(s) that you are using?

Jon

Hi Jon,The idea is to put a .py script into the shell:startup folder.
So, I create a shortcut.

When I manually create the shortcut, it looks like the attachment.

When I run this play instead of doing it manually, the “Start In” field is not populated, but everything else is fine.
We can run jobs when that field is populated, but when it’s not it does not run the job. Thus, the start in field must be populated.

I couldn’t find a var that worked, I tried args and everything else in the documentation.

  • name: Create shortcut to Launch Server.py in startup
    win_shortcut:
    src: C:\cygwin\home\YRunner\launch_server.py
    dest: C:\Users\YRunner\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\launch_server.py.lnk

I think an alternative might be using a .sh script triggered by a batch file, but I don’t know the syntax and it would be nice to let ansible do it as it should.

Right, I understand what you mean now.

Did you try setting 'directory' to the location where you want 'start in' to be?

If that doesn't do it, have a look at the module code, it's probably going to be fairly straightforward to add another module parameter, assuming the api supports setting the directory to start in. It would probably be less work than writing your own script.

If you do have to change the module code, please consider creating a pull request to get it included into ansible. You can use it as a custom module by copying into /etc/ansible/library (or wherever 'library' is set to in your ansible.cfg file).

Hope this helps,

Jon

Hi J,
Thanks for the reply.
directory: does not do what i need.
I am afraid I might hose something when I try this.
Would I be looking at the “win_shortcut.psl” file? I have no idea what I would add.
Do you think you could be more specific? I’m not yet a confident coder.

J!
I think I just fixed it!
Just for s+g’s, I tried using directory AND src, and I believe it works now!
Thanks! Very happy!

Larry

Glad you have it working.

Out of interest, yes win_shortcut.ps1 is the right file.

I would recommend getting yourself a windows virtual machine or two to try things out against.
I just use virtualbox, others prefer using vagrant. There are tools around like packer that you can use to spin up windows vms based on the time-limited evaluation versions that ms make available too.

There’s a walk through of how to develop windows modules here - https://docs.ansible.com/ansible/2.4/dev_guide/developing_modules_general_windows.html

Its worth having a look at the other modules if you are thinking of creating your own module.

Hope this helps,

Jon