Thursday, July 8, 2010

Startup with Windows (use wshom)

'two options - both require reference to Windows Script Host Object Mode (wshom.ocx)

'add a registry entry in HKLM\Software\Microsoft\Windows\CurrentVersion\Run
Dim oShell As IWshShell_Class
Set oShell = New IWshShell_Class
oShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyVBApp" , _
"c:\app\appname.exe" , "REG_SZ"


'put shortcut in startup menu
'include reference in VB program to Windows Script Host Object Mode (wshom.ocx)
Dim oShell As IWshShell_Class
Dim oSCut As IWshShortcut_Class
Dim sPath As String

Set oShell = New IWshShell_Class
sPath = oShell.SpecialFolders( "Startup" )
Set oSCut = oShell.CreateShortcut(sPath & "\TestStartup.lnk" )
oSCut.TargetPath = cPGM
oSCut.Save