Page 1 of 1 1
Topic Options
#8871 - 2001-05-23 11:10 AM Simple Script
Anonymous
Unregistered


Hello,
I am just starting to use Kix32 today.
How can i write a script where i first check if a environment variable exists
and then, if it does then to create a registry key.
If the environment variable does not exist then i have to create it first and then write the reg key.

------------------
omen9@hotmail.com

Top
#8872 - 2001-05-24 01:30 AM Re: Simple Script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Hello omen9,

Here is a sample for you to look at.

code:

$MYVAR = "MYAPP"
IF $MYVAR = "%WINDIR%"
ELSE
SET "$MYVAR=%WINDIR%"
ENDIF

IF @INWIN = 1
$NOTICE1 = ReadValue ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "LegalNoticeText")
$NOTICE2 = ReadValue ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "LegalNoticeCaption")
IF $NOTICE1 = "My Company message"
ELSE WriteValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "LegalNoticeText", "My Company message","REG_SZ")
ENDIF
IF $NOTICE2 = "Notice: CompanyŠ"
ELSE WriteValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "LegalNoticeCaption", "Notice: CompanyŠ","REG_SZ")
ENDIF
ELSE
IF EXIST("%windir%\warn.exe")
ELSE COPY "V:\warn.exe" %WINDIR%
ENDIF
$RUNWARN = ReadValue ("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", "WARN")
IF $RUNWARN = "%WINDIR%\WARN.EXE"
ELSE WriteValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", "WARN", "%WINDIR%\WARN.EXE","REG_SZ")
ENDIF
ENDIF



SET
Action
Sets environment variables in the environment of the current user (HKEY_CURRENT_USER\Environment).

Syntax
SET "variable=string"

Remarks
After any change to the environment, KiXtart informs running programs that the change was made,
prompting them to regenerate their environments. Programs that support this feature
(such as Program Manager, Task Manager, and Windows Explorer) update their environments when
they receive the WM_SETTINGCHANGE message.

The environment of the current process (KiXtart 95) is not affected.
This command does not work on Windows 9x. As an alternative, use the SHELL command to
run Winset.exe. (Winset.exe is included on the Windows 9x CD.)


------------------
NTDOC...
The dark side is quicker, easier, more seductive.
If you choose the quick and easy path, you will become an agent of evil.

[This message has been edited by NTDOC (edited 24 May 2001).]

Top
#8873 - 2001-05-24 06:55 AM Re: Simple Script
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Welcome to the board.

Another way of get of getting an environment variable is:
f.e. we check environment variable tmp and write its value to the
registry. by errors you will get an error message.

code:

$env=ExpandEnvironmentVars("%tmp%")
IF (len($env) <> 0)
IF (AddKey("HKEY_CURRENT_USER\environment") <> 0)
? "Error "+@error+": "+@serror
ENDIF
ENDIF
IF (ExistKey("HKEY_CURRENT_USER\environment") = 1)
IF (WriteValue("HKEY_CURRENT_USER\environment","tmp",$tmp,"REG_SZ") <> 0)
? "Error "+@error+": "+@serror
ENDIF
ENDIF


Greetings.

------------------
Site map:

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.045 seconds in which 0.025 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