Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, September 4, 2012 8:25 PM
I've spend a good while reviewing other posts but haven't seen anything that helps me really. Eventually I would like to learn how to kick off other app remotely, but first I need to learn how to simply get Notepad to run. When I run the command in the title above the remote machine opens and closes dllhost.exe and that's it: no notepad. I'm an admin on both the local and remote machines. Please tell me if I missing a few more switches or what?
HomeCookN
All replies (12)
Wednesday, September 5, 2012 2:03 PM ✅Answered | 2 votes
Okay, I think I have an answer for you. You can start notepad this way, and you probably are doing it.
Try this:
Invoke-Command -ComputerName Server2 -ScriptBlock {Start-Process C:\Windows\System32\notepad.exe;get-process}
you should see the notepad process.
Now do this:
get-process -computername Server2
You should not see a notepad.exe process.
The notepad process is created as a child process of the remote session instance that was created on Server2 to run your script block. As soon as the script block finished, the session was removed and all of it's child processes went with it.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Wednesday, September 5, 2012 2:53 PM ✅Answered | 2 votes
The V2 task scheduler has options for that built in.
You can tell it to start a task at specific intervals, but only if there is not already an instance of the task running.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Tuesday, September 4, 2012 8:41 PM | 2 votes
I believe powershell cannot remotely execute commands that have a GUI. You might try PsExec (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx).
G. Samuel Hays
Wednesday, September 5, 2012 1:05 PM
Thanks a lot for turning me on to PsExec, G. Sam; it's a new utility to me and sounds as though it could do what I would like to do. On the other hand, I'm just getting started with PowerShell 3 and I would like to understand its operation a lot better before I branch to yet another new sys admin app to learn.
Plus, it's hard to believe that PowerShell 3.0, with its various remoting-specific cmdlets, can not simply start notepad.exe. Part of the Running Remote Commands page claims that one can run any command on a remote computer. If you--or anyone else--might have any additional info, I would appreciate seeing it.
Windows PowerShell Remoting
Windows PowerShell remoting, which uses the WS-Management protocol, lets you run any Windows PowerShell command on one or many remote computers
HomeCookN
Wednesday, September 5, 2012 1:09 PM | 1 vote
"any Windows Powerhsell command". Notepad is not a Powershell command. You can also run non-interactive command lines remotely.
Grant Ward, a.k.a. Bigteddy
Wednesday, September 5, 2012 1:11 PM | 1 vote
Before you conclude that it's some kind of "bug" that you can't simply start a notepad process, consider the consequeces.
The process is going to start in a non-interactive session. No one will ever see it, or be able to use it.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Wednesday, September 5, 2012 1:26 PM
I'm not saying anything about a bug, my friend. If anything is lacking, it is my knowledge of PowerShell, nothing else. My story is that Powershell can start a remote process with no GUI; I simply want to learn how to do that. I am only using Notepad as a test case.
HomeCookN
Wednesday, September 5, 2012 1:27 PM
I usderstand that Notepad is not a PowerShell Command, Bigtedy; the Poweshell command would be Start-Process; that's what I would like to run remotely.
HomeCookN
Wednesday, September 5, 2012 1:41 PM
From the about_Remote_FAQ, here's why I believe Notepad should be able to be started remotely. So far I have not been able to see Notepad.exe listed on the Task Manager Process tab, which I would think it would be if the process had in fact been started. I'm just trying to learn how to use this tool, guys. Thank you all for your help.
CAN I RUN WINDOWS PROGRAMS ON A REMOTE COMPUTER?
For example, if you use a Windows PowerShell command to run Notepad on a
remote computer, the Notepad process starts on the remote computer, but
the Notepad user interface does not appear. To interrupt the command and
restore the command prompt, press CTRL+C.
HomeCookN
Wednesday, September 5, 2012 1:57 PM | 1 vote
I'm not saying anything about a bug, my friend. If anything is lacking, it is my knowledge of PowerShell, nothing else. My story is that Powershell can start a remote process with no GUI; I simply want to learn how to do that. I am only using Notepad as a test case.
HomeCookN
Notepad is not a good test case, I can't get it to work either. Invoke-Command and its related cmdlets are designed to run non-interactive commands, i.e. commands that do not require user input, but simply return results. Command-line commands are appropriate for remoting.
As mj pointed out, it is useless to start Notepad remotely, and I think the FAQ is just trying to stress this fact, by saying that the only way of stopping it is with Ctrl-C.
Grant Ward, a.k.a. Bigteddy
Wednesday, September 5, 2012 2:35 PM
Yep, you've nailed it! Thank you very much for your time and interest. Here's what I ran with the line results--which I believe I actually understand now--shown below:
1 Invoke-Command -ComputerName Server2 -ScriptBlock {Start-Process notepad.exe;get-process notepad}
2 Get-Process -ComputerName Server2 -Name notepad
3 Start-Sleep 1
4 Get-Process -ComputerName Server2 -Name notepad
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName PSComputerName
--
1 22 6 1276 2752 37 0.00 2676 notepad Server2
2 52 6 1468 3916 42 2676 notepad
4 Get-Process : Cannot find a process with the name "notepad".
HomeCookN
Wednesday, September 5, 2012 2:50 PM
Thanks, Bigteddy; I agree with you that my working with the Notepad test case was a bad idea. And you point out the key take-away, using the Ctrl-C example, that PowerShell remoting is not the right approach to the task of starting a process and then ending the remote session while leaving the remote process still running.
Guess I'll forget about remoting and go back to the original plan of placing a local Task Scheduler task on Server2 which will fire every x minutes, try a Get-Process, doing nothing if it succeeds, but firing a Start-Process in response to a Get-Process error.
I really do appreciate your time.
HomeCookN