- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to start any program using PowerShell?
If you have noticed, you can start notepad and calculator or other standard system utilities with the Windows Run or through the PowerShell console directly by typing just their names, but not the wordpad.exe, word, excel or any other application. It will throw an exception.
For example, just type notepad.exe in PowerShell console and it will open the program but type wordpad.exe there will be an error.
wordpad.exe − The term 'wordpad.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1 + wordpad.exe + ~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (wordpad.exe:String) , CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
This is because all the programs run through the command whose paths have stored into an environmental variable.
To check the environmental path variables, use the below command.
$env:Path -split ';'
C:\Program Files (x86)\Intel\iCLS Client\ C:\Program Files\Intel\iCLS Client\ C:\WINDOWS\system32 C:\WINDOWS C:\WINDOWS\System32\Wbem C:\WINDOWS\System32\WindowsPowerShell\v1.0\ C:\Program Files\Intel\Intel(R) Management Engine Components\DAL C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL C:\Program Files\Intel\Intel(R) Management Engine Components\IPT C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT C:\Program Files (x86)\Skype\Phone\ C:\Program Files\Intel\WiFi\bin\ C:\Program Files\Common Files\Intel\WirelessCommon\
Programs located under the above path will run directly through the PowerShell console without providing the full path of the application or utility.
Now, to open the Wordpad you need to give the full path of the Wordpad. But when you give full path in the double or single quotation it will consider it as a string and returns the same value without executing the program.
"C:\Program Files\Windows NT\Accessories\wordpad.exe"
To execute the program, you need to use the ampersand (&) sign followed by the full path of the program.
& 'C:\Program Files\Windows NT\Accessories\wordpad.exe'
Another way to execute the program is to browse to that directory and run the program.
cd 'C:\Program Files\Windows NT\Accessories\'
and run the program name.
PS C:\Program Files\Windows NT\Accessories> .\wordpad.exe
So far, we have executed the program with the full pathname. Now we want to execute wordpad.exe, directly from the PowerShell console. To do so, we need to provide the program path to the environmental variable.
$env:Path += ";C:\Program Files\Windows NT\Accessories\"
Now you just need to type wordpad.exe from the PowerShell console and the program will open.
Please Note − Change in the environment variable is temporary. Once you close the PowerShell console, the newly added environment variable path will be removed. To add this path permanently you need to use the profile script path and it loads every time when PowerShell console starts.
- How to start a windows service using PowerShell?
- How to start multiple windows services using PowerShell?
- How to start dependent services in PowerShell?
- How to start the Azure VM using Azure CLI in PowerShell?
- How to start the specific task of the task scheduler using PowerShell?
- How to get the certificate's start and expiry date using PowerShell?
- How to get services based on start-type in PowerShell?
- How to start windows service with display name in PowerShell?
- How to traceroute using PowerShell?
- How to open any file with its default application with PowerShell?
- How to create a dummy file of any size with PowerShell?
- How to format string using PowerShell?
- How to send email using PowerShell?
- How to connect to SSH using PowerShell?
- How to start service using Alarm Manager in android?