Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Scheduling powershell.exe

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 10-16-2006   #1 (permalink)
BM
Guest


 

Scheduling powershell.exe


Scheduling ...

Powershell.exe -PSConsoleFile q.psc1 -NonInteractive -NoProfile -command ....

brings up the interactive window.

I dont want the interactive window in the desktop.
I tried
set-executionpolicy unrestrictd
but that does not seem to make any difference .

I am wondering if any one has hit an issue like this one. I am really stuck
here .
Any information will greatly helpful ....





My System SpecsSystem Spec
Old 10-17-2006   #2 (permalink)
klumsy@xtra.co.nz
Guest


 

Re: Scheduling powershell.exe

powershell.exe -?

reveals the following parameter

-Noninteractive
Does not present an interactive prompt to the user.

haven't played with it myself yet, but enjoy

Karl

My System SpecsSystem Spec
Old 10-17-2006   #3 (permalink)
Andrew Webb
Guest


 

RE: Scheduling powershell.exe

Unfortunately, -NonInteractive does not seem to mean "don't show the window
at all".

Andrew Webb
My System SpecsSystem Spec
Old 10-17-2006   #4 (permalink)
Andrew Webb
Guest


 

RE: Scheduling powershell.exe

Even this doesn't manage to *not* show the window...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;

namespace WindowsApplication21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread (new ThreadStart (Start));
thread.IsBackground = true;
thread.Start ();
}

public void Start ()
{
try
{
Process process = new Process ();
process.StartInfo.FileName = "powershell.exe";
process.StartInfo.Arguments = "-Noninteractive -NoLogo -command \"cd
'C:\\Documents and Settings\\Andrew Webb\\Desktop'; ./test.ps1\"";
process.StartInfo.CreateNoWindow = true;
process.Start ();
}
catch (Exception ex)
{
Debug.WriteLine (ex.Message);
}
}
}
}

My System SpecsSystem Spec
Old 10-17-2006   #5 (permalink)
Andrew Webb
Guest


 

RE: Scheduling powershell.exe

Consider writing a program with no window that hosts a PowerShell runspace;
execute your commands/script in that runspace. Lee Holmes has an example of
how to do this on his PowerShell blog:

http://www.leeholmes.com/blog/MSHLog...tionality.aspx

This will *definitely* not show any window.

Andrew Webb
My System SpecsSystem Spec
Old 10-17-2006   #6 (permalink)
Andrew Webb
Guest


 

RE: Scheduling powershell.exe

I got it! Finally!

The following C# code shows how:-

Process process = new Process ();
process.StartInfo.FileName = "powershell.exe";
process.StartInfo.Arguments = "-Noninteractive -NoLogo -command \"cd
'C:\\Documents and Settings\\Andrew Webb\\Desktop'; ./test.ps1\"";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start ();


Andrew Webb

My System SpecsSystem Spec
Old 10-17-2006   #7 (permalink)
Andrew Webb
Guest


 

RE: Scheduling powershell.exe

For the ultimate solution, see my new post: "PSScriptRunner - run a PS script
with no window flashing on screen".

Andrew Webb
My System SpecsSystem Spec
Old 10-20-2006   #8 (permalink)
BM
Guest


 

RE: Scheduling powershell.exe

Andrew...
I ll check your solution yet ... I think it should do it ...
BTW ..Is there any other way to do accomplish this ...
I ave developed a couple of cmdlets and it will be scheduled using NT
scheduler ..thanks





"Andrew Webb" wrote:

> For the ultimate solution, see my new post: "PSScriptRunner - run a PS script
> with no window flashing on screen".
>
> Andrew Webb

My System SpecsSystem Spec
Old 10-21-2006   #9 (permalink)
Andrew Webb
Guest


 

RE: Scheduling powershell.exe

> BTW ..Is there any other way to do accomplish this ...

In your scheduled task, you are launching an executable (PowerShell.exe) -
but as you've seen, this brings up a window that is on screen for as long as
the script takes to execute. And as you've also seen, no command-line switch
makes the window be hidden.

With my solution:-
http://www.databatcher.com/freestuff/PSScriptRunner.zip
you are also running an executable, but my exe a) creates no window for
itself and b) forks PowerShell such that its window is hidden. Very basic
stuff. Of course the command line arguments that you pass to my exe are
passed along to PowerShell.

So... is there another way to accomplish the same thing? Not that I've
found. And even if there is, I think my way is the simplest. If you're a
programmer you're free to take my technique and build it into a program of
your own making of course.

Andrew
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
window scheduling sam dk Vista General 0 04-25-2008 08:55 AM
scheduling script Ben Christian PowerShell 5 04-09-2008 12:12 PM
scheduling a powershell script oldtechie PowerShell 12 01-22-2008 07:40 PM
Scheduling Non Interactive powershell job =?Utf-8?B?Qk0=?= PowerShell 2 09-26-2006 06:54 PM
Scheduling running of PowerShell Scripts Andrew Watt [MVP] PowerShell 1 07-21-2006 05:01 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51