Windows service path variable

Windows CMD: PATH Variable – Add To PATH – Echo PATH

PATH is an environment variable that specifies a set of directories, separated with semicolons ( ; ), where executable programs are located.

In this note i am showing how to print the contents of Windows PATH environment variable from the Windows command prompt.

I am also showing how to add a directory to Windows PATH permanently or for the current session only.

Cool Tip: List environment variables in Windows! Read More →

Echo Windows PATH Variable

Print the contents of the Windows PATH variable from cmd :

The above commands return all directories in Windows PATH environment variable on a single line separated with semicolons ( ; ) that is not very readable.

To print each entry of Windows PATH variable on a new line, execute:

Cool Tip: Set environment variables in Windows! Read More →

Add To Windows PATH

Warning! This solution may be destructive as Windows truncates PATH to 1024 characters. Make a backup of PATH before any modifications.

Save the contents of the Windows PATH environment variable to C:\path-backup.txt file:

Set Windows PATH For The Current Session

Set Windows PATH variable for the current session:

Set Windows PATH Permanently

Run as Administrator: The setx command is only available starting from Windows 7 and requires elevated command prompt.

Permanently add a directory to the user PATH variable:

Permanently add a directory to the system PATH variable (for all users):

Info: To see the changes after running setx – open a new command prompt.

How to set the path and environment variables in Windows

Setting the path and environment variables will differ depending on the version of Windows you have on your computer. Choose a link below for your version of Windows.

Administrator privileges are usually required to modify the path and environment variables.

Setting the path and variables in Windows 10

  1. From the desktop, right-click the very bottom-left corner of the screen to get the Power User Task Menu.
  2. From the Power User Task Menu, click System.
  3. In the Settings window, scroll down to the Related settings section and click the System info link.
  4. In the System window, click the Advanced system settings link in the left navigation pane.
  5. In the System Properties window, click the Advanced tab, then click the Environment Variablesbutton near the bottom of that tab.
  6. In the Environment Variables window (pictured below), highlight the Path variable in the System variables section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon, as shown below.
Читайте также:  Internet explorer 11 для windows 10 открыть

You can edit other environment variables by highlighting the variable in the System variables section and clicking Edit. If you need to create a new environment variable, click New and enter the variable name and variable value.

To view and set the path in the Windows command line, use the path command.

Setting the path and variables in Windows 8

  1. From the desktop, right-click the very bottom-left corner of the screen to get the Power User Task Menu.
  2. From the Power User Task Menu, click System.
  3. Click the Advanced System Settings link in the left column.
  4. In the System Properties window, click the Advanced tab, then click the Environment Variablesbutton near the bottom of that tab.
  5. In the Environment Variables window (pictured below), highlight the Path variable in the System variables section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon, as shown below.

You can edit other environment variables by highlighting the variable in the System variables section and clicking Edit. If you need to create a new environment variable, click New and enter the variable name and variable value.

To view and set the path in the Windows command line, use the path command.

Setting the path and variables in Windows Vista and Windows 7

  1. From the desktop, right-click the Computer icon and select Properties. If you don’t have a Computer icon on your desktop, click Start, right-click the Computer option in the Start menu, and select Properties.
  2. Click the Advanced System Settings link in the left column.
  3. In the System Properties window, click the Advanced tab, then click the Environment Variablesbutton near the bottom of that tab.
  4. In the Environment Variables window (pictured below), highlight the Path variable in the System variables section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon, as shown below.

You can edit other environment variables by highlighting the variable in the System variables section and clicking Edit. If you need to create a new environment variable, click New and enter the Variable name and Variable value.

To view and set the path in the Windows command line, use the path command.

Setting the path and variables in Windows 2000 and Windows XP

The path is now managed by Windows 2000 and Windows XP and not the autoexec.bat or autoexec.nt files, as was done with earlier versions of Windows. To change the system environment variables, follow the steps below.

  1. From the desktop, right-click My Computer and click Properties. If you don’t have a My Computer icon on your desktop, click Start, right-click the My Computer option in the Start menu, and select Properties.
  2. In the System Propertieswindow, click the Advancedtab.
  3. In the Advanced section, click the Environment Variablesbutton.
  4. In the Environment Variables window (as shown below), highlight the Path variable in the System Variable section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon, as shown below.
Читайте также:  Предупреждение системы безопасности windows activex

You can edit other environment variables by highlighting the variable in the System variables section and clicking Edit. If you need to create a new environment variable, click New and enter the Variable name and Variable value.

To view and set the path in the Windows command line, use the path command.

What is the default Windows %PATH%?

The path is based on programs installed on the computer, so there is no «default path.» However, the Windows minimum path is often the path below.

Keep in mind that as you install programs, the path is updated with the paths for the newly installed programs. So, if you have erased your path after installing other programs, those programs may be affected.

Setting path in the MS-DOS and Windows command line

To view and set the path in MS-DOS and in the Windows command line, use the path command.

How to manage PATH variable in Windows?

