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 6127365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:29:54+00:00 2026-05-23T16:29:54+00:00

I am writing an batch file in Windows to run post-installation scripts, and one

  • 0

I am writing an batch file in Windows to run post-installation scripts, and one of the things that needs to be done is to add a directory to the system path.

The script is working, and it does something like this:

setx Path "%PATH%;c:\path\to\add" -m

This is setting the path correctly, but this script could potentially be run multiple times if the user reinstalls the program.

I would like to search the string for c:\path\to\add so I don’t keep adding the same path over and over to the system path. This is pretty trivial in Linux with sed, but I don’t know what the command is in Windows. I’ve found findstr, but this seems to only work on files.

Is this possible in Windows without installing additional software?

EDIT:

I’m using Inno Setup to create the install executable.

  • 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-23T16:29:55+00:00Added an answer on May 23, 2026 at 4:29 pm

    At the risk of some downvotes till an expert provides a sound way of doing this,

    the below removes the specific path from the environment variable if it exists, so that it can be added again:

    set str=%path%
    :: str is the same with path
    
    set str=%str:;C:\Path\To\Add=%
    :: ";c:\path\to\add" is now removed from str
    
    setx Path "%str%;c:\path\to\add" -m
    :: proceed with setting the path
    

    This carries the risk of removing the string if it is in fact actually a part of a path, for instance c:\path\to\add\somefolder. Also if the path actually ends with a \, or it is the first entry and it in fact does not start with ;, etc..

    Various forms can be called consecutively to circumvent some of these,

    set str=%str:;C:\Path\To\Add\;=;%
    set str=%str:;C:\Path\To\Add;=;%
    set str=%str:;C:\Path\To\Add\=%
    set str=%str:C:\Path\To\Add\;=%
    set str=%str:;C:\Path\To\Add=%
    

    But, AAMOF I’n not sure this is a sane way of doing this..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Windows batch files, but I'm writing a .bat file that just
Howdy, I'm writing a batch script that will run on a Windows XP machine.
I'm writing a batch file on Windows which gets one argument: a zip file
I am writing a batch file to run on Windows server 2008 R2, it
I am writing a batch file script using Windows command and want to change
I'm writing a Windows batch file and want to copy something to the desktop.
When writing a batch file to automate something on a Windows box, I've needed
I have a variable define as: set filePath=.\file.txt I'm writing a windows batch file.
When I'm writing a batch file to run automatically, how do I write it
I'm writing a windows service that import an XML file into a SQLite database.

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.