[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