Repository: ansible/ansible

Issue:
win_shortcut: Using a relative src= can cause error
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
win_shortcut

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
v2.3+

##### SUMMARY
<!--- Explain the problem briefly -->
When using a task like this:
```yaml
- name: Create putty shortcut
  win_shortcut:
    src: 'putty.exe'
    dest: '%Public%\Desktop\PuTTY.lnk'
    icon: '%ProgramFiles%\PuTTY\putty.exe,0'
```

The following error occurs:
```
fatal: [windows-2012]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "
        Exception setting \"TargetPath\": \"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))\"
        At line:89 char:9
        +         $ShortCut.TargetPath = $src
        +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : CatchFromBaseAdapterSetValueTI", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 1
}
```

This is fixed by using an absolute path:
```yaml
- name: Create putty shortcut
  win_shortcut:
    src: '%ProgramFiles%\PuTTY\putty.exe'
    dest: '%Public%\Desktop\PuTTY.lnk'
    icon: '%ProgramFiles%\PuTTY\putty.exe,0'
```


Discussion:
I think this might just be an understanding. I would expect a relative path to resolve to the user's home directory (or to be a bit more windowsy, I'd expect the relative path root to be the same as %HOMEPATH% for any given user).  So I think the src value needs to change.

to demonstrate this

`ansible windowshosts -m raw -a 'pwd'`

The below ought to fix it - can you test?

```
- name: Create putty shortcut
  win_shortcut:
    src: '%ProgramFiles%\PuTTY\putty.exe'
    dest: '%Public%\Desktop\PuTTY.lnk'
    icon: '%ProgramFiles%\PuTTY\putty.exe,0'
```

That said I think it should be documented that relative paths are relative to %HOMEPATH% though.

needs_info

@jhawkesworth Obviously that fixes it (I stated so in my description), but I think you miss the point of the ticket. It should not bail out the way it did.

BTW If people do this in the GUI, Windows will look for the executable (presumably using the PATH) and possibly makes it an absolute path. In any case, it works there.
!needs_info
Ok I missed the point of the ticket! I didn't know or had forgotten that windows will search for the link target if you create a shortcut in the GUI.  

So, the question is, how to fix it?

In the case you describe, src is 'a file name to search for' rather than any kind of (relative or absolute) path.  I wonder whether to have a 'search_src' alternative to src attribute and make 'src' only accept relative or absolute paths?  That way you could be strict about ensuring the src hasn't changed from what you expect (if idempotency-checking a shortcut is important), but still allow searching for a file.

Or perhaps have a 'mode' parameter, which could either be 'strict' i.e. full or relative src path must be specified or 'normal' which would search like the GUI does?

Catching that particular exception and returning a more user-friendly message like "The shortcut src '\$src\' could not be found" might be enough?

I'd like the strict mode or equivalent functionality from a 'configuration management' point of view, but I understand now why you are expecting different behaviour.


I see two reasonable solutions for this: 
1) Implement proper auto-location using current PATH and `SearchPath` Win32 function for `src` values that don't contain a path separator.
2) require that `src` be an absolute path (eg, fail if no path separator char is found)

