Link to home
Start Free TrialLog in
Avatar of limva
limva

asked on

Did Program Run at Startup of Windows?

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!
Avatar of rspahitz
rspahitz
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PS
Set objWSHShell = Nothing at the end of Sub
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'.)
>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



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?
Avatar of limva
limva

ASKER

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!
Avatar of limva

ASKER

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!
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