Use the vbs script to add a program to the auto-start item

Source: Internet
Author: User

[Programming instance] Use vbs script to addProgramTo the auto-start item

Tip: WriteArticleThen we found that the csdn editor filtered out some characters, such as &, so the following script may run incorrectly .. Add & this character to the viewer.

There are many vbs script functions, but sometimes we only need some of them, today, I suddenly want to study how to use the vbs script to add a program to a self-starting item ......

Let's start with a paragraph...

'================================================ ==========================================
'
'Vbscript source file -- created with sapien technologies primalscript 4.1
'
'Name: add2run01. vbs
'
'Author: shile
'Date: 2008-12-13
'
'Comment: vbs implements adding a program to a self-starting item
'
'================================================ ==========================================

On Error resume next 'error continues executing next command

Dim WS

Set Ws = Createobject ("wscript. Shell ")

WS. regwrite "HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Run \ cmd", "cmd.exe"

It was intercepted by the 360 security guard, but you can click "agree. The startup item cannot be displayed after being refreshed in autoruns. It seems that this software is not perfect.

The function is too weak. I want to enhance it ....

First, open a window to ask what program to add to the startup item, and ask about the key value of the startup Item.

'================================================ ==========================================
'
'Vbscript source file -- created with sapien technologies primalscript 4.1
'
'Name: add2run02. vbs
'
'Author: shile
'Date: 2008-12-13
'
'Comment: vbs implements adding a program to a self-starting item
'
'================================================ ==========================================

On Error resume next 'error continues executing next command

Dim WS

Set Ws = Createobject ("wscript. Shell ")

Dim runkey, runpath

Runkey = inputbox ("enter the name of the auto-START key value", "enter ")
Runpath = inputbox ("Enter the corresponding program path", "enter ")

'Ws. regwrite "HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Run \ cmd", "cmd.exe"

WS. regwrite "HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Run \" & runkey, runpath

'Prompt

Msgbox "added" & runkey "<" & runpath "> succeeded", vbyes, "Congratulations! "
It was originally intended to use vbok, but we found that there are still two buttons, or vbyes!

The function is still not strong. If you can determine whether there are existing items and whether to replace the items for confirmation, it will be more complete!

Continue...

'================================================ ==========================================
'
'Vbscript source file -- created with sapien technologies primalscript 4.1
'
'Name: add2run03. vbs
'
'Author: shile
'Date: 2008-12-13
'
'Comment: vbs implements adding a program to a self-starting item
'
'================================================ ==========================================

On Error resume next 'error continues executing next command

Dim WS

Set Ws = Createobject ("wscript. Shell ")

Dim runkey, runpath

Runkey = inputbox ("enter the name of the auto-START key value", "enter ")
Runpath = inputbox ("Enter the corresponding program path", "enter ")

Dim temp, RET
Temp = ws. regread ("HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Run \" & runkey)
'Msgbox temp

If temp <> empty then
Ret = msgbox ("key value" & runkey "already exists, its value is" & Temp ", whether to replace it with a new value" & runpath, vbokcancel, "prompt! ")
If ret = vbok then
WS. regwrite "HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Run \" & runkey, runpath
Msgbox "changed" & runkey "to" & runpath "success", vbyes, "Congratulations! "
End if
Else
WS. regwrite "HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Run \" & runkey, runpath
Msgbox "added" & runkey "<" & runpath "> succeeded", vbyes, "Congratulations! "
End if

Of course, there are many boot items in the registry ......

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/shile/archive/2008/12/13/3511724.aspx

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.