I'd kinda lean toward option 2, just because it provides much more predictable behavior and doesn't create a potential order dependency on other configuration (plus, bonus, it's easier ;) )

+1 for option 2. I like predictable :-)
While 2 is the easiest option, we miss out on the fact that it behaves differently to what most users may expect. In a lot of cases people do not know exactly where a binary lives and never had to care about it either. So option 1 to me looks like a win over option 2.
At [19:00 UTC](http://www.thetimezoneconverter.com/?t=19:00&tz=UTC) this ticket will be processed during [the first Windows Sprint](https://github.com/ansible/community/wiki/Windows:-sprints#2017-07-04-1900-utc-sprint-1), we would appreciate if you could join the Sprint to help out with fixing/closing this issue.
This issue was discussed during Windows Spring 1 and it was decided that @dagwieers will implement option 2.

Resolving patch:
diff --git a/lib/ansible/modules/windows/win_shortcut.py b/lib/ansible/modules/windows/win_shortcut.py
--- a/lib/ansible/modules/windows/win_shortcut.py
+++ b/lib/ansible/modules/windows/win_shortcut.py
@@ -34,6 +34,8 @@
   src:
     description:
     - Executable or URL the shortcut points to.
+    - The executable needs to be in your PATH, or has to be an absolute
+      path to the executable.
   description:
     description:
     - Description for the shortcut.
@@ -42,7 +44,7 @@
     description:
     - Destination file for the shortcuting file.
     - File name should have a C(.lnk) or C(.url) extension.
-    required: true
+    required: yes
   args:
     description:
     - Additional arguments for the executable defined in C(src).
@@ -51,7 +53,7 @@
     - Working directory for executable defined in C(src).
   icon:
     description:
-    - Icon used for the shortcut
+    - Icon used for the shortcut.
     - File name should have a C(.ico) extension.
     - The file name is followed by a comma and the number in the library file (.dll) or use 0 for an image file.
   hotkey:
@@ -61,50 +63,56 @@
     description:
     - Influences how the application is displayed when it is launched.
     choices:
-    - default
     - maximized
     - minimized
+    - normal
   state:
     description:
     - When C(present), creates or updates the shortcut.  When C(absent),
       removes the shortcut if it exists.
     choices:
-    - present
     - absent
-    default: 'present'
-author: Dag Wieers (@dagwieers)
+    - present
+    default: present
+author:
+- Dag Wieers (@dagwieers)
 notes:
 - 'The following options can include Windows environment variables: C(dest), C(args), C(description), C(dest), C(directory), C(icon) C(src)'
 - 'Windows has two types of shortcuts: Application and URL shortcuts. URL shortcuts only consists of C(dest) and C(src)'
 '''
 
 EXAMPLES = r'''
-# Create an application shortcut on the desktop
-- win_shortcut:
+- name: Create an application shortcut on the desktop
+  win_shortcut:
     src: C:\Program Files\Mozilla Firefox\Firefox.exe
     dest: C:\Users\Public\Desktop\Mozilla Firefox.lnk
     icon: C:\Program Files\Mozilla Firefox\Firefox.exe,0
 
-# Create the same shortcut using environment variables
-- win_shortcut:
+- name: Create the same shortcut using environment variables
+  win_shortcut:
     description: The Mozilla Firefox web browser
-    src: '%PROGRAMFILES%\Mozilla Firefox\Firefox.exe'
-    dest: '%PUBLIC%\Desktop\Mozilla Firefox.lnk'
-    icon: '%PROGRAMFILES\Mozilla Firefox\Firefox.exe,0'
-    directory: '%PROGRAMFILES%\Mozilla Firefox'
+    src: '%ProgramFiles%\Mozilla Firefox\Firefox.exe'
+    dest: '%Public%\Desktop\Mozilla Firefox.lnk'
+    icon: '%ProgramFiles\Mozilla Firefox\Firefox.exe,0'
+    directory: '%ProgramFiles%\Mozilla Firefox'
+
+- name: Create an application shortcut for an executable in PATH to your desktop
+  win_shortcut:
+    src: cmd.exe
+    dest: Desktop\Command prompt.lnk
 
-# Create a URL shortcut to the Ansible website
-- win_shortcut:
-    src: 'https://ansible.com/'
-    dest: '%PUBLIC%\Desktop\Ansible website.url'
+- name: Create an application shortcut for the Ansible website
+  win_shortcut:
+    src: '%ProgramFiles%\Google\Chrome\Application\chrome.exe'
+    dest: '%UserProfile%\Desktop\Ansible website.lnk'
+    args: --new-window https://ansible.com/
+    directory: '%ProgramFiles%\Google\Chrome\Application'
+    icon: '%ProgramFiles%\Google\Chrome\Application\chrome.exe,0'
 
-# Create an application shortcut for the Ansible website
-- win_shortcut:
-    src: '%PROGRAMFILES%\Google\Chrome\Application\chrome.exe'
-    dest: '%PUBLIC%\Desktop\Ansible website.lnk'
-    args: '--new-window https://ansible.com/'
-    directory: '%PROGRAMFILES%\Google\Chrome\Application'
-    icon: '%PROGRAMFILES%\Google\Chrome\Application\chrome.exe,0'
+- name: Create a URL shortcut for the Ansible website
+  win_shortcut:
+    src: https://ansible.com/
+    dest: '%Public%\Desktop\Ansible website.url'
 '''
 
 RETURN = '''


Test patch:
diff --git a/test/integration/targets/win_shortcut/tasks/clean.yml b/test/integration/targets/win_shortcut/tasks/clean.yml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/win_shortcut/tasks/clean.yml
@@ -0,0 +1,27 @@
+# Test code for the file module.
+# (c) 2017, Dag Wieers <dag@wieers.com>
+
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
+
+- name: Clean up Ansible website link
+  win_file:
+    path: '%UserProfile%\Desktop\Ansible website.url'
+    state: absent
+
+- name: Clean up Registry Editor shortcut
+  win_file:
+    path: '%Public%\Desktop\Registry Editor.lnk'
+    state: absent
diff --git a/test/integration/targets/win_shortcut/tasks/main.yml b/test/integration/targets/win_shortcut/tasks/main.yml
--- a/test/integration/targets/win_shortcut/tasks/main.yml
+++ b/test/integration/targets/win_shortcut/tasks/main.yml
@@ -1,157 +1,34 @@
-- name: Clean up Ansible website link
-  win_file:
-    path: '%UserProfile%\Desktop\Ansible website.url'
-    state: absent
-
-- name: Add Ansible website link on the desktop
-  win_shortcut:
-    src: 'https://ansible.com/'
-    dest: '%UserProfile%\Desktop\Ansible website.url'
-    state: present
-  register: ansible_website_link_add
-
-- name: Check there was a change
-  assert:
-    that:
-    - ansible_website_link_add.changed == true
-
-- name: Add Ansible website link on the desktop again
-  win_shortcut:
-    src: 'https://ansible.com/'
-    dest: '%UserProfile%\Desktop\Ansible website.url'
-    state: present
-  register: ansible_website_link_add_again
-
-- name: Check there was no change
-  assert:
-    that:
-    - ansible_website_link_add_again.changed == false
-
-- name: Remove link
-  win_shortcut:
-    dest: '%UserProfile%\Desktop\Ansible website.url'
-    state: absent
-  register: ansible_website_link_remove
-
-- name: Check there was a change
-  assert:
-    that:
-    - ansible_website_link_remove.changed == true
-
-- name: Remove link again
-  win_shortcut:
-    dest: '%UserProfile%\Desktop\Ansible website.url'
-    state: absent
-  register: ansible_website_link_remove_again
-
-- name: Check there was no change
-  assert:
-    that:
-    - ansible_website_link_remove_again.changed == false
-
-- name: Clean up Registry Editor shortcut
-  win_file:
-    path: '%Public%\Desktop\Registry Editor.lnk'
-    state: absent
-
-- name: Add a regedit shortcut on the desktop
-  win_shortcut:
-    description: "Registry Editor"
-    src: regedit.exe
-    dest: '%Public%\Desktop\Registry Editor.lnk'
-    state: present
-  register: regedit_shortcut_add
-
-- name: Check there was a change
-  assert:
-    that:
-    - regedit_shortcut_add.changed == true
-
-- name: Add a regedit shortcut on the desktop again
-  win_shortcut:
-    description: "Registry Editor"
-    src: regedit.exe
-    dest: '%Public%\Desktop\Registry Editor.lnk'
-    state: present
-  register: regedit_shortcut_add_again
-
-- name: Check there was no change
-  assert:
-    that:
-    - regedit_shortcut_add_again.changed == false
-
-- name: Update a regedit shortcut on the desktop
-  win_shortcut:
-    description: "Registry Editor"
-    src: C:\BogusPath\regedit.exe
-    dest: '%Public%\Desktop\Registry Editor.lnk'
-    state: present
-  register: regedit_shortcut_update
-
-- name: Check there was a change
-  assert:
-    that:
-    - regedit_shortcut_update.changed == true
-
-- name: Update a regedit shortcut on the desktop again
-  win_shortcut:
-    description: "Registry Editor"
-    src: C:\BogusPath\regedit.exe
-    dest: '%Public%\Desktop\Registry Editor.lnk'
-    state: present
-  register: regedit_shortcut_update_again
-
-- name: Check there was no change
-  assert:
-    that:
-    - regedit_shortcut_update_again.changed == false
-
-- name: Add an (explicit) icon
-  win_shortcut:
-    description: "Registry Editor"
-    src: C:\Windows\regedit.exe
-    dest: '%Public%\Desktop\Registry Editor.lnk'
-    icon: 'C:\Windows\regedit.exe,0'
-    state: present
-  register: regedit_shortcut_add_icon
-
-- name: Check there was a change
-  assert:
-    that:
-    - regedit_shortcut_add_icon.changed == true
-
-- name: Add an (explicit) icon again
-  win_shortcut:
-    description: "Registry Editor"
-    src: C:\Windows\regedit.exe
-    dest: '%Public%\Desktop\Registry Editor.lnk'
-    icon: 'C:\Windows\regedit.exe,0'
-    state: present
-  register: regedit_shortcut_add_icon_again
-
-- name: Check there was no change
-  assert:
-    that:
-    - regedit_shortcut_add_icon_again.changed == false
-
-- name: Remove shortcut
-  win_shortcut:
-    dest: '%Public%\Desktop\Registry Editor.lnk'
-    state: absent
-  register: regedit_shortcut_remove
-
-- name: Check there was a change
-  assert:
-    that:
-    - regedit_shortcut_remove.changed == true
-
-- name: Remove shortcut again
-  win_shortcut:
-    dest: '%Public%\Desktop\Registry Editor.lnk'
-    state: absent
-  register: regedit_shortcut_remove_again
-
-- name: Check there was no change
-  assert:
-    that:
-    - regedit_shortcut_remove_again.changed == false
\ No newline at end of file
+# Test code for the file module.
+# (c) 2017, Dag Wieers <dag@wieers.com>
+
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
+
+- name: Clean slate
+  include: clean.yml
+
+- name: Test in normal mode
+  include: tests.yml
+  vars:
+    in_check_mode: no
+
+- name: Clean slate
+  include: clean.yml
+
+- name: Test in check-mode
+  include: tests.yml
+  vars:
+    in_check_mode: yes
+  check_mode: yes
diff --git a/test/integration/targets/win_shortcut/tasks/tests.yml b/test/integration/targets/win_shortcut/tasks/tests.yml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/win_shortcut/tasks/tests.yml
@@ -0,0 +1,249 @@
+# Test code for the file module.
+# (c) 2017, Dag Wieers <dag@wieers.com>
+
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
+
+- name: Add Ansible website link on the desktop
+  win_shortcut:
+    src: https://ansible.com/
+    dest: '%UserProfile%\Desktop\Ansible website.url'
+    state: present
+  register: ansible_website_link_add
+
+- name: Check there was a change
+  assert:
+    that:
+    - ansible_website_link_add.changed == true
+    - ansible_website_link_add.dest == 'C:\\Users\\Administrator\\Desktop\\Ansible website.url'
+    - ansible_website_link_add.src == 'https://ansible.com/'
+
+- name: Add Ansible website link on the desktop again
+  win_shortcut:
+    src: https://ansible.com/
+    dest: '%UserProfile%\Desktop\Ansible website.url'
+    state: present
+  register: ansible_website_link_add_again
+
+- name: Check there was no change (normal mode)
+  assert:
+    that:
+    - ansible_website_link_add_again.changed == false
+    - ansible_website_link_add_again.dest == 'C:\\Users\\Administrator\\Desktop\\Ansible website.url'
+    - ansible_website_link_add_again.src == 'https://ansible.com/'
+  when: not in_check_mode
+
+- name: Check there was a change (check-mode)
+  assert:
+    that:
+    - ansible_website_link_add_again.changed == true
+    - ansible_website_link_add_again.dest == 'C:\\Users\\Administrator\\Desktop\\Ansible website.url'
+    - ansible_website_link_add_again.src == 'https://ansible.com/'
+  when: in_check_mode
+
+- name: Remove link
+  win_shortcut:
+    dest: '%UserProfile%\Desktop\Ansible website.url'
+    state: absent
+  register: ansible_website_link_remove
+
+- name: Check there was a change (normal mode)
+  assert:
+    that:
+    - ansible_website_link_remove.changed == true
+    - ansible_website_link_remove.dest == 'C:\\Users\\Administrator\\Desktop\\Ansible website.url'
+  when: not in_check_mode
+
+- name: Check there was no change (check-mode)
+  assert:
+    that:
+    - ansible_website_link_remove.changed == false
+    - ansible_website_link_remove.dest == 'C:\\Users\\Administrator\\Desktop\\Ansible website.url'
+  when: in_check_mode
+
+- name: Remove link again
+  win_shortcut:
+    dest: '%UserProfile%\Desktop\Ansible website.url'
+    state: absent
+  register: ansible_website_link_remove_again
+
+- name: Check there was no change
+  assert:
+    that:
+    - ansible_website_link_remove_again.changed == false
+    - ansible_website_link_remove_again.dest == 'C:\\Users\\Administrator\\Desktop\\Ansible website.url'
+
+- name: Add a regedit shortcut on the desktop
+  win_shortcut:
+    description: "Registry Editor"
+    src: regedit.exe
+    dest: '%Public%\Desktop\Registry Editor.lnk'
+    state: present
+  register: regedit_shortcut_add
+
+- name: Check there was a change
+  assert:
+    that:
+    - regedit_shortcut_add.changed == true
+    - regedit_shortcut_add.description == 'Registry Editor'
+    - regedit_shortcut_add.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+    - regedit_shortcut_add.src == 'C:\\Windows\\regedit.exe'
+
+- name: Add a regedit shortcut on the desktop again
+  win_shortcut:
+    description: "Registry Editor"
+    src: regedit.exe
+    dest: '%Public%\Desktop\Registry Editor.lnk'
+    state: present
+  register: regedit_shortcut_add_again
+
+- name: Check there was no change (normal mode)
+  assert:
+    that:
+    - regedit_shortcut_add_again.changed == false
+    - regedit_shortcut_add_again.description == 'Registry Editor'
+    - regedit_shortcut_add_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+    - regedit_shortcut_add_again.src == 'C:\\Windows\\regedit.exe'
+  when: not in_check_mode
+
+- name: Check there was a change (check-mode)
+  assert:
+    that:
+    - regedit_shortcut_add_again.changed == true
+    - regedit_shortcut_add_again.description == 'Registry Editor'
+    - regedit_shortcut_add_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+    - regedit_shortcut_add_again.src == 'C:\\Windows\\regedit.exe'
+  when: in_check_mode
+
+- name: Update a regedit shortcut on the desktop
+  win_shortcut:
+    description: "Registry Editor"
+    src: C:\BogusPath\regedit.exe
+    dest: '%Public%\Desktop\Registry Editor.lnk'
+    state: present
+  register: regedit_shortcut_update
+
+- name: Check there was a change
+  assert:
+    that:
+    - regedit_shortcut_update.changed == true
+    - regedit_shortcut_update.description == 'Registry Editor'
+    - regedit_shortcut_update.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+    - regedit_shortcut_update.src == 'C:\\BogusPath\\regedit.exe'
+
+- name: Update a regedit shortcut on the desktop again
+  win_shortcut:
+    description: "Registry Editor"
+    src: C:\BogusPath\regedit.exe
+    dest: '%Public%\Desktop\Registry Editor.lnk'
+    state: present
+  register: regedit_shortcut_update_again
+
+- name: Check there was no change (normal mode)
+  assert:
+    that:
+    - regedit_shortcut_update_again.changed == false
+    - regedit_shortcut_update_again.description == 'Registry Editor'
+    - regedit_shortcut_update_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+    - regedit_shortcut_update_again.src == 'C:\\BogusPath\\regedit.exe'
+  when: not in_check_mode
+
+- name: Check there was a change (check-mode)
+  assert:
+    that:
+    - regedit_shortcut_update_again.changed == true
+    - regedit_shortcut_update_again.description == 'Registry Editor'
+    - regedit_shortcut_update_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+    - regedit_shortcut_update_again.src == 'C:\\BogusPath\\regedit.exe'
+  when: in_check_mode
+
+- name: Add an (explicit) icon
+  win_shortcut:
+    description: "Registry Editor"
+    src: C:\Windows\regedit.exe
+    dest: '%Public%\Desktop\Registry Editor.lnk'
+    icon: 'C:\Windows\regedit.exe,0'
+    state: present
+  register: regedit_shortcut_add_icon
+
+- name: Check there was a change
+  assert:
+    that:
+    - regedit_shortcut_add_icon.changed == true
+    - regedit_shortcut_add_icon.description == 'Registry Editor'
+    - regedit_shortcut_add_icon.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+    - regedit_shortcut_add_icon.icon == 'C:\\Windows\\regedit.exe,0'
+    - regedit_shortcut_add_icon.src == 'C:\\Windows\\regedit.exe'
+
+- name: Add an (explicit) icon again
+  win_shortcut:
+    description: "Registry Editor"
+    src: C:\Windows\regedit.exe
+    dest: '%Public%\Desktop\Registry Editor.lnk'
+    icon: 'C:\Windows\regedit.exe,0'
+    state: present
+  register: regedit_shortcut_add_icon_again
+
+- name: Check there was no change (normal mode)
+  assert:
+    that:
+    - regedit_shortcut_add_icon_again.changed == false
+    - regedit_shortcut_add_icon_again.description == 'Registry Editor'
+    - regedit_shortcut_add_icon_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+    - regedit_shortcut_add_icon_again.icon == 'C:\\Windows\\regedit.exe,0'
+    - regedit_shortcut_add_icon_again.src == 'C:\\Windows\\regedit.exe'
+  when: not in_check_mode
+
+- name: Check there was a change (check-mode)
+  assert:
+    that:
+    - regedit_shortcut_add_icon_again.changed == true
+    - regedit_shortcut_add_icon_again.description == 'Registry Editor'
+    - regedit_shortcut_add_icon_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+    - regedit_shortcut_add_icon_again.icon == 'C:\\Windows\\regedit.exe,0'
+    - regedit_shortcut_add_icon_again.src == 'C:\\Windows\\regedit.exe'
+  when: in_check_mode
+
+- name: Remove shortcut
+  win_shortcut:
+    dest: '%Public%\Desktop\Registry Editor.lnk'
+    state: absent
+  register: regedit_shortcut_remove
+
+- name: Check there was a change (normal mode)
+  assert:
+    that:
+    - regedit_shortcut_remove.changed == true
+    - regedit_shortcut_remove.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+  when: not in_check_mode
+
+- name: Check there was no change (check-mode)
+  assert:
+    that:
+    - regedit_shortcut_remove.changed == false
+    - regedit_shortcut_remove.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'
+  when: in_check_mode
+
+- name: Remove shortcut again
+  win_shortcut:
+    dest: '%Public%\Desktop\Registry Editor.lnk'
+    state: absent
+  register: regedit_shortcut_remove_again
+
+- name: Check there was no change
+  assert:
+    that:
+    - regedit_shortcut_remove_again.changed == false
+    - regedit_shortcut_remove_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk'