![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Invisible Windows Having developed an aversion to black boxes appearing on the screen over the years, what I think would be a really cool feature for this powershell would be the ability to run PowerShell scripts invisibly. Now, of course, I can wrap a .ps1 script in say something like a Windows Script Host script like say (VBScript)..... Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "MyPowerShellScript.ps1",0 and with the correct .ps1 file association set up it will run invisibly, but it would be nice to be able to do this with the need for any wrapper at all. ie something along the lines of powershell -Invisible <Path to script> I don't know if the powershell team follow this newsgroup, but that would be my powershell suggestion of the day, or perhaps the functionality's there already, and I've just missed it? -- Jon |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Invisible Windows Redirectting the stdout to Out-Null or $null maybe can accomplish what u want ![]() just like: powershell "& 'c:\......\test.ps1'" > $null powershell "& 'c:\......\test.ps1'" | Out-Null best wishes "Jon" <Email_Address@SomewhereOrOther.com> wrote: news:eUf3iXR3HHA.484@TK2MSFTNGP06.phx.gbl... > Having developed an aversion to black boxes appearing on the screen over the > years, what I think would be a really cool feature for this powershell would > be the ability to run PowerShell scripts invisibly. > > Now, of course, I can wrap a .ps1 script in say something like a Windows > Script Host script like say (VBScript)..... > > > Set WshShell = WScript.CreateObject("WScript.Shell") > WshShell.Run "MyPowerShellScript.ps1",0 > > > and with the correct .ps1 file association set up it will run invisibly, but > it would be nice to be able to do this with the need for any wrapper at all. > > ie something along the lines of > > powershell -Invisible <Path to script> > > I don't know if the powershell team follow this newsgroup, but that would be > my powershell suggestion of the day, or perhaps the functionality's there > already, and I've just missed it? > > -- > Jon > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Invisible Windows Hi. Thanks for the reply. Yep, similar to that solution, except that the 'black box' would never appear at any stage of the process ie if I ran a script such as this one (by double-clicking on a .ps1 file), then all that would be seen would be the MessageBox and no black box.... [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Windows.Forms.MessageBox]::Show("Hello") I suspect that I'll create a simple replacement .exe, whose sole purpose will be to launch the powershell.exe and the script invisibly, and associate ..ps1 files with that instead. So all is not lost :-) , but it would be simpler if it were just an extra switch in launching powershell.exe, in which case I could add it to the registry association for the .ps1 extension. -- Jon "Edengundam" <feng_eden@163.com> wrote in message news:%23AF%234vU3HHA.5360@TK2MSFTNGP03.phx.gbl... > Redirectting the stdout to Out-Null or $null maybe can accomplish what u > want ![]() > > just like: > powershell "& 'c:\......\test.ps1'" > $null > powershell "& 'c:\......\test.ps1'" | Out-Null > > best wishes > > "Jon" <Email_Address@SomewhereOrOther.com> wrote: > news:eUf3iXR3HHA.484@TK2MSFTNGP06.phx.gbl... >> Having developed an aversion to black boxes appearing on the screen over > the >> years, what I think would be a really cool feature for this powershell > would >> be the ability to run PowerShell scripts invisibly. >> >> Now, of course, I can wrap a .ps1 script in say something like a Windows >> Script Host script like say (VBScript)..... >> >> >> Set WshShell = WScript.CreateObject("WScript.Shell") >> WshShell.Run "MyPowerShellScript.ps1",0 >> >> >> and with the correct .ps1 file association set up it will run invisibly, > but >> it would be nice to be able to do this with the need for any wrapper at > all. >> >> ie something along the lines of >> >> powershell -Invisible <Path to script> >> >> I don't know if the powershell team follow this newsgroup, but that would > be >> my powershell suggestion of the day, or perhaps the functionality's there >> already, and I've just missed it? >> >> -- >> Jon >> >> > > |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Invisible Windows Hi, I'm monitoring this DL for a while and really wonder why you are the first in months to explicitly asking for that – I also miss this functionality. Since PS is a hostable scripting environment we basically would need a Windows-based host for PS, analogous to wscript.exe for VBScript. powershell.exe, as we get it today from MS, is a Console-based host, similar to cscript.exe for VBScript, so any attempt to get rid of the black box using some kind of hiding wrapper is just a clumsy workaround but not a clean and straightforward solution. Basically any talented and experienced C# programmer (unfortunately that’s not me) could do that for the PS community since the required interfaces are available and well documented, but maybe the demand is currently not expressed as clear as it should be. Gerd "Jon" wrote: > Having developed an aversion to black boxes appearing on the screen over the > years, what I think would be a really cool feature for this powershell would > be the ability to run PowerShell scripts invisibly. > > Now, of course, I can wrap a .ps1 script in say something like a Windows > Script Host script like say (VBScript)..... > > > Set WshShell = WScript.CreateObject("WScript.Shell") > WshShell.Run "MyPowerShellScript.ps1",0 > > > and with the correct .ps1 file association set up it will run invisibly, but > it would be nice to be able to do this with the need for any wrapper at all. > > ie something along the lines of > > powershell -Invisible <Path to script> > > I don't know if the powershell team follow this newsgroup, but that would be > my powershell suggestion of the day, or perhaps the functionality's there > already, and I've just missed it? > > -- > Jon > > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Invisible Windows Thanks for the reply Gerd. Agree with you completely. I'm currently using the 'permanent wrapper' style solution, in that I've re-associated .ps1 files with an executable that relaunches powershell.exe invisibly, with the arguments passed to it . I also use a toggle switch between the 2 ways of running (similar to toggling between the 2 hosts cscript.exe and wscript.exe). This works fine, although I had a few hiccups initially with forms not appearing, but with a few minor modifications to the code (using the 'Run' method of [System.Windows.Forms.Application] (there may be better ways)) I managed to resolve these. I'm not really up to writing a completely new substitute host for powershell either, which I'm sure would involve a lot of hard work and headaches, but hats off to anyone who does. It would be nicer imho if this functionality were implemented from the top down, in an analogous way to the WScript.exe / CScript.exe model, which would enable 'black boxless' powershell scripts to be distributed far more easily, and in turn I'm sure would also contribute to a massive explosion in the popularity of powershell. -- Jon "Gerd Schneider" <GerdSchneider@discussions.microsoft.com> wrote in message news:3C9B0596-D7C4-4205-BFBD-5BA2F33AC75C@microsoft.com... > Hi, > > I'm monitoring this DL for a while and really wonder why you are the first > in months to explicitly asking for that – I also miss this functionality. > > Since PS is a hostable scripting environment we basically would need a > Windows-based host for PS, analogous to wscript.exe for VBScript. > powershell.exe, as we get it today from MS, is a Console-based host, > similar > to cscript.exe for VBScript, so any attempt to get rid of the black box > using > some kind of hiding wrapper is just a clumsy workaround but not a clean > and > straightforward solution. > > Basically any talented and experienced C# programmer (unfortunately that’s > not me) could do that for the PS community since the required interfaces > are > available and well documented, but maybe the demand is currently not > expressed as clear as it should be. > > Gerd > > > "Jon" wrote: > >> Having developed an aversion to black boxes appearing on the screen over >> the >> years, what I think would be a really cool feature for this powershell >> would >> be the ability to run PowerShell scripts invisibly. >> >> Now, of course, I can wrap a .ps1 script in say something like a Windows >> Script Host script like say (VBScript)..... >> >> >> Set WshShell = WScript.CreateObject("WScript.Shell") >> WshShell.Run "MyPowerShellScript.ps1",0 >> >> >> and with the correct .ps1 file association set up it will run invisibly, >> but >> it would be nice to be able to do this with the need for any wrapper at >> all. >> >> ie something along the lines of >> >> powershell -Invisible <Path to script> >> >> I don't know if the powershell team follow this newsgroup, but that would >> be >> my powershell suggestion of the day, or perhaps the functionality's there >> already, and I've just missed it? >> >> -- >> Jon >> >> >> |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Invisible Windows We do monitor the newsgroup and yes, this is on the feature list for v2, probably as a -hide flag on PowerShell.exe. It might also be something that you can convince the PSCX folks to add to their package since they release more often we do. Keith? In the meantime, here is a script that will let you hide the console window. Do set-console -hidden to hide the console and set-console to make it visible again. Typical test sequence is: set-console -hidden ; start-sleep 5 ; set-console Extract the script from this message and save it as Set-Console.ps1 in your path. -bruce ----------------------------cut here-------------------- # # Sample script showing how to show and hide # console windows from PowerShell. It uses in-line # CSharp code to create a ConsoleHelper class to show # and hide the console. # param ([switch] $hidden) # # CSharp code for the ConsoleHelper class # $code = @' using System; using System.Runtime.InteropServices; public class ConsoleHelper { private const Int32 SW_HIDE = 0; private const Int32 SW_SHOW = 5; [DllImport("user32.dll")] private static extern Boolean ShowWindow( IntPtr hWnd, Int32 nCmdShow); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool AllocConsole(); [DllImport("Kernel32.dll")] private static extern IntPtr GetConsoleWindow(); public static void HideConsole() { IntPtr hwnd = GetConsoleWindow(); if (hwnd != IntPtr.Zero) { ShowWindow(hwnd, SW_HIDE); } } public static void ShowConsole() { IntPtr hwnd = GetConsoleWindow(); if (hwnd != IntPtr.Zero) { ShowWindow(hwnd, SW_SHOW); } } } '@ # # Only build the assembly if the type doesn't exist # # if this statement fails, then the trap handler will # compile the code [ConsoleHelper] > $null $ch = [ConsoleHelper] trap { # Get an instance of the CSharp code provider $cp = new-object Microsoft.CSharp.CSharpCodeProvider # And compiler parameters... $cpar = New-Object System.CodeDom.Compiler.CompilerParameters $cpar.GenerateInMemory = $true $cpar.GenerateExecutable = $false $cpar.OutputAssembly = "custom" $cr = $cp.CompileAssemblyFromSource($cpar, $code) # display any errors (there should be none...) if ( $cr.Errors.Count) { $codeLines = $code.Split("`n"); foreach ($ce in $cr.Errors) { write-host "Error: $($codeLines[$($ce.Line - 1)])" $ce | out-default } Throw "Compile failed..." } else { # don't report the exception continue } } # # Now use the helper to show and hide the window... # if ($hidden) { $ch::HideConsole() } else { $ch::ShowConsole() } ----------------------------cut here--------------------- -- Bruce Payette [MSFT] Windows PowerShell Technical Lead Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. "Jon" <Email_Address@SomewhereOrOther.com> wrote in message news:eUf3iXR3HHA.484@TK2MSFTNGP06.phx.gbl... > Having developed an aversion to black boxes appearing on the screen over > the years, what I think would be a really cool feature for this powershell > would be the ability to run PowerShell scripts invisibly. > > Now, of course, I can wrap a .ps1 script in say something like a Windows > Script Host script like say (VBScript)..... > > > Set WshShell = WScript.CreateObject("WScript.Shell") > WshShell.Run "MyPowerShellScript.ps1",0 > > > and with the correct .ps1 file association set up it will run invisibly, > but it would be nice to be able to do this with the need for any wrapper > at all. > > ie something along the lines of > > powershell -Invisible <Path to script> > > I don't know if the powershell team follow this newsgroup, but that would > be my powershell suggestion of the day, or perhaps the functionality's > there already, and I've just missed it? > > -- > Jon > > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Invisible Windows Thanks for the reply Bruce. Encouraging to know you guys read actually read this stuff ;-) Thanks also for the script. Works great. A number of interesting techniques in there to learn from - will be exploring that in detail. Also looking forward to version 2. That's great news Actually I'm excited about powershell which I may not have conveyed in my original post, and with a few minor modifications like this, even more so. It has a massive potential imho, and is quite likely to make technologies such as VBScript / CScript (which I know and love) to ultimately seem like childs' play by comparison. So keep up the good work! Cheers. -- Jon "Bruce Payette [MSFT]" <brucepay@microsoft.com> wrote in message news:uqlQhw23HHA.1212@TK2MSFTNGP05.phx.gbl... > We do monitor the newsgroup and yes, this is on the feature list for v2, > probably as a -hide flag on PowerShell.exe. It might also be something > that you can convince the PSCX folks to add to their package since they > release more often we do. Keith? > > In the meantime, here is a script that will let you hide the console > window. Do > set-console -hidden > to hide the console and > set-console > to make it visible again. Typical test sequence is: > > set-console -hidden ; start-sleep 5 ; set-console > > Extract the script from this message and save it as Set-Console.ps1 in > your path. > > -bruce > > ----------------------------cut here-------------------- > # > # Sample script showing how to show and hide > # console windows from PowerShell. It uses in-line > # CSharp code to create a ConsoleHelper class to show > # and hide the console. > # > > param ([switch] $hidden) > > # > # CSharp code for the ConsoleHelper class > # > $code = @' > using System; > using System.Runtime.InteropServices; > public class ConsoleHelper > { > private const Int32 SW_HIDE = 0; > private const Int32 SW_SHOW = 5; > > [DllImport("user32.dll")] > private static extern Boolean ShowWindow( > IntPtr hWnd, > Int32 nCmdShow); > [DllImport("kernel32.dll", SetLastError = true)] > public static extern bool AllocConsole(); > > [DllImport("Kernel32.dll")] > private static extern IntPtr GetConsoleWindow(); > > public static void HideConsole() > { > IntPtr hwnd = GetConsoleWindow(); > if (hwnd != IntPtr.Zero) > { > ShowWindow(hwnd, SW_HIDE); > } > } > > public static void ShowConsole() > { > IntPtr hwnd = GetConsoleWindow(); > if (hwnd != IntPtr.Zero) > { > ShowWindow(hwnd, SW_SHOW); > } > } > } > '@ > > # > # Only build the assembly if the type doesn't exist > # > # if this statement fails, then the trap handler will > # compile the code > [ConsoleHelper] > $null > $ch = [ConsoleHelper] > trap { > # Get an instance of the CSharp code provider > $cp = new-object Microsoft.CSharp.CSharpCodeProvider > # And compiler parameters... > $cpar = New-Object System.CodeDom.Compiler.CompilerParameters > $cpar.GenerateInMemory = $true > $cpar.GenerateExecutable = $false > $cpar.OutputAssembly = "custom" > $cr = $cp.CompileAssemblyFromSource($cpar, $code) > # display any errors (there should be none...) > if ( $cr.Errors.Count) > { > $codeLines = $code.Split("`n"); > foreach ($ce in $cr.Errors) > { > write-host "Error: $($codeLines[$($ce.Line - 1)])" > $ce | out-default > } > Throw "Compile failed..." > } > else > { > # don't report the exception > continue > } > } > > # > # Now use the helper to show and hide the window... > # > if ($hidden) > { > $ch::HideConsole() > } > else > { > $ch::ShowConsole() > } > ----------------------------cut here--------------------- > > -- > Bruce Payette [MSFT] > Windows PowerShell Technical Lead > Microsoft Corporation > This posting is provided "AS IS" with no warranties, and confers no > rights. > > "Jon" <Email_Address@SomewhereOrOther.com> wrote in message > news:eUf3iXR3HHA.484@TK2MSFTNGP06.phx.gbl... >> Having developed an aversion to black boxes appearing on the screen over >> the years, what I think would be a really cool feature for this >> powershell would be the ability to run PowerShell scripts invisibly. >> >> Now, of course, I can wrap a .ps1 script in say something like a Windows >> Script Host script like say (VBScript)..... >> >> >> Set WshShell = WScript.CreateObject("WScript.Shell") >> WshShell.Run "MyPowerShellScript.ps1",0 >> >> >> and with the correct .ps1 file association set up it will run invisibly, >> but it would be nice to be able to do this with the need for any wrapper >> at all. >> >> ie something along the lines of >> >> powershell -Invisible <Path to script> >> >> I don't know if the powershell team follow this newsgroup, but that would >> be my powershell suggestion of the day, or perhaps the functionality's >> there already, and I've just missed it? >> >> -- >> Jon >> >> > > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Invisible Windows "Bruce Payette [MSFT]" <brucepay@microsoft.com> wrote in message news:uqlQhw23HHA.1212@TK2MSFTNGP05.phx.gbl... > We do monitor the newsgroup and yes, this is on the feature list for v2, > probably as a -hide flag on PowerShell.exe. It might also be something > that you can convince the PSCX folks to add to their package since they > release more often we do. Keith? It's already there: :-) start-process powershell.exe -Arguments '-noprofile C:\users\hillr\foo.ps1' -NoWindow -NoShellExecute -- Keith http://www.codeplex.com/powershellcx |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Windows Media Center cursor invisible | Vista music pictures video | |||
| invisible ads | System Security | |||
| HDD invisible | Vista hardware & devices | |||
| Invisible Recycle Bin | Vista General | |||
| invisible files | Vista General | |||