Solved

Run program on startup

Posted on 2002-05-10
6
197 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
ID: 7000789
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
ID: 7000792
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
ID: 7000794
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:n_narayanan
ID: 7000802
For System Tray look at this,

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

Narayanan
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 7001056
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
ID: 7001472
This is a great site. I really appreciate all the help from you experts.

n narayanan this really works well.

C
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vba find the last empty column 10 89
VBA: Add rows to listbox based on criteria 7 79
add text to end of existing text in file 16 69
Visual Basic Excel Formatting error 4 85
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

864 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

24 Experts available now in Live!

Get 1:1 Help Now