How can I run a program on a windows minion desktop (visible)

716 views
Skip to first unread message

John Simmons

unread,
Jul 12, 2016, 10:41:02 AM7/12/16
to Salt-users
I want to run a program on a windows 7 salt-minion desktop.  Something simple, like just opening notepad, with an argument of a specific txt file to open.

This question was addressed [here](https://groups.google.com/forum/#!topic/salt-users/fl1B4bCG-Nk), and the solution appeared to be to go into services.msc and in the properties for salt-minion on the windows 7 minion, select "Allow interaction with the desktop".  That works in a way, but it doesn't actually run the program on the desktop.  For example, if I want to run something simple like notepad, and I send the command

salt 'myWindowsMinion' cmd.run 'start notepad' 

Then on my minion, I get a popup on my desktop that says "Interactive Service Detection", and I have to click to allow it to show, which then takes me to a separate environment, to show the notepad screen.

I imagine this is actually expected behavior for the way I'm running it, but is there any way to actually run something on the master, that opens notepad on a windows 7 minion desktop?

I am not worried about any security concerns.  I'm pretty new to Saltstack, so I apologize if the answer is fairly obvious.

Thanks

John Simmons

unread,
Jul 12, 2016, 10:42:58 AM7/12/16
to Salt-users
Also, I forgot to mention, when I execute the salt 'myWindowsMinion' cmd.run 'start notepad', the master never returns, even after I've closed the Interactive Service Detection warning, and notepad.  It just sits there, and I have to kill the job manually.

John Simmons

unread,
Jul 12, 2016, 11:39:59 AM7/12/16
to Salt-users
I have also tried using a script on the minion, for example, if I use a state, that looks like this

startnotepad:
  cmd.run:
    - name: C:\Users\myuser\Desktop\startnotepad.bat
    - runas: myuser
    - password: mypassword

with the startnotepad.bat looking like this

@echo off
start "notepad" "C:\Users\myuser\Desktop\mytestfile.txt"
exit

Then I get a success, as if it ran ok:

myminion:
----------
          ID: startnotepad
    Function: cmd.run
        Name: C:\Users\myuser\Desktop\startnotepad.bat
      Result: True
     Comment: Command "C:\Users\myuser\Desktop\startnotepad.bat" run
     Started: 08:27:22.068000
     Duration: 226.0 ms
     Changes:   
              ----------
              pid:
                  3004
              retcode:
                  0
              stderr:
              stdout:

Summary for myminion
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1

Message has been deleted

Christopher Baklid

unread,
Jul 13, 2016, 8:15:12 AM7/13/16
to Salt-users
If you enable the "session-id" tab in the view in taskmanager, you'll notice that the process is running under session-id 0, which is a non-interactive session.

The only way I really see this working is by downloading PsExec from microsoft and run it on the minion like so:


salt win7 cmd
.run "C:\psexec.exe -accepteula -d -i 1 notepad"


-acceptuela accepts the uela
-d          detaches the process from salt
-i 1        specifies what session-id the window should appear in (in this case the first user that logs in has id 1)

Unfortunately it starts as the back most window, so if any other windows are open, it start behind those

I hope that helps

John Simmons

unread,
Jul 13, 2016, 12:11:24 PM7/13/16
to Salt-users
Thanks! I think that solution will work for me.

M_Smith

unread,
Jul 13, 2016, 3:58:13 PM7/13/16
to Salt-users
I got this to work for a game client by using powershell to generate a scheduled task that then could be executed remotely. If you want I can dig up the code for it and send it over, but it sounds like the other solution will work as well to me.
Reply all
Reply to author
Forward
0 new messages