VB6 Write the Registration form

Source: Internet
Author: User

Inevitably encounter the case of writing a registry, wrote a practical point of the RegWrite function. In order to reduce the amount of code, Wscript.Shell replaced the API to achieve.

The way it's used is in the comments, and it's not too much to explain. PS: Comments are much richer than implementation code, m (-.-) m

Code:

Private FunctionRegWrite (ByValName_ as String,OptionalValue_ as String,OptionalType_ as String="REG_SZ") as Integer'@Author: Lichmama'@Whatfor: Offer a simply -to-write registry'@Arguments:'name_, String'Registry key/value Path, eg. Hkey_current_user\environment (\?)'Value_, String, Optional'Registry Value Name'Type_, String, Optional and default with "REG_SZ"'Registry Data Type, eg. REG_SZ, REG_BINARY, ...'@Usage:'Create new subitem:'Call RegWrite ("hkey_current_user\enviroment\newsubitem\")'Create new subitem and set the default value:'Call RegWrite ("hkey_current_user\enviroment\newsubitem\", "Default-value-data")'Create new value:'Call RegWrite ("Hkey_current_user\enviroment\newsubitem\newvalue", "New-value-data", "REG_EXPAND_SZ")'Overwrite value:'Call RegWrite ("Hkey_current_user\enviroment\newsubitem\newvalue", "Overwrite-value-data", "REG_SZ")'@Return: Integer, zero means successful, and Non-zero means failed on Error GoToError_Handler:DimObjshell as Object        SetObjshell =CreateObject("Wscript.Shell")        IfIsMissing (Value_) Then        PagerObjshell. RegWrite (name_)Else        PagerObjshell. RegWrite (Name_, Value_, Type_)End IfError_handler:regwrite=Err.NumberSetObjshell = NothingEnd Function

Use the above method to write the registry to modify the environment variables to take effect immediately:

Private Declare FunctionSendMessageTimeoutLib "User32" Alias "Sendmessagetimeouta" _    (ByValhwnd as Long, _    ByValMsg as Long, _    ByValWParam as Long, _    ByRefLParam asAny , _ByValFuflags as Long, _    ByValUtimeout as Long, _    ByRefLpdwresult as Long) as LongPrivate ConstHwnd_broadcast = &HFFFF&Private ConstWm_wininichange = &h1aPrivate ConstWm_settingchange =Wm_wininichangePrivate ConstSmto_normal = &H0Private Subupdatesystemenvironment ()'@http://www.bczlw.com/article/faq/bianchengyuyan/vc-mfc/2007-3-5/2007030523033000.html    PagerSendMessageTimeout (Hwnd_broadcast, Wm_settingchange,0&,ByVal "Environment", Smto_normal, +&,0&)End Sub

VB6 Write the Registration form

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.