Generate System Environment Variables

Source: Internet
Author: User
Code
Procedure createenvironment (const alibpath, aincpath: string );
Resourcestring
Reg_c51_lib = 'c51lib ';
Reg_c51_inc = 'c51inc ';
Reg_path = 'path ';
Reg_machine_location = 'System \ CurrentControlSet \ Control \ Session Manager \ environment ';
Reg_user_location = 'enable ';
VaR
Fpath: string;

Function dataexits (const asources, aData: string): Boolean;
VaR
Flist: tstrings;
I: integer;
Begin
Result: = false;
Flist: = Split (asources ,';');
For I: = 0 to flist. Count-1 do
Begin
If flist [I] = aData then result: = true;
End;
End;
Begin
With Tregistry. Create do
Begin
Try
Rootkey: = HKEY_LOCAL_MACHINE;
Openkey (reg_machine_location, true );

Fpath: = readstring (reg_path );

If not dataexits (fpath, alibpath) then
Begin
Fpath: = readstring (reg_path) + alibpath + ';';

Writestring (reg_path, fpath );
Setenvironmentvariable (pchar (reg_c51_lib), pchar (alibpath ));
// Sendmessage (hwnd_broadcast, wm_settingchange, 0, INTEGER (pchar ('Environment ')));
End;

Fpath: = readstring (reg_path );
If not dataexits (fpath, aincpath) then
Begin
Fpath: = readstring (reg_path) + aincpath + ';';

Writestring (reg_path, fpath );
Setenvironmentvariable (pchar (reg_c51_lib), pchar (alibpath ));
// Sendmessage (hwnd_broadcast, wm_settingchange, 0, INTEGER (pchar ('Environment ')));
End;
Sendmessage (hwnd_broadcast, wm_settingchange, 0, INTEGER (pchar ('Environment ')));
Finally
Free;
End;
End;
End;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.