Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 help and support Forum Windows 8 Forum Vista Tutorials

Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroup Archive > Misc Newsgroups > PowerShell

Vista - Possible to run a Powershell script with no taskbar window?


 
 
11-03-2008   #1 (permalink)
James R. Gentile


 

Possible to run a Powershell script with no taskbar window?

I have a script that needs to run 24/7, but I'd rather not have the
additional taskbar button, it gets in the way, so how can I run without it?
It's for personal use, so it'd be fine if I had to open task manager to kill
the script... Also is it possible to have a script check if it is already
running? It has a unique title, so maybe it can scan all program title's
somehow? I know these are advanced topics, so thanks for any help.



My System SpecsSystem Spec
11-04-2008   #2 (permalink)
cerna.zelva


 

Re: Possible to run a Powershell script with no taskbar window?

On 4 Lis, 01:52, "James R. Gentile" <n...@xxxxxx> wrote:
Quote:

> I have a script that needs to run 24/7, but I'd rather not have the
> additional taskbar button, it gets in the way, so how can I run without it?
> It's for personal use, so it'd be fine if I had to open task manager to kill
> the script... Also is it possible to have a script check if it is already
> running? *It has a unique title, so maybe it can scan all program title's
> somehow? I know these are advanced topics, so thanks for any help.
I had a similar question to hidden window some time ago. I needed to
show a winform gui, but with main PowerShell window invisible. The
only solution for me was to go and create an executable for that
purpose. More at http://www.leporelo.eu/blog.aspx?id=...-in-powershell
My System SpecsSystem Spec
11-04-2008   #3 (permalink)
RickB


 

Re: Possible to run a Powershell script with no taskbar window?

On Nov 3, 6:52*pm, "James R. Gentile" <n...@xxxxxx> wrote:
Quote:

> I have a script that needs to run 24/7, but I'd rather not have the
> additional taskbar button, it gets in the way, so how can I run without it?
> It's for personal use, so it'd be fine if I had to open task manager to kill
> the script... Also is it possible to have a script check if it is already
> running? *It has a unique title, so maybe it can scan all program title's
> somehow? I know these are advanced topics, so thanks for any help.
If you schedule the powershell job and run it under the system ID it
will be totally invisible. Unfortunately, because it is invisible, it
has no window title. So there is no good way to tell if it is running
besides perhaps to ask the scheduler. I.E.

PS 1> schtasks
TaskName Next Run Time Status
==================================== ========================
===============
File Watcher At system start up Running
PFW_Monitor 7:00:00 AM, 11/4/2008
PS 2>
My System SpecsSystem Spec
11-09-2008   #4 (permalink)


 
 

Re: Possible to run a Powershell script with no taskbar window?

Test this.

Require : http://www.leeholmes.com/blog/GetThe...Parameters.asp
Code:
function ShowWindowAsync([IntPtr] $hWnd, [Int32] $nCmdShow)
{
    $parameterTypes = [IntPtr], [Int32] 
    $parameters = $hWnd, $nCmdShow
    Invoke-Win32 "user32.dll" ([Boolean]) "ShowWindowAsync" $parameterTypes $parameters
}
function Show-PowerShell() { 
     $null = ShowWindowAsync $myWindowHandle 1 
}
function Hide-PowerShell() { 
    $null = ShowWindowAsync $myWindowHandle  0  
}
function Minimize-PowerShell() { 
    $null = ShowWindowAsync $myWindowHandle  2  
}
# Values for $nCmdShow
#   SW_HIDE = 0;
#   SW_SHOWNORMAL = 1;
#   SW_NORMAL = 1;
#   SW_SHOWMINIMIZED = 2;
#   SW_SHOWMAXIMIZED = 3;
#   SW_MAXIMIZE = 3;
#   SW_SHOWNOACTIVATE = 4;
#   SW_SHOW = 5;
#   SW_MINIMIZE = 6;
#   SW_SHOWMINNOACTIVE = 7;
#   SW_SHOWNA = 8;
#   SW_RESTORE = 9;
#   SW_SHOWDEFAULT = 10;
#   SW_MAX = 10
Console :
Code:
 
  #must be saved before the call
$myWindowHandle = (Get-Process -Id $pid).MainWindowHandle 
start-transcript
Hide-PowerShell 
# (Get-Process -Id $pid).MainWindowHandle -eq 0
sleep 2 
 
Show-PowerShell;
Winform :
Code:
 
$myWindowHandle = (Get-Process -Id $pid).MainWindowHandle 
 # PowerShell-Scripting.com - PowerShell Form Converter V0.9
...
$Form1.Add_Shown({Hide-PowerShell;$Form1.Activate()})
$Form1.ShowDialog()
 
$Form1.Dispose()
Show-PowerShell;
My System SpecsSystem Spec
 

Possible to run a Powershell script with no taskbar window? problems?



Thread Tools


Similar topics to: Possible to run a Powershell script with no taskbar window?
Thread Forum
Re: Don't show powershell in taskbar PowerShell
RE: Don't show powershell in taskbar PowerShell
Converting a BAT script into a PowerShell Script PowerShell
when run powershell script as windows service ,powershell fail PowerShell
Script pauses when you click in the powershell text window PowerShell


Vista Forums 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 Ltd

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