How to Launch an App in an Existing Session












2














When a scheduled task runs I would like to open a Powershell window on my desktop to tail the log file and watch the progress. Specifically I would like the task to open the window on my desktop and run Get-Content C:LogFile.txt -Wait. When the task has finished I would like it to close the powershell window.



Is there a way to start a graphical window under another user? From what I have found, most commands will run under the privilege of the specified user but not create a window on their desktop.



It would be even nicer if it would run under whichever user is logged on when the task starts and not a hard coded user.



EDIT: So far I have the code below. I works to an extent. It creates the tailing window but when I call $p.kill() it kills the psexec process but not the powershell process. Can I send a Ctrl-C to the powershell window?



# start tailing the log
$psexec = 'c:psexec.exe'
$arguments = '-i powershell.exe -windowstyle maximized -command "& {get-content c:logstask_log.log -wait}"'
$p = start-process $psexec -argumentlist $arguments -passthru
# start the task
Some-task.exe
# kill the tail
$p.kill()









share|improve this question




















  • 2




    You keep saying 'I WOULD like...', How far along in this script are you? Is launching a window under another user the only problem/question here?
    – Wutnaut
    May 1 '14 at 18:42










  • @Wutnaut Well I have the task that runs a powershell script and creates the log file. Currently I just open the log file manually.
    – TwistedTech
    May 1 '14 at 18:52










  • @Colyn1337 I haven't tried to many things since everything I can think of just runs under the privilege of the account. I don't know how to start a graphical window under another account which is why I asked.
    – TwistedTech
    May 1 '14 at 18:53
















2














When a scheduled task runs I would like to open a Powershell window on my desktop to tail the log file and watch the progress. Specifically I would like the task to open the window on my desktop and run Get-Content C:LogFile.txt -Wait. When the task has finished I would like it to close the powershell window.



Is there a way to start a graphical window under another user? From what I have found, most commands will run under the privilege of the specified user but not create a window on their desktop.



It would be even nicer if it would run under whichever user is logged on when the task starts and not a hard coded user.



EDIT: So far I have the code below. I works to an extent. It creates the tailing window but when I call $p.kill() it kills the psexec process but not the powershell process. Can I send a Ctrl-C to the powershell window?



# start tailing the log
$psexec = 'c:psexec.exe'
$arguments = '-i powershell.exe -windowstyle maximized -command "& {get-content c:logstask_log.log -wait}"'
$p = start-process $psexec -argumentlist $arguments -passthru
# start the task
Some-task.exe
# kill the tail
$p.kill()









share|improve this question




















  • 2




    You keep saying 'I WOULD like...', How far along in this script are you? Is launching a window under another user the only problem/question here?
    – Wutnaut
    May 1 '14 at 18:42










  • @Wutnaut Well I have the task that runs a powershell script and creates the log file. Currently I just open the log file manually.
    – TwistedTech
    May 1 '14 at 18:52










  • @Colyn1337 I haven't tried to many things since everything I can think of just runs under the privilege of the account. I don't know how to start a graphical window under another account which is why I asked.
    – TwistedTech
    May 1 '14 at 18:53














2












2








2







When a scheduled task runs I would like to open a Powershell window on my desktop to tail the log file and watch the progress. Specifically I would like the task to open the window on my desktop and run Get-Content C:LogFile.txt -Wait. When the task has finished I would like it to close the powershell window.



Is there a way to start a graphical window under another user? From what I have found, most commands will run under the privilege of the specified user but not create a window on their desktop.



It would be even nicer if it would run under whichever user is logged on when the task starts and not a hard coded user.



EDIT: So far I have the code below. I works to an extent. It creates the tailing window but when I call $p.kill() it kills the psexec process but not the powershell process. Can I send a Ctrl-C to the powershell window?



# start tailing the log
$psexec = 'c:psexec.exe'
$arguments = '-i powershell.exe -windowstyle maximized -command "& {get-content c:logstask_log.log -wait}"'
$p = start-process $psexec -argumentlist $arguments -passthru
# start the task
Some-task.exe
# kill the tail
$p.kill()









