Code for adding programs to self starting items using VBS scripts

Time:2022-4-30

Because the editor filters some characters, such as &, the following script may run incorrectly.. Just add & & this character.
There are many functions of vbs script, but sometimes we only need some of them. Today, I suddenly want to study how to use vbs script to add programs to self startup items

Let’s start with a paragraph

Copy codeThe code is as follows:


‘==========================================================================

‘ VBScript Source File — Created with SAPIEN Technologies PrimalScript 4.1

‘ NAME: add2run01.vbs

‘ AUTHOR: shile
‘ DATE : 2008-12-13

‘comment: VBS implementation adds program to self start item

‘==========================================================================
On error resume next ‘error resume next command
dim ws
Set ws=CreateObject(“Wscript.Shell”)
ws.RegWrite “HKLM\Software\Microsoft\Windows\CurrentVersion\Run\cmd”,”cmd.exe”


It was intercepted by 360 security guards, but just click agree. After refreshing in AutoRuns, the startup item cannot be displayed. It seems that the software is not perfect
The function is too weak. I want to enhance
First, pop up a window to ask what program to add to the startup item, and ask the key value of the next startup item.

Copy codeThe code is as follows:


‘==========================================================================

‘ VBScript Source File — Created with SAPIEN Technologies PrimalScript 4.1

‘ NAME: add2run02.vbs

‘ AUTHOR: shile
‘ DATE : 2008-12-13

‘comment: VBS implementation adds program to self start item

‘==========================================================================
On error resume next ‘error resume next command
Dim ws
Set ws=CreateObject(“Wscript.Shell”)
Dim runKey,runPath
Runkey = InputBox (“enter the key value name of self startup item”, “please enter”)
Runpath = InputBox (“enter the corresponding program path”, “please 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!”


Originally want to use vbok, but found that there are still two buttons, or vbyes!
The function is still not very strong. If you can judge whether there are existing items and whether to replace them for confirmation, it will be more perfect!
Go on

Copy codeThe code is as follows:


‘==========================================================================

‘ VBScript Source File — Created with SAPIEN Technologies PrimalScript 4.1

‘ NAME: add2run03.vbs

‘ AUTHOR: shile
‘ DATE : 2008-12-13

‘comment: VBS implementation adds program to self start item

‘==========================================================================
On error resume next ‘error resume next command
dim ws
Set ws=CreateObject(“Wscript.Shell”)
Dim runKey,runPath
Runkey = InputBox (“enter the key value name of self startup item”, “please enter”)
Runpath = InputBox (“enter the corresponding program path”, “please enter”)
Dim temp,ret
temp = ws.RegRead(“HKLM\Software\Microsoft\Windows\CurrentVersion\Run\”&runKey)
‘MsgBox temp
If temp <> Empty Then
RET = msgbox (“the key value” & runkey “already exists, its value is” & Temp “, whether to replace it with the new value” & runpath, vbokcancel, “prompt!”)
If ret = vbOK Then
ws.RegWrite “HKLM\Software\Microsoft\Windows\CurrentVersion\Run\”&runKey,runPath
Msgbox “modify” & runkey “value is” & 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 startup entries in the registry, so I won’t explain them one by one