How can I run a command window hidden or minimised?

610

Solution 1

This should be what you need:

$Process = new-Object System.Diagnostics.Process
$Process.StartInfo.UserName="Administrator"
$Process.StartInfo.Password=$Credential.Password
$Process.StartInfo.Domain="$Computer"
$Process.StartInfo.WindowStyle="Hidden"
$Process.StartInfo.FileName="cmd.exe"
$Process.StartInfo.Arguments="$localArgs"
$Process.Start()

Solution 2

You can use the Start-Process cmdlet (PowerShell 2.0):

Start-Process cmd.exe -Credential $credential -WindowStyle Hidden -WorkingDirectory ... -ArgumentList...

Solution 3

You can't use -Credential and -WindowStyle parameters together with PowerShell v2, you either need PowerShell v3 or use -NoNewWindow and -Credential parameters together

You can use the below code for PowerShell v2:

$user = "{user}"
$pass = ConvertTo-SecureString -String "{password}" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential `
     -argumentlist $user, $pass

start-process -Credential $cred -NoNewWindow powershell "-command & '{path and script}'"
Share:
610

Related videos on Youtube

martin
Author by

martin

Updated on September 17, 2022

Comments

  • martin
    martin over 1 year

    I'm developing a puzzle game that's going to be based on my own game engine. My intention is to make the game engine open-source (including some demos) while the game itself (levels, textures, level editor, ...) to be paid.
    What's worrying me is what type of license for the game engine should I use?

    I think this is similar to original DOOM source code re-release in 1999 under GPL licence. You can do whatever you want with it but if you want to play the original game you need the DOOM.WAD file which you can legaly obtain only by buying the original game.

    So, can I use GPL? I think it means that all software build on top of it has to stay GPL. But maybe in my case it doesn't matter because I'm not going to make changes to the engine that wouldn't be also in the standalone game engine.

    • Kumaran Sivasubramaniam
      Kumaran Sivasubramaniam almost 14 years
      Do you want the PowerShell script or the cmd.exe prompt to be hidden?
    • Joey
      Joey almost 14 years
      Why do you even run a PowerShell script by calling cmd which then starts PowerShell? That sounds like at least two levels of indirection too much.
    • Ben
      Ben almost 14 years
      @Mark - I want the command window to be hidden
    • Ben
      Ben almost 14 years
      @Johannes - That was the only way I could successfully pass Admin credentials to it, by running the above "wrapper" script
    • Joey
      Joey almost 14 years
      Taken a look at Start-Process?
    • Kevin Brown-Silva
      Kevin Brown-Silva almost 9 years
      I'm voting to close this question as off-topic because it is about licensing or legal issues, not programming or software development. See here for details, and the help center for more.
  • Ben
    Ben almost 14 years
    Think this is 90% there, but am getting " Parameter set cannot be resolved using the specified named parameters" when I add the -Credential argument.
  • martin
    martin about 11 years
    The first one makes sence to me. I want to give the game engine for free but I'm a bit afraid that someone will just take it and try to sell as it is. So maybe I can use GPL and clearly state that I give everyone permission to use parts of it in their own proprietary games but still restrict using the engine as whole only under GPL.
  • beatgammit
    beatgammit about 11 years
    This is probably what you're already thinking, but why not release part under LGPL (the part others can use in a proprietary game) and the rest GPL, assuming that the parts under LGPL are used as a library by you. Otherwise, you could consider using the MPL if the parts you want others to use are in individual files. Then others can use just those files, not the library as a whole, as is in a proprietary game.
  • martin
    martin about 11 years
    Licensing libraries under LGPL and the core "game" that connects everything together under GPL is a good idea. That's probably the way I want to go but I'll have a look on MPL as well. Thanks @tjameson!