Honza
Honza

Reputation: 101

launch VBS script after PC startup

I want launch my simple VBS script after PC startup (Win XP). I don't want put this script in C:\Documents and Settings\%UserName%\Start Menu\Programs\Startup

I want do it in script, it is possible?

Script:<br>
Dim oShell<br>
Set oShell = WScript.CreateObject ("WScript.Shell")<br>
oShell.run "notepad.exe c:\text.txt"

Upvotes: 10

Views: 74480

Answers (7)

dank8
dank8

Reputation: 369

Task Scheduler Alternative

No script is needed, create a new task (Task Scheduler 1.0 (learn.microsoft.com) for instruction). Then "Create a task" and populate at least these details:

New Trigger:  At Login
New Action -> Action:         Start A Program
              Program/Script:  notepad.exe
              Arguments:       text.txt
              Start in:        c:\

Software: Windows 10, Task Scheduler 1.0

Upvotes: -1

Gediz G&#220;RSU
Gediz G&#220;RSU

Reputation: 636

Easy Way :

Make a bat file

WScript.exe "Path\to\your\script.vbs"

add it to startup from gpedit.msc

Upvotes: 3

user8967105
user8967105

Reputation:

Add this code to the start of your vbs script Change the end of myKey to whatever you want to call the registry key

Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\MyVbsScript"
WshShell.RegWrite myKey,WScript.ScriptFullName,"REG_SZ"

Upvotes: 0

In-depth

How to Automate VBScripts to run at startup.

Step 1

  • Click Start -> Run -> cmd or Click search and type cmd
  • Press enter
  • Type assoc .vbs in command prompt Which should print .vbs=VBSFile
  • Type ftype VBSFile in command prompt

which should print:

vbsfile="%SystemRoot%\System32\WScript.exe" "%1" %*

So, now you know that your vbscript files open with WScript by default.

  • In command-prompt, type:

    reg query HKEY_CLASSES_ROOT\Applications\WScript.exe /s

If you do not see this:

HKEY_CLASSES_ROOT\Applications\WScript.exe
    (Standard)    REG_SZ    "%SystemRoot%\System32\WScript.exe" "%1" %*

Then you need to do the following, if the above is what you see, then you can skip and go to step 3:

Step 2

  • Go to:

    Start

    Run

  • Type in:

    regedit

  • Select regedit press enter (or double-click regedit) and allow the program to make changes to your computer

  • Navigate to:

HKEY_CLASSES_ROOT\Applications\WScript.exe (If WScript.exe key does not exist, right-click Applications and create new key, rename it to WScript.exe)

  • In the empty space on the right, where there are values, right-click and
  • Choose new
  • Select String Value
  • Under Name where New Value #1 is highlighted, rename by typing (Standard)
  • Under Data, double click the empty value and enter the value you got from the previous step

"%SystemRoot%\System32\WScript.exe" "%1" %*

Step 3

  • If you do not have regedit open,

Go to:

  • Start
  • Run

Type in:

regedit

Select app, press enter and allow the program to make changes to your computer

  • Else, if regedit is open, then:
  • Navigate to:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

  • Right click the run folder
  • in the empty space on the right, where there are values, right-click and choose new
  • Select Expandable String Value
  • Under Name where New Value #1 is highlighted, rename by typing your own name e.g. myscript
  • under Data, double click the empty value and enter this
  • Make sure its type is REG_EXPAND_SZ, i.e. an expanded string
"%SystemRoot%\System32\WScript.exe" "C:\Users\me\myFolder\mySub-folder\myFile.vbs" "%1" %*
  • Restart your machine. Your vbs should run automatically

Notes:

  • make sure .VBS is added to the Path environment variable
  • if you want to use cscript instead, In step 2 type:

    reg query HKEY_CLASSES_ROOT\Applications\cscript.exe /s

...instead and proceed, taking note to replace WScript with cscript where relevant i.e. this query:

reg query HKEY_CLASSES_ROOT\Applications\cscript.exe /s

Should produce this result:

(Standard)    REG_SZ    "C:\Windows\System32\cscript.exe" "%1" %*
  • If your key and/or value is messed up you can always right-click the messed up item and delete it. If you however want to use the terminal, you can always follow: http://ss64.com/nt/reg.html
  • To check if WScript is one of the startup apps, press ctrl+alt+delete, choose the Task Manager, click on Startup. You should see Microsoft Windows Based Script Host listed.

Upvotes: 6

Hichem
Hichem

Reputation: 1182

you can fire a vbscipt from registry or startup by

WScript C:\somefloder\somefolder2\yourscript.vbs

you can put this line in a value on

For all the users on the machine HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

for the current user HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Upvotes: -3

aphoria
aphoria

Reputation: 20179

You will either have to put it in the Startup folder or run it from the registry.

For all users, use registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.

For the current user, use registry key HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Upvotes: 7

Danielo515
Danielo515

Reputation: 7051

Just an appoinment, everybody probalby just know already.

HKLM is for any user on the machine, because means Local Machine

HKCU is just for the current user.

Upvotes: 1

Related Questions