Solved

Did Program Run at Startup of Windows?

Posted on 2001-08-07
9
152 Views
Last Modified: 2010-05-02
I have a program that needs to run at the startup of Windows (Win98).  My questions are:

1. How do I make it run automatically at Windows startup without putting it or its shortcut in the Start Up folder?

2. Is there a way to let the program know that it was run at Windows startup or it was started manually?

Thanks in advance!
0
Comment
Question by:limva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 6361818
I think you can modify the win.ini to get it to start when Windows starts, or on NT, set it as a service that starts at login.

To test when it was run, I think I heard that there's a function that indicates how many milliseconds have passed since Windows started.  If you check this and compare against a reasonably small number (< 2 minutes?) then you can probably assume that it began with the Windows startup.

Anther way is to add two programs at Windows startup, with a hidden "test" app first and your real app second.  If your real app detects the first program is not running, then the user probably shut it down and you app was manually started.  If your app see that it is running, compare the time it started against the time your app started; if the time is sufficiently small, then they started together at startup.
0
 
LVL 28

Accepted Solution

by:
Ark earned 100 total points
ID: 6361837
Hi
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long

Private Sub Form_Load()
    Dim objWSHShell As Object
    Dim s As String
    Dim bManually As Boolean
    Set objWSHShell = CreateObject("WScript.Shell")
    On Error Resume Next
    s = objWSHShell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyApp")
    If Err or s = "" Then 'Running first time
       s = App.Path
       If Right$(s, 1) <> "\" Then s = s & "\"
       objWSHShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyApp", s & App.EXEName & ".exe"
    End If
    If GetTickCount > 10000 Then bManually = True
End Sub

Cheers
0
 
LVL 28

Expert Comment

by:Ark
ID: 6361846
PS
Set objWSHShell = Nothing at the end of Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:rspahitz
ID: 6361872
Hey, Ark...yeah, that's the timer thing I was looking for.

The thing I wonder is: if your system takes 2 minutes to boot, what will be the value of GetTickCount when this app runs at startup?  Will it be within the 10000 millisecond period?  If not, you get a false reading.

(Also, to be explicit, you should probably initialize bManual = false somewhere before the 'if'.)
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6361885
>If GetTickCount > 10000 Then bManually = True


Might be more solid to include a command line parameter in the reg start up.

objWSHShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyApp", s & App.EXEName
& ".exe -Auto"

Then

If Command$ Like "*-Auto*" Then bManually = True



0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6361897
But Paul, if you do that, then somewhere you must delete the registry entry when Windows shuts down (or crashes) or it will still be there next time you start up, won't it?
0
 

Author Comment

by:limva
ID: 6361949
Thanks guys!  All of your solutions are right!  But Ark's is the best for my needs right now.

Paul's suggestion is also very good. If Windows crashes or shuts down and it reboots, that will still count as an automatic startup of the program.  Therefore the parameter "Auto" stays in the registry.

Thanks again and the best to all of you!
0
 

Author Comment

by:limva
ID: 6361953
Thanks guys!  All of your solutions are right!  But Ark's is the best for my needs right now.

Paul's suggestion is also very good. If Windows crashes or shuts down and it reboots, that will still count as an automatic startup of the program.  Therefore the parameter "Auto" stays in the registry.

Thanks again and the best to all of you!
0
 
LVL 28

Expert Comment

by:Ark
ID: 6362156
Thanks for points, glad I could help you.
Sure, Paul's solution for checking bManually is better.
I used GetTickCount in my old app which used RunOnce key. This key works brfore logging and seems window not count ticks before logging.

Cheers
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

740 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