Solved

Run program on startup

Posted on 2002-05-10
6
194 Views
Last Modified: 2007-12-19
How do I get an application to run when the PC starts up. i.e it will appear in the system tray.

Is there a way to add this facility when an application is setup on a PC or when the application is run for the first time

0
Comment
Question by:cuntacinte
6 Comments
 
LVL 5

Expert Comment

by:Bhaskar Ganapathe
Comment Utility
Hi cuntacinte,

   You can do this by editing the WIN.INI file.

   Beware, its very dangerous.

   Throught VB, you have to open the WIN.INI file and add a line to run ur program.

   THis will make ur program to run when u start the PC. Or you can put ur exe in the Startup through
0
 
LVL 3

Accepted Solution

by:
n_narayanan earned 300 total points
Comment Utility
Include this in your vb code

Public Sub EnableStartup()
    Dim cPGM As String
    Dim oShell As IWshRuntimeLibrary.IWshShell, frmMsgBox As frmMessageBox
    On Error GoTo ErrEnablestartup
    Set oShell = New IWshRuntimeLibrary.IWshShell_Class
   
   
    cPGM$ = App.Path & "\pmsg.exe"
    oShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\PMSG", cPGM, "REG_SZ"
    Set oShell = Nothing
    Exit Sub
ErrEnablestartup:
    Dim strErr As String
    strErr = "Err no:" & Err.Number & " Err Desc:" & Err.Description & " Module:Global Proc:EnableStartup " & " Sts:Continue Process " & Date & " " & Time
    Call ErrorLog(strErr)
End Sub


Where pmsg.exe is your application name

0
 
LVL 3

Expert Comment

by:n_narayanan
Comment Utility
This is for removal

' Needs a reference to the project "Windows Script Host Object Model" WSHOM.OCX
Public Sub DisableStartup()
    Dim oShell As IWshRuntimeLibrary.IWshShell_Class, frmMsgBox As frmMessageBox
    On Error GoTo ErrDisableStartup
    Set oShell = New IWshRuntimeLibrary.IWshShell_Class
 
    oShell.RegDelete "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\PMSG"
    Set oShell = Nothing
    Exit Sub
ErrDisableStartup:
    Resume Next
End Sub
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 3

Expert Comment

by:n_narayanan
Comment Utility
For System Tray look at this,

http://www.freevbcode.com/ShowCode.Asp?ID=950

Narayanan
0
 
LVL 28

Expert Comment

by:vinnyd79
Comment Utility
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const ERROR_SUCCESS = 0&
Private Const REG_SZ = 1
Private X As Long

Private Sub SaveString(Hkey As Long, strpath As String, strValue As String, strdata As String)
    Dim keyhand As Long
    Dim r As Long
    X = RegCreateKey(Hkey, strpath, keyhand)
    X = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
    X = RegCloseKey(keyhand)
End Sub

Private Sub Command1_Click()
Call SaveString(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "appname", "C:\myapp.exe")
End Sub
0
 

Author Comment

by:cuntacinte
Comment Utility
This is a great site. I really appreciate all the help from you experts.

n narayanan this really works well.

C
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Why I am having this error installing Visual Basic Enterprise 11 55
z = x + y – 1 6 54
Access 2016 VB code 9 85
VBA filters 2 37
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now