Java modifies the Windows registry to enable auto-Start applications ., Javawindows

Source: Internet
Author: User

Java modifies the Windows registry to enable auto-Start applications ., Javawindows

To modify the Windows registry using Java, use the cmd command.

The example and running result are as follows:

Package day01; import java. io. IOException;/* 1, reg add a new subitem or item to the Registry Syntax: reg add KeyName [/v EntryName |/ve] [/t DataType] [/s separator] [/d value] [/f] parameter KeyName specifies the full path of the subitem. For remote computers, please include the computer name before the sub-path in \ ComputerName \ PathToSubkey. If ComputerName is ignored, operations on the local computer are performed by default. Start with the corresponding subdirectory tree path. The valid subdirectory trees are HKLM, HKCU, HKCR, HKU, and HKCC. Only HKLM and HKU are available on the remote machine. Description of the value HKCR: HKEY_CLASSES_ROOT HKCU: HKEY_CURRENT_USER HKLM: HKEY_LOCAL_MACHINE HKU: HKEY_USERS HKCC: HKEY_CURRENT_CONFIG/v EntryName specifies the name of the item to be added to the specified subitem. /Ve specifies that the entry added to the registry is null. /T DataType specifies the Data Type of the item value. DataType can be of the following types: REG_SZ REG_MULTI_SZ REG_DWORD_BIG_ENDIAN REG_DWORD REG_BINARY REG_LINK REG_FULL_RESOURCE_DESCRIPTOR REG_EXPAND_SZ/s separator specifies the characters used to separate multiple data instances. Use this parameter when REG_MULTI_SZ is specified as the data type and multiple items need to be listed. If not specified, the default separator "\ 0" is used ". /D value specifies the value of the new registry key. /F directly add a subitem or item without asking for information. /? Display help at the command prompt. Note that this operation cannot add a subtree. This version of Reg does not need to be confirmed when you add a subitem. The following table lists the return values of the reg add operation. Value description 0 Success 1 failure */public class Test00 {/*** Reg parameter description */v option to add or delete value name */t RegKey data type (reg_sz string) */d the data to be allocated to the added registry ValueName */f force deletion without prompting */public static void changeStart (boolean isStartAtLogon) throws IOException {String regKey = "HKEY_CURRENT_USER \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run"; String myAppName = "mgtest"; String exePath = "\" D: \ Program Files (x86) \ love \ HelloWorld. Exe \ ""; runtime.getruntime(cmd.exe c ("reg" + (isStartAtLogon? "Add": "delete") + regKey + "/v" + myAppName + (isStartAtLogon? "/T reg_sz/d" + exePath: "/f");} public static void main (String [] args) throws IOException {try {changeStart (true );} catch (IOException e) {// changeStart (false); e. printStackTrace ();}}}

 

 

 

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.