Link to home
Start Free TrialLog in
Avatar of kvnagaraj2000
kvnagaraj2000

asked on

Running VB program at startup and shut down automatically

How can I run VB application at the startup and shut down after a specified time?  I am developing a personal application that should run automatically at startup which takes the administrator login to give permission for a specified time i.e. 1 hr / 2 hrs etc and runs in the background.  Once the time is elapsed, it should shutdown automatically.  I would like to restrict my children to play/use computer for a limited time only.
SOLUTION
Avatar of mladenovicz
mladenovicz

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
Avatar of mladenovicz
mladenovicz

Ooops. This
ret& = ExitWindowsEx(EWX_FORCE Or SHUTDOWN, 0)
should be
 ret& = ExitWindowsEx(EWX_FORCE Or EWX_SHUTDOWN, 0)
ASKER CERTIFIED SOLUTION
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
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore 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
Avatar of kvnagaraj2000

ASKER

Thanks for the replies.  I am working on them.  Just wondering, how can I avoid displaying the instance of the application in the Task bar?
Check ShowInTaskbar property of form
Hi,

Also you can do that:

App.TaskVisible = False

So it is not visible in Windows task manager. Good luck ;)

Michael
SOLUTION
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
Though I could able to logoff, remove the instance from the taskbar and placing the program in the startup folder, I couldn't run the program automatically.  I need to click the program from the start menu.  But I want to run my program automatically and if possible, it souldn't allow to start other programs until it gives access.  How can I proceed?

I have tried with the code given by  mladenovicz for both running & shutdown.  Shutdown is perfectly working but it is throwing an error when I try to run the program automatically at startup by placing the module code in the module, program code in the form_load and replaced the path.  Anybody can help in this regard?
What error do you get? What line does produce error?
I have copied the code in the module & form_load and changed the path of the EXE file... In the immediate window it has displayed "error" as the retval=161.  
This code that creates key in registry should be executed just once. That code can be a part of your app and you will have to check if key exists - you should not create key if it exists. Or you can create separate app that adds this info to the registry and execute it just once.
>>I would like to restrict my children to play/use computer for a limited time only.
r u sure .. this is the y the program is been made .. i hope so .. and if the computer shutsdown after 1 or 2 hours .. what stops ur children from starting the computer again ?