share|improve this question















When a scheduled task runs I would like to open a Powershell window on my desktop to tail the log file and watch the progress. Specifically I would like the task to open the window on my desktop and run Get-Content C:LogFile.txt -Wait. When the task has finished I would like it to close the powershell window.



Is there a way to start a graphical window under another user? From what I have found, most commands will run under the privilege of the specified user but not create a window on their desktop.



It would be even nicer if it would run under whichever user is logged on when the task starts and not a hard coded user.



EDIT: So far I have the code below. I works to an extent. It creates the tailing window but when I call $p.kill() it kills the psexec process but not the powershell process. Can I send a Ctrl-C to the powershell window?



# start tailing the log
$psexec = 'c:psexec.exe'
$arguments = '-i powershell.exe -windowstyle maximized -command "& {get-content c:logstask_log.log -wait}"'
$p = start-process $psexec -argumentlist $arguments -passthru
# start the task
Some-task.exe
# kill the tail
$p.kill()






windows-7 powershell psexec session-hijacking






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 1 '14 at 21:15







TwistedTech

















asked May 1 '14 at 18:26









TwistedTechTwistedTech

102315




102315








  • 2




    You keep saying 'I WOULD like...', How far along in this script are you? Is launching a window under another user the only problem/question here?
    – Wutnaut
    May 1 '14 at 18:42










  • @Wutnaut Well I have the task that runs a powershell script and creates the log file. Currently I just open the log file manually.
    – TwistedTech
    May 1 '14 at 18:52










  • @Colyn1337 I haven't tried to many things since everything I can think of just runs under the privilege of the account. I don't know how to start a graphical window under another account which is why I asked.
    – TwistedTech
    May 1 '14 at 18:53














  • 2




    You keep saying 'I WOULD like...', How far along in this script are you? Is launching a window under another user the only problem/question here?
    – Wutnaut
    May 1 '14 at 18:42










  • @Wutnaut Well I have the task that runs a powershell script and creates the log file. Currently I just open the log file manually.
    – TwistedTech
    May 1 '14 at 18:52










  • @Colyn1337 I haven't tried to many things since everything I can think of just runs under the privilege of the account. I don't know how to start a graphical window under another account which is why I asked.
    – TwistedTech
    May 1 '14 at 18:53








2




2




You keep saying 'I WOULD like...', How far along in this script are you? Is launching a window under another user the only problem/question here?
– Wutnaut
May 1 '14 at 18:42




You keep saying 'I WOULD like...', How far along in this script are you? Is launching a window under another user the only problem/question here?
– Wutnaut
May 1 '14 at 18:42












@Wutnaut Well I have the task that runs a powershell script and creates the log file. Currently I just open the log file manually.
– TwistedTech
May 1 '14 at 18:52




@Wutnaut Well I have the task that runs a powershell script and creates the log file. Currently I just open the log file manually.
– TwistedTech
May 1 '14 at 18:52












@Colyn1337 I haven't tried to many things since everything I can think of just runs under the privilege of the account. I don't know how to start a graphical window under another account which is why I asked.
– TwistedTech
May 1 '14 at 18:53




@Colyn1337 I haven't tried to many things since everything I can think of just runs under the privilege of the account. I don't know how to start a graphical window under another account which is why I asked.
– TwistedTech
May 1 '14 at 18:53










1 Answer
1






active

oldest

votes


















0














First, you'll need PSExec.exe, it's free and provided by the sys internals group. You want a command similar to this:



psexec \RemoteComputer "%systemroot%system32windowspowershellv1.0powershell.exe" -u username -p password -i -h


Read the PSExec help file and play around with the settings. You'll be most interested in the '-i' switch as it's what indicates the session to interact with. Just using the '-i' without a session id (like in the example), psexec just chooses one. If there isn't one available, it'll use session 0.



You may even find that the New-PSSession and Enter-PSSession Powershell cmdlets are better suited to what you need. On your computer, run the following in powershell:



$Session = New-PSSession -ComputerName computer.domain.com
Enter-PSSession -Session $Session


When you run those commands, your terminal on your machine becomes the terminal on the remote machine. Commands you enter in the remote session are executed on the remote machine and the output is fed back to yours. When your done enter the Exit-PSSession command to return to your own session.






share|improve this answer























  • So to get the window to show up on that user's desktop I need to specify the session id? Is there a way to list the existing sessions?
    – TwistedTech
    May 1 '14 at 19:06






  • 1




    @TwistedTech performing operations in someone else's session is a huge responsibility. There's a certain level of knowledge required to own that responsibility effectively. Take some time and research some more before you attempt something like this.
    – Colyn1337
    May 1 '14 at 19:13












  • I know. The accounts are utility accounts for kiosks. I am not taking over another person's session. (Someone else added the session-hijacking tag. I don't really agree that is what I am trying to do but I left it anyway.)
    – TwistedTech
    May 1 '14 at 19:18












  • While Powershell remoting is awesome, I actually do want the window to appear. My goal is to be able to look at the screen of a kiosk and check where the task is at. The task can take up to an hour to run and I want to know what it is doing without having to open the log on each machine.
    – TwistedTech
    May 1 '14 at 21:18






  • 2




    @TwistedTech, why can't you just monitor the state of all the kiosks from one central computer?
    – dangph
    May 1 '14 at 22:23











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f748581%2fhow-to-launch-an-app-in-an-existing-session%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














First, you'll need PSExec.exe, it's free and provided by the sys internals group. You want a command similar to this:



psexec \RemoteComputer "%systemroot%system32windowspowershellv1.0powershell.exe" -u username -p password -i -h


Read the PSExec help file and play around with the settings. You'll be most interested in the '-i' switch as it's what indicates the session to interact with. Just using the '-i' without a session id (like in the example), psexec just chooses one. If there isn't one available, it'll use session 0.



You may even find that the New-PSSession and Enter-PSSession Powershell cmdlets are better suited to what you need. On your computer, run the following in powershell:



$Session = New-PSSession -ComputerName computer.domain.com
Enter-PSSession -Session $Session


When you run those commands, your terminal on your machine becomes the terminal on the remote machine. Commands you enter in the remote session are executed on the remote machine and the output is fed back to yours. When your done enter the Exit-PSSession command to return to your own session.






share|improve this answer























  • So to get the window to show up on that user's desktop I need to specify the session id? Is there a way to list the existing sessions?
    – TwistedTech
    May 1 '14 at 19:06






  • 1




    @TwistedTech performing operations in someone else's session is a huge responsibility. There's a certain level of knowledge required to own that responsibility effectively. Take some time and research some more before you attempt something like this.
    – Colyn1337
    May 1 '14 at 19:13












  • I know. The accounts are utility accounts for kiosks. I am not taking over another person's session. (Someone else added the session-hijacking tag. I don't really agree that is what I am trying to do but I left it anyway.)
    – TwistedTech
    May 1 '14 at 19:18












  • While Powershell remoting is awesome, I actually do want the window to appear. My goal is to be able to look at the screen of a kiosk and check where the task is at. The task can take up to an hour to run and I want to know what it is doing without having to open the log on each machine.
    – TwistedTech
    May 1 '14 at 21:18






  • 2




    @TwistedTech, why can't you just monitor the state of all the kiosks from one central computer?
    – dangph
    May 1 '14 at 22:23
















0














First, you'll need PSExec.exe, it's free and provided by the sys internals group. You want a command similar to this:



psexec \RemoteComputer "%systemroot%system32windowspowershellv1.0powershell.exe" -u username -p password -i -h


