Page 1 of 1 1
Topic Options
#83409 - 2002-07-23 07:28 PM Add2Path() - add a directory to the path
davidrgeorge Offline
Lurker

Registered: 2002-01-08
Posts: 2
I used to use a reskit to do this but figured it would be faster to not have to make an external call.

function add2path($dir,$type)
; $dir: The directory you want to add to the path
; $type: '1' is local machine path, '0' is user path

if $type
$regpath="hkey_local_machine\system\currentcontrolset\control\session manager\environment"
else
$regpath="hkey_current_user\environment"
endif
$path=readvalue($regpath,"path")
if instr($path,$dir) = 0
if $path=""
$newpath=$dir
else
$newpath=$path+";"+$dir
endif
writevalue($regpath,"path",$newpath,"REG_EXPAND_SZ")
endif
endfunction

[ 28. October 2002, 19:46: Message edited by: Radimus ]

Top
#83410 - 2002-07-23 07:48 PM Re: Add2Path() - add a directory to the path
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Four remarks:

Firstly, HKEY_LKOCAL_MACHINE requires administrative privileges to write to under Windows NT/2000/XP.

Secondly, please post your UDF in between [CODE] tags and use the standard UDF formatting (see the other posted UDFs for examples).

Thirdly, suppress all return codes (see Why does the console display zeros and ones (amongst others)? )

Fourthly, you are not returning any kind of success or error code. Normally, one would expect a return code of '0' for a successful call to ADD2PATH, or the appropriate error code.

[ 23 July 2002, 19:49: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#83411 - 2005-07-09 12:38 AM Re: Add2Path() - add a directory to the path
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
think this should be trashed.
_________________________
!

download KiXnet

Top
#83412 - 2005-07-09 01:17 AM Re: Add2Path() - add a directory to the path
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It should at least be moved to Scripts.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#83413 - 2005-07-11 08:28 AM Re: Add2Path() - add a directory to the path
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
David,

in addition to what Jens (sealeopard) said, the internally used variables need all to be DIM'd to match the guidelines of posting to the udf libraries.
Please ammend the udf and let me know when done, I'll move this back to the library then ... oh wait, drop a note to the moderators of the Scripts forum better


Edited by Jochen (2005-07-11 08:29 AM)
_________________________



Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2375 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.052 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org