Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Command line path system variable edit

Posted on 2004-08-03
7
Medium Priority
?
2,412 Views
Last Modified: 2010-04-13
Hi,

I am building an SMS installer package and as part of the install I need to edit the "Path" system variable so that 2 entries are removed and the rest of the "Path"  system variable to remains in place.  I know that the "Path" system variable exists in the registry at \local_machine\software\......\environment\path but cannot think of a way of using a script to edit the key instead of deleting it or recreating it .

Does anyone know how this can achieved using SMS installer or a third party tool that I could plug into the SMS installer script?

Thanks, Steve
0
Comment
Question by:Steve_L1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 11712260
If you have access to Windows 2000's resource kit, there's a registry editing command-line tool there (reg.exe, I believe it's called)
Read here: http://www.robvanderwoude.com/index.html
0
 
LVL 3

Expert Comment

by:saito1
ID: 11713074
0
 
LVL 85

Accepted Solution

by:
oBdA earned 375 total points
ID: 11713342
You can use setx.exe from the W2k Resource Kit (http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/setx-o.asp) to set the Path variable permanently. Then you can try this script, which will let you add or remove parts of the path. Note that the script is currently in test mode, it will only display the setx command it would otherwise issue, so that you can verify if the new path is built correctly. This will only run on W2k or later.
As usual: No warranties included, use it at your own risk, test it before you apply it in earnest.

====8<----[ChangePath.cmd]----
@echo off
setlocal enabledelayedexpansion
:: *** List of folders to be added:
set AddPath="C:\TestAdd1" "D:\TestAdd2"
:: *** List of folders to be removed:
set RemPath="C:\Service\Tools" "C:\Perl\Bin\"

set WorkPath="%Path:;=" "%"
set NewPath=
for %%a in (%WorkPath%) do call :process %%a
for %%a in (%AddPath%) do set NewPath=!NewPath!%%~a;
:: *** Test mode: Remove the ECHO in front of the following line to "arm" the script
ECHO setx.exe PATHTEST "%NewPath%" -m
goto leave

:process
set Remove=FALSE
for %%a in (%RemPath%) do if /i %1==%%a set Remove=TRUE
if /i %Remove%==TRUE goto :eof
set NewPath=%NewPath%%~1;
goto :eof

:leave
====8<----[ChangePath.cmd]----
0
[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

 
LVL 6

Expert Comment

by:Scott_Willcocks
ID: 11713543
the problem with SMS is that when running the setup on a clients machine it runs the setup under the clients security context

BSMith logs in and SMS sees that he needs this software it pushes it out him it runs on his machine as if BSMith is loading the software.

if BSMith is on a WIN9x client windows 95 98 etc no problem if the SMS installation has A add path to directory set go into the SMS ipf with the SMS installer software and goto view>script editor. and check for add to path is in the script if not goto left panel and select add directory to path and set the path you can use sms variables. when you run this on the WIN9x client all good.

If BSMith is on a WINNT client w2K WXp you will have a problem as a standard use does not have the correct permisions to write to the system path.

This is why Installshield is taking over if you create an msi and active directory assign the package when you deploy the package runs under the windows installer service which can elevate the rights of the package.
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11714489
Don't know of a way to "edit" the key, but you could definitely use the Reg utility that sirbounty mentioned.

I use it for several things usually, to query if certain keys are there and then run an if statement.

For instance, Reg query HLKM\Software\ORL\WinVNC3\%version%

Queries for what version of VNC they have when I set the version variable.

I then do a Reg delete to delete old entries if it is an outdated version: Reg delete \\%1\%CLE% (%1 being the target computer and %CLE% being a defined path in the registry.)

Then a Reg copy to copy the current settings from an existing computer with the correct registry settings: Reg copy %serv%\%CLE% \\%1\%CLE% /s /f

Works like a champ for me :)
0
 
LVL 6

Expert Comment

by:Scott_Willcocks
ID: 11714521
if you are using SMS installer edit the ipf add the add directory to path.

Just tested it on windows 2K and it works SMS falls over trying to add services not system paths my bad haven't used sms installer for about a year now.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 11714548
Another method, if the right permissions are in place, and the path should be the same for all users, is to export your key to a path.reg file.
Then simply run
 regedit /s path.reg
from a comman line to silently import it...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This week I attended a Startup Week Chattanooga talk on Gender Diversity in Technology. Check out what I learned.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question