Every time I experiment with a new language, compiler, interpreter, tool, or whatever, and I want to run that from the command line, I would have to go to System and change my PATH variable. However, the box to put the monster string in consists of only a 1-line text box. I frequently find myself having to copy/paste the PATH string into Notepad just to edit it — It’s already over half a page. Right now I’ve counted about 30 different path URL’s.

Is there a better way to manage paths than to squeeze all of them into one string? I’m thinking of using SUSE for development since my PATH is so messed up.

6 Answers 6

If you always start the command line from one or a few shortcuts, you can run a batch file when it starts. For example:

where the batch file could have

or anything else, and this would persist only for that cmd.exe instance.

XP’s Service Pack 2 Support tools (looks like there’s one for SP3, but it doesn’t say what’s in it) comes with a program setx.exe that works like a permanent set .

There is a really nice freeware environment editor available called RapidEE

Rapid Environment Editor

Rapid Environment Editor (RapidEE) is an environment variables editor.

It includes an easy to use GUI and replaces the small and inconvenient Windows edit box.

RapidEE 8.x supports Windows XP, 2003, Vista, 2008, Windows 7, Windows 8 & Windows 10 (including 64-bit versions).

If you still use Windows NT or 2000, then use version 6.1. For Windows 9x or ME use version 2.1.

  • Editable tree: Show environment variables and values as an editable tree.
  • Portable mode: RapidEE doesn’t require installation and could be run as a «portable application».
  • Error checking: Automatically checking for invalid pathnames and filenames
  • Multilanguage interface: RapidEE is translated into a number of languages (English, Russian, Japanese, French, Polish, German, Italian, Latvian, Slovak, Greek, Spanish, Chinese, Dutch, Swedish, Korean, Croatian, Danish, Brazilian Portuguese, Finnish, Norwegian, Indonesian, Romanian, Hungarian, Turkish, Abkhazian, Ukrainian, Czech, Arabic), and the language can be changed on the fly.

Accessing Environment Variables from Windows Services

I am attempting to write a Windows Service in C#. I need to find the path to a certain file, which is stored in an environment variable. In a regular C# console application, I can achieve that with the following line:

If I write that to the console I see that it was successful.

Читайте также:  Все комбинации горячих клавиш windows 10

Now, if I try that same code in a Windows Service, the string t is empty.

10 Answers 10

I’ve no idea if this is useful, but I’ve found that for every service, there is an option to add environment variables directly to a service.

It is done via the registry.

Say the key to your service is .

Create a REG_MULTI_SZ called Environment.

Now you can add entries like .

and these will be available to the service code.

If you are using the Windows Resource ToolKit to install scripts as a service (instsrv.exe and srvany.exe), then, again, you have the option of setting Environment variables for the service, but most likely it is the wrong one as these would be for srvany.exe.

Instead, you use the key .

and create a REG_MULTI_SZ called AppEnvironment

Set the entries in the same way.

And now your script service has it’s own environment variables.

I’m using these techniques with PHP+WinCache to allow me to set an APP_POOL_ID unique to each service which allows WinCache to share a central cache (based upon APP_POOL_ID) for all «threads» (using WShell to launch non-blocking child «threads» and still share the same WinCache as the launcher, allowing simplistic, inter-process communication).

Anyway. I hope this helps somewhat.

I think, in the main, you aren’t adding unnecessary env_vars to the global environment. You can keep them targetted and unique when you have more than 1.

Modifying the “Path to executable” of a windows service

I’d like to modify the path to my application, but doing so breaks it because the service still points to the old location.

By going to Administrative Tools > Services you can open a properties dialog and view the Path to executable , but there is no way to change it.

Is there any way a user can modify the service path without having to reinstall the application ?

8 Answers 8

There is also this approach seen on SuperUser which uses the sc command line instead of modifying the registry:

Note: the space after binPath= is important. You can also query the current configuration using:

This displays output similar to:

It involves editing the registry, but service information can be found in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services . Find the service you want to redirect, locate the ImagePath subkey and change that value.

You could also do it with PowerShell:

Open Run(win+R) , type «Regedit.exe» , to open «Registry Editor», go to

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services

find «Apache2.4» open the folder find the «ImagePath» in the right side, open «ImagePath» under «value Data» put the following path:

«C:\xampp\apache\bin\httpd.exe» -k runservice foe XAMPP for others point to the location where Apache is installed and inside locate the bin folder «C:(Apache installed location)\bin\httpd.exe» -k runservice

Slight modification to this @CodeMaker ‘s answer, for anyone like me who is trying to modify a MongoDB service to use authentication.

When I looked at the «Path to executable» in «Services» the executed line already contained speech marks. So I had to make minor modification to his example.

  1. Type Services in Windows
  2. Find MongoDB (or the service you want to change) and open the service, making sure to stop it.
  3. Make a note of the Service Name (not the display name)
  4. Look up and copy the «Path to executable» and copy it.

For me the path was (note the speech marks)

Оцените статью