?
Solved

Command line path system variable edit

Posted on 2004-08-03
7
Medium Priority
?
2,409 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

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…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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