I've developed the little class below as what I hope is a generally-
useful way of adding programs to, and removing them from, the Registry
list of apps that start automatically with Windows. I'd be grateful
for any comments that y'all might be able to give me. Thanks.
----------
Usage:
Dim ASU As CAutoStartup
ASU = New CAutoStartup("[registry-key-value]")
...
IF ASU.Active Then ... ' If program already in auto-startup list
...
Try
ASU.Active = True ' Method 1 of interaction
Catch ex as Exception
MessageBox.Show(ex.ToString, "Whoops!")
End Try
...
ASU.Disable() ' Method 2 of interaction
...
ASU = Nothing
----------
Class:
Imports Microsoft.Win32
Public Class CAutoStartup
Private Const STARTUP_KEY As String = _
"Software\Microsoft\Windows\CurrentVersion\Run \"
Private m_Value As String
Private m_Executable As String
Public Sub New(ByVal Value As String)
m_Value = Value
m_Executable = Application.ExecutablePath
End Sub
Public Sub New(ByVal Value As String, ByVal Executable As String)
m_Value = Value
If Executable = vbNullString Then
m_Executable = Application.ExecutablePath
Else
m_Executable = Executable
End If
End Sub
Public Property Active() As Boolean
Get
Return StartupIsActive()
End Get
Set(ByVal Value As Boolean)
Select Case Value
Case True : Enable()
Case False : Disable()
End Select
End Set
End Property
Public Sub Enable()
Dim Key As RegistryKey
If Me.Active Then Exit Sub
Key = Registry.CurrentUser.OpenSubKey(STARTUP_KEY, True)
If Key Is Nothing Then
Throw New Exception("Registry key not available.")
Exit Sub
End If
Try
Key.SetValue(m_Value, m_Executable)
Catch
Throw New Exception("Unable to write registry value.")
End Try
Key = Nothing
End Sub
Public Sub Disable()
Dim Key As RegistryKey
If Not Me.Active Then Exit Sub
Key = Registry.CurrentUser.OpenSubKey(STARTUP_KEY, True)
If Key Is Nothing Then Exit Sub
Try : Key.DeleteValue(m_Value) : Catch : End Try
Key = Nothing
End Sub
Private Function StartupIsActive() As Boolean
Dim Key As RegistryKey
Dim Value As String
Key = Registry.CurrentUser.OpenSubKey(STARTUP_KEY)
If Key Is Nothing Then Return False
Value = Key.GetValue(m_Value, vbNullString)
Key = Nothing
Return (Value = m_Executable)
End Function
End Class 4 1218
* Tony Vitonis <no***@nowhere.com> scripsit: I've developed the little class below as what I hope is a generally- useful way of adding programs to, and removing them from, the Registry list of apps that start automatically with Windows. I'd be grateful for any comments that y'all might be able to give me. Thanks.
You may want to extend the class with a Run Once feature. You will find
a VB6 implementation here: <http://vbaccelerator.com/article.asp?id=2520>.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Hi Tony,
There are two sets of startup registry keys - one for the current user,
which you have, and one for all users (HKLM). You may want to provide that as
well.
You might also like to give the option of starting from either of the
Programs/Startup folders - current user and All Users (and maybe Default
User).
Regards,
Fergus
Excellent suggestions from you and Mr. Wagner, thanks. I'll work on
the class at leisure and resubmit for your perusal when I'm "done".
(Very O.T.: Herr Wagner, have you heard the German word "Dorfmatraze"?
I heard it the other day, and while my German is scanty and distant, I
imagine it to mean "village mattress", something like "the town
bicycle in English.) fi******@tesco.net says...
There are two sets of startup registry keys - one for the current user, which you have, and one for all users (HKLM). You may want to provide that as well.
You might also like to give the option of starting from either of the Programs/Startup folders - current user and All Users (and maybe Default User).
Hi Tony,
ROFL.:-)) Definitely OT.
I had to think about the town bicycle (then, of course - 'Out for a <ride>
on the town bicycle'), but village mattress has instantly recognisable charm!!
Regards,
Fergus
ps It's Dorfmatratze, but I reckon that was just a typo. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dschectman |
last post by:
I have an interesting issue. I need to implement a dynamic table to
mimic a select list. Each time you double click from the master list,
a row is added to the list of selected items. The list...
|
by: Mike |
last post by:
So, I've been trying to do "MyFirstVBWebApp" and I am hitting numerous
roadblocks. After much google'ing, here is what I have done
(XP Pro SP1, IIS 5.1)
1. Uninstalled IIS
2. renamed the...
|
by: NAGY |
last post by:
hello,
I created an asp.net web app in C# from a non administrative account in
Visual Studio 2003, .net 1.1. when i try to run the application in debug mode
from Debug start menu option, i get an...
|
by: Brett Romero |
last post by:
I'd like to start my app by double clicking a file. Via the file
extension, it should know the app to load. The file will contain
several IDs in XML, which my gets data off of and loads into a...
|
by: Ashley Bryant |
last post by:
I've created a Windows Service in vb.net that is set up to run automatically,
but it never starts during system startup. I can start it manually, but I
need the service to start without any user...
|
by: =?Utf-8?B?bm95ZXM=?= |
last post by:
I have a solution that contains a windows forms project and some web service
projects. Some of the web service projects are file-based and some are
project based. When I run the application from...
|
by: SAL |
last post by:
I have an ASP.NET 2.0 app that takes about 17 seconds to load on first
startup but then is very fast after that. As I understand it from some posts
in June, this is caused by the loading of the App...
|
by: Smokey Grindel |
last post by:
Ok this is wierd I am seeing this issue with C# and VB.NET apps made in
..NET...
I have the framework installed (.NET 3.5 currently)... i installed my
applications... I placed them in the...
|
by: SilverGS |
last post by:
I want to automatically open a Command Window from the Startup folder in Windows XP.
right now after XP starts, I click on Start run, cmd and then when the command window is open I type in a bunch...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |