-1

I have an old (Windows 2003) server running. I then have a Powershell script which I need to execute using a scheduled task (running it on it's own works fine). On all my other (windows 2008) servers, when the Scheduled Task runs, the powershell window displays in the foreground, giving a visual indication that it is running.

But on my Windows 2003 server, it appears to be running, but not in the foreground. My script restarts an application, and when it restarts, I can see in task manager that it is running, but I don't know where.

I am logged in as Administrator. The task is set with run only if logged in. The Task Scheduler service has allow service to interact with the desktop ticked.

What else do I need to do to make it run in the foreground, and more importantly, restart my application in the foreground?

I also set up a basic test.cmd file which writes a single line to the screen, and that also doesn't work in task scheduler.


UPDATE

It seems the problem is due to the Task Scheduler running everything in Session 0 (Console), instead of Session 1 (RDP). Is there any way to force it to run the scripts in the correct session (1)?

IGGt
  • 135
  • 6
  • unfortunately no. I just put it down to it being Win 2003. As it didn't appear to have any noticeable affect on the result of my script I just left it running, and periodically go in and manually reset things. – IGGt May 11 '15 at 10:08
  • `mstsc.exe /admin` (on newer systems) or `mstsc.exe /console` (on older systems) will log you in to session 0. – Massimo Mar 28 '20 at 22:10

2 Answers2

0

Powershell is standard from Windows Server 2008r2 and not in earlier versions, including your windows server 2003. You have to install this feature seperatly to get it to work in 2003. Did you do this? Else, it will not work.

Saeed
  • 366
  • 3
  • 11
  • It is installed ok. If I `right click > run with powershell` on my ps1 file it runs as expected, in the foreground. I also tested a basic file (test.cmd) which just has the text `echo "This is a Test"` and tried to run this in Task Scheduler. And that was exactly the same. e.g. it runs (I can see `cmd` appear in task scheduler), but I don't know where as I can't see the window. – IGGt Apr 01 '15 at 09:21
  • I'm sorry this answer of mine has not been correct. I see that you already said "running it on it's own works fine". What happens when you let this start in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run. Just to test it if it will run then – Saeed Apr 01 '15 at 09:25
  • sorry, I'm not quite sure what you mean? – IGGt Apr 01 '15 at 09:42
  • You want to run a powershell script when the user logs in, using the task scheduler method. You can also achieve this by using the Run key in the registry. The keys in this path will run each time the "current user" is logged in. Or is your question that you dont know how this works? – Saeed Apr 01 '15 at 09:44
  • I see. Unfortunately I can't test this currently as the current user needs to be logged in permanently, in order for all the applications to keep running. This is on a live server. n.b. I have powershell, VBS, batch file versions of this script, none of them are working, it's not limited to just powershell. – IGGt Apr 01 '15 at 09:50
  • This is very strange, I have no idea my friend, im sorry bout this. I have never had this. You can run it on its own but not when its run in a task. What about event viewer? Have you checked that? Does it show an error message? – Saeed Apr 01 '15 at 10:00
  • OK cheers anyway. I checked Event Viewer, and there was nothing out of the ordinary that helps. – IGGt Apr 01 '15 at 10:12
0

it worked for me. In Task manager, go to Users Tab and click on Session 0, right click and connect. It opens up Session 0 and you can see all the tasks running in foreground on this session. Thanks for your help.

Alok
  • 101
  • 2
  • 1
    cheers, but the problem wasn't seeing the scripts running, because as you point, out we could simply log into Session 0. The problem was trying to make the scripts run in Session 1, so that my applications were restarted in Session 1 and not 'hidden' in session 0. – IGGt May 11 '15 at 10:13
  • ah, slightly different issue then. I didn't know how to login to session 0, i could only connect to it from session 1. (only RDP available on this server). i only wanted to see the windows on foreground because on of them was getting some exception which was not caught properly. All ok now. – Alok May 11 '15 at 11:03
  • `mstsc.exe /admin` (on newer systems) or `mstsc.exe /console` (on older systems) will log you in to session 0. – Massimo Mar 28 '20 at 22:10