Read the PSExec help file and play around with the settings. You'll be most interested in the '-i' switch as it's what indicates the session to interact with. Just using the '-i' without a session id (like in the example), psexec just chooses one. If there isn't one available, it'll use session 0.



You may even find that the New-PSSession and Enter-PSSession Powershell cmdlets are better suited to what you need. On your computer, run the following in powershell:



$Session = New-PSSession -ComputerName computer.domain.com
Enter-PSSession -Session $Session


When you run those commands, your terminal on your machine becomes the terminal on the remote machine. Commands you enter in the remote session are executed on the remote machine and the output is fed back to yours. When your done enter the Exit-PSSession command to return to your own session.






share|improve this answer























  • So to get the window to show up on that user's desktop I need to specify the session id? Is there a way to list the existing sessions?
    – TwistedTech
    May 1 '14 at 19:06






  • 1




    @TwistedTech performing operations in someone else's session is a huge responsibility. There's a certain level of knowledge required to own that responsibility effectively. Take some time and research some more before you attempt something like this.
    – Colyn1337
    May 1 '14 at 19:13












  • I know. The accounts are utility accounts for kiosks. I am not taking over another person's session. (Someone else added the session-hijacking tag. I don't really agree that is what I am trying to do but I left it anyway.)
    – TwistedTech
    May 1 '14 at 19:18












  • While Powershell remoting is awesome, I actually do want the window to appear. My goal is to be able to look at the screen of a kiosk and check where the task is at. The task can take up to an hour to run and I want to know what it is doing without having to open the log on each machine.
    – TwistedTech
    May 1 '14 at 21:18






  • 2




    @TwistedTech, why can't you just monitor the state of all the kiosks from one central computer?
    – dangph
    May 1 '14 at 22:23














0












0








0






First, you'll need PSExec.exe, it's free and provided by the sys internals group. You want a command similar to this:



psexec \RemoteComputer "%systemroot%system32windowspowershellv1.0powershell.exe" -u username -p password -i -h


Read the PSExec help file and play around with the settings. You'll be most interested in the '-i' switch as it's what indicates the session to interact with. Just using the '-i' without a session id (like in the example), psexec just chooses one. If there isn't one available, it'll use session 0.



You may even find that the New-PSSession and Enter-PSSession Powershell cmdlets are better suited to what you need. On your computer, run the following in powershell:



$Session = New-PSSession -ComputerName computer.domain.com
Enter-PSSession -Session $Session


When you run those commands, your terminal on your machine becomes the terminal on the remote machine. Commands you enter in the remote session are executed on the remote machine and the output is fed back to yours. When your done enter the Exit-PSSession command to return to your own session.






share|improve this answer














First, you'll need PSExec.exe, it's free and provided by the sys internals group. You want a command similar to this:



psexec \RemoteComputer "%systemroot%system32windowspowershellv1.0powershell.exe" -u username -p password -i -h


Read the PSExec help file and play around with the settings. You'll be most interested in the '-i' switch as it's what indicates the session to interact with. Just using the '-i' without a session id (like in the example), psexec just chooses one. If there isn't one available, it'll use session 0.



You may even find that the New-PSSession and Enter-PSSession Powershell cmdlets are better suited to what you need. On your computer, run the following in powershell:



$Session = New-PSSession -ComputerName computer.domain.com
Enter-PSSession -Session $Session


When you run those commands, your terminal on your machine becomes the terminal on the remote machine. Commands you enter in the remote session are executed on the remote machine and the output is fed back to yours. When your done enter the Exit-PSSession command to return to your own session.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 1 '14 at 19:24

























answered May 1 '14 at 19:01









Colyn1337Colyn1337

1,163823




