Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:04:39+00:00 2026-05-28T03:04:39+00:00

Noob help please. I’m trying to write a script that will check if a

  • 0

Noob help please. I’m trying to write a script that will check if a process is running, and if not, start it. If the process is running, it should do nothing. I’ve come up with the following so far but it is starting a new instance of the process regardless of whether it was running already. Any help is appreciated.

$Prog = "C:\utilities\prog.exe"
$Running = Get-Process prog -ErrorAction SilentlyContinue
$Start = ([wmiclass]"win32_process").Create($Prog)
if($Running -eq $null)
{$Start}
else
{}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:04:39+00:00Added an answer on May 28, 2026 at 3:04 am

    First of all, here’s is what is wrong in your code.
    In your code, the process is created before you evaluate whether your program is already running

    $Prog = "C:\utilities\prog.exe"
    $Running = Get-Process prog -ErrorAction SilentlyContinue
    $Start = ([wmiclass]"win32_process").Create($Prog) # the process is created on this line
    if($Running -eq $null) # evaluating if the program is running
    {$Start}
    

    It is possible to create a block of code that should be evaluated further in your code by wrapping it in {} (a scriptblock):

    $Prog = "C:\utilities\prog.exe"
    $Running = Get-Process prog -ErrorAction SilentlyContinue
    $Start = {([wmiclass]"win32_process").Create($Prog)} 
    if($Running -eq $null) # evaluating if the program is running
    {& $Start} # the process is created on this line
    

    However, if you’re looking for a short one-liner to solve your problem:

    if (! (ps | ? {$_.path -eq $prog})) {& $prog}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm an absolute Silverlight noob that is confused by the help file. Here is
noob here still experimenting with templates. Trying to write a message processing class template
I am a delphi noob so please help me out with this. I have
Someone please help. I am a noob here who has just created an array
I am a real noob when it comes to javascript/ajax, so any help will
please help with this noob questions but really making me go crazy> if I
am a noob at universal apps so please help me out and let me
Little help for a javascript noob please... I have this in a .js file
I'm a database noob so please bear with me. I'm trying to join three
I'm a jQuery noob here, please help! Much much appreciated! my urls.py: url('^xhr_test/$','posts.views.xhr_test'), my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.