1

Is it possible that someone here could explain how to use this code. Please keep in mind i am a complete amateur, so simplifications may be needed.

Private Const cPGM = "C:\VB Forum\startup\Example.exe"

Dim oShell As IWshShell_Class
Set oShell = New IWshShell_Class
oShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyVBApp", _
               cPGM, "REG_SZ"

How exactly is this code used? Is it saved as an .exe file and ran or what? Thanks for your prompt reply and informational feedback.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Francesco D.
  • 11
  • 1
  • 2
  • Where did you get this code from? What are you trying to achieve? – Brian Willis Apr 02 '10 at 05:48
  • i got this code from this website. It gives a detailed description, however, id like a professional's advice on how to use it. As i said i'm inexperienced and could use a simplified instructions. It is to be used to get Example.exe to run at start-up. In addition, is it possible to have Example.exe running as a service, so continuously from start-up and in the background. Thanks again. – Francesco D. Apr 02 '10 at 06:48
  • sorry the website is http://oreilly.com/pub/a/oreilly/windows/ron/startup_0401.html – Francesco D. Apr 02 '10 at 06:49

1 Answers1

2

All this code does is add a value to the registry. It adds an item to the key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

with the name MyVBApp, and the value C:\VB Forum\startup\Example.exe

As it states in the article, this registry entry will cause the program C:\VB Forum\startup\Example.exe to launch automatically at system startup.

In order to use this code it does somehow have to be executed which, of course, requires an executable. If you want to see this code in action, the simplest thing to do would be to create a new "Standard EXE" project, add a reference to the Windows Script Host Object Model, paste the code into the Form_Load event, then run the app. Look at this registry key and you'll see this new entry. Be sure and delete it though because I assume you don't have some executable named C:\VB Forum\startup\Example.exe that you wish to run every time Windows starts, do you?

raven
  • 18,004
  • 16
  • 81
  • 112