1,163823












  • So to get the window to show up on that user's desktop I need to specify the session id? Is there a way to list the existing sessions?
    – TwistedTech
    May 1 '14 at 19:06






  • 1




    @TwistedTech performing operations in someone else's session is a huge responsibility. There's a certain level of knowledge required to own that responsibility effectively. Take some time and research some more before you attempt something like this.
    – Colyn1337
    May 1 '14 at 19:13












  • I know. The accounts are utility accounts for kiosks. I am not taking over another person's session. (Someone else added the session-hijacking tag. I don't really agree that is what I am trying to do but I left it anyway.)
    – TwistedTech
    May 1 '14 at 19:18












  • While Powershell remoting is awesome, I actually do want the window to appear. My goal is to be able to look at the screen of a kiosk and check where the task is at. The task can take up to an hour to run and I want to know what it is doing without having to open the log on each machine.
    – TwistedTech
    May 1 '14 at 21:18






  • 2




    @TwistedTech, why can't you just monitor the state of all the kiosks from one central computer?
    – dangph
    May 1 '14 at 22:23


















  • So to get the window to show up on that user's desktop I need to specify the session id? Is there a way to list the existing sessions?
    – TwistedTech
    May 1 '14 at 19:06






  • 1




    @TwistedTech performing operations in someone else's session is a huge responsibility. There's a certain level of knowledge required to own that responsibility effectively. Take some time and research some more before you attempt something like this.
    – Colyn1337
    May 1 '14 at 19:13












  • I know. The accounts are utility accounts for kiosks. I am not taking over another person's session. (Someone else added the session-hijacking tag. I don't really agree that is what I am trying to do but I left it anyway.)
    – TwistedTech
    May 1 '14 at 19:18












  • While Powershell remoting is awesome, I actually do want the window to appear. My goal is to be able to look at the screen of a kiosk and check where the task is at. The task can take up to an hour to run and I want to know what it is doing without having to open the log on each machine.
    – TwistedTech
    May 1 '14 at 21:18






  • 2




    @TwistedTech, why can't you just monitor the state of all the kiosks from one central computer?
    – dangph
    May 1 '14 at 22:23
















So to get the window to show up on that user's desktop I need to specify the session id? Is there a way to list the existing sessions?
– TwistedTech
May 1 '14 at 19:06




So to get the window to show up on that user's desktop I need to specify the session id? Is there a way to list the existing sessions?
– TwistedTech
May 1 '14 at 19:06




1




1




@TwistedTech performing operations in someone else's session is a huge responsibility. There's a certain level of knowledge required to own that responsibility effectively. Take some time and research some more before you attempt something like this.
– Colyn1337
May 1 '14 at 19:13






@TwistedTech performing operations in someone else's session is a huge responsibility. There's a certain level of knowledge required to own that responsibility effectively. Take some time and research some more before you attempt something like this.
– Colyn1337
May 1 '14 at 19:13














I know. The accounts are utility accounts for kiosks. I am not taking over another person's session. (Someone else added the session-hijacking tag. I don't really agree that is what I am trying to do but I left it anyway.)
– TwistedTech
May 1 '14 at 19:18






I know. The accounts are utility accounts for kiosks. I am not taking over another person's session. (Someone else added the session-hijacking tag. I don't really agree that is what I am trying to do but I left it anyway.)
– TwistedTech
May 1 '14 at 19:18














While Powershell remoting is awesome, I actually do want the window to appear. My goal is to be able to look at the screen of a kiosk and check where the task is at. The task can take up to an hour to run and I want to know what it is doing without having to open the log on each machine.
– TwistedTech
May 1 '14 at 21:18




While Powershell remoting is awesome, I actually do want the window to appear. My goal is to be able to look at the screen of a kiosk and check where the task is at. The task can take up to an hour to run and I want to know what it is doing without having to open the log on each machine.
– TwistedTech
May 1 '14 at 21:18




2




2




@TwistedTech, why can't you just monitor the state of all the kiosks from one central computer?
– dangph
May 1 '14 at 22:23




@TwistedTech, why can't you just monitor the state of all the kiosks from one central computer?
– dangph
May 1 '14 at 22:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f748581%2fhow-to-launch-an-app-in-an-existing-session%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Plaza Victoria

Puebla de Zaragoza

Musa