Possible to run a Powershell script with no taskbar window?

  • Thread starter James R. Gentile
  • Start date
J

James R. Gentile

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 Computer

C

cerna.zelva

On 4 Lis, 01:52, "James R. Gentile" <[email protected]> wrote:

> 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=run-scheduled-tasks-with-winform-gui-in-powershell
 

My Computer

R

RickB

On Nov 3, 6:52 pm, "James R. Gentile" <[email protected]> wrote:

> 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 Computer

BatchMan

New Member
Test this.

Require : http://www.leeholmes.com/blog/GetTheOwnerOfAProcessInPowerShellPInvokeAndRefOutParameters.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 
 # [URL="http://powershell-scripting.com/index.php?option=com_content&task=view&id=217&Itemid=80"]PowerShell-Scripting.com - PowerShell Form Converter V0.9[/URL]
...
$Form1.Add_Shown({Hide-PowerShell;$Form1.Activate()})
$Form1.ShowDialog()
 
$Form1.Dispose()
Show-PowerShell;
 

My Computer

Top