#47941 - 1999-07-09 03:46 AM
How to strip a string....
|
Anonymous
Anonymous
Unregistered
|
I want to make a new variable in windows. The variable is the path to the All Users Profile. %allusersprofile% Since this path dont exist anywhere in the registry, i use the 'common desktop' key and strip i the '\desktop'. I could not find a way in kix to do this the easy way, so here is the result:$x = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Common Desktop") $d = "Desktop" if instr("$x", "$d") $sl = len("$d") + 1 endif $d = "Skrivebord" if instr("$x", "$d") $sl = len("$d") + 1 endif $kl = len("$x") $y = $kl - $sl $AllUsersProfile = substr("$x", 1, $y) setm "AllUsersProfile=$AllUsersProfile" Any comments, suggestions, questions? ------------------ Magne
|
|
Top
|
|
|
|
#47942 - 1999-07-12 10:34 AM
Re: How to strip a string....
|
Anonymous
Anonymous
Unregistered
|
Do it Simple:$AllUsersProfile="%systemroot%\Profiles\All Users" Cause Nt has a %systemroot% variable and the Profile is Always located in the SystemRoot, this is the Most simple Sollution to this problem !! (KISS = Keep It Simple Silly) ------------------ Lon Geefshuysen, www.xs4all.nl/~longeef/NT/KiXtart lon_geefshuysen@essentium.com
|
|
Top
|
|
|
|
#47943 - 1999-07-19 01:20 PM
Re: How to strip a string....
|
Anonymous
Anonymous
Unregistered
|
'%SystemRoot%\Profiles\All Users' is only valid in NT 4.0. It will not work for Windows 2000 or NT 3.51.
|
|
Top
|
|
|
|
#47944 - 1999-07-20 04:48 AM
Re: How to strip a string....
|
Anonymous
Anonymous
Unregistered
|
In W2K there already is a ALLUSERSPROFILE system variable. For W2K you can check if this Variable exists and then use that one: example if %allusersprofile% ? "Windows 2000" Else $AllUsersProfile="%systemroot%\Profiles\All Users" EndIfFor NT 3.5X, you need to find the Location where it store's this directory ! (I can't search for it, cause I haven't got any NT 3.5X systems running anymore) ------------------ Lon Geefshuysen, www.xs4all.nl/~longeef/NT/KiXtart lon_geefshuysen@essentium.com
|
|
Top
|
|
|
|
#47945 - 1999-07-20 07:09 AM
Re: How to strip a string....
|
Anonymous
Anonymous
Unregistered
|
Correction on the script:if %allusersprofile% ? "Windows 2000" $AllUsersProfile=%allusersprofile% Else $AllUsersProfile="%systemroot%\Profiles\All Users" EndIf
|
|
Top
|
|
|
|
#47946 - 1999-07-20 09:52 AM
Re: How to strip a string....
|
Anonymous
Anonymous
Unregistered
|
I think the real problem got 'lost' here somewhere. The real problem is not to make the %allusersprofile%, but to 'extract' a part of a string. e.g I have this string: 'this is a string' and want to extract only: 'is a'. How is this done the most easy way?------------------ Magne
|
|
Top
|
|
|
|
#47947 - 1999-07-23 07:11 AM
Re: How to strip a string....
|
Anonymous
Anonymous
Unregistered
|
Well to strip a string like 'this is a string', is not very dificult, but what I need to know before I can write an example is what is known about the string. ie: is the wanted part always on the same place?, is the string always the same structure?..if from a string like "C:\WINNT\Profiles\All Users\Desktop" you need only the first part you can use this code to strip out the '\Desktop' example code $x = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Common Desktop") $d = "\Desktop" $lx = LEN($x) $ld = LEN($d) $allusersprofile = SUBSTR($x,1,$lx-$ld) ------------------ Lon Geefshuysen, www.xs4all.nl/~longeef/NT/KiXtart lon_geefshuysen@essentium.com
|
|
Top
|
|
|
|
#47948 - 1999-07-23 08:48 PM
Re: How to strip a string....
|
Anonymous
Anonymous
Unregistered
|
The example you show here is very alike the script i first posted here. But what it really does is not to extract the string '\desktop', but to remove the last 8 caracters from variable $x. This will not work if the length of the string to extract is unknown. But, then again, what help would it be to extract a pre defined string if it is unknown? im tired....
------------------ Magne
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2312 anonymous users online.
|
|
|