How to know the User Log off or Shutdown the system Using VB

Reply

Join Date: Apr 2008
Posts: 11
Reputation: mafaisal is an unknown quantity at this point 
Solved Threads: 0
mafaisal mafaisal is offline Offline
Newbie Poster

How to know the User Log off or Shutdown the system Using VB

 
0
  #1
Apr 6th, 2008
Hello Experts

When the system user Log off the system , shutdown and so on How to know that in vbcode
Bcoz When user Log on i have vb application that automatically work, but when user logg off , shut down i have write code in application

Please Help me

Faisal
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: How to know the User Log off or Shutdown the system Using VB

 
0
  #2
Apr 6th, 2008
place a shortcut of your vb application in windows startup folder. it will automatically launch your program whenever you will login to windows.

and for shutdown, there is no coding required. windows already has a logging off utility that logs off each user from the current session before your computer is going to be restarted or shut down and unloads/closes all running processes/programs from memory.

so make sure your program is running. you can ensure that by visiting the process list in windows task manager. now when a user logs off from his/her session windows will automatically unload your program and close it.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: How to know the User Log off or Shutdown the system Using VB

 
0
  #3
Apr 6th, 2008
hmmm....
do like shouvik suggest if u want your program automatically when windows start.
Last edited by Jx_Man; Apr 6th, 2008 at 2:56 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: How to know the User Log off or Shutdown the system Using VB

 
0
  #4
Apr 6th, 2008
instead of placing the shortcut if you wish to launch your program automatically though coding then you can try the following snippet :-

PLACE THIS CODE IN A MODULE
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
  4. (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  5.  
  6. Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey _
  7. As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData _
  8. As Any, ByVal cbData As Long) As Long
  9.  
  10. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  11.  
  12. Public Const REG_SZ = 1
  13. Public Const HKEY_LOCAL_MACHINE = &H80000002
  14.  
  15. Public Sub IncludeAtStartup(hKey As Long, strPath As String, strValue As String, _
  16. strdata As String)
  17.  
  18. Dim keyhand As Long
  19. Dim r As Long
  20.  
  21. r = RegCreateKey(hKey, strPath, keyhand)
  22. r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
  23. r = RegCloseKey(keyhand)
  24. End Sub

NOW IN YOUR FORM_LOAD EVENT() PLACE THIS CODE
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim strname as String
  2.  
  3. strname = App.EXEName & ".Exe"
  4. Call IncludeAtStartup(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
  5. strname, App.Path & "\" & App.EXEName & ".exe")

hope this helps.

regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: How to know the User Log off or Shutdown the system Using VB

 
0
  #5
Apr 6th, 2008
also u can write code to put your application on startup folder. so u no need to put your program manually on startup.
see this following code :
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub GetStartUp()
  2. Dim mShell
  3. Dim txtFStartUp As String
  4. Set mShell = CreateObject("WScript.Shell")
  5. txtFStartUp = mShell.SpecialFolders("Startup")
  6.  
  7. FileCopy App.Path & "\" & App.EXEName & _
  8. ".exe", txtFStartUp & "\YourAppName.exe"
  9. End Sub
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 34
Reputation: techtix is an unknown quantity at this point 
Solved Threads: 4
techtix techtix is offline Offline
Light Poster

Re: How to know the User Log off or Shutdown the system Using VB

 
0
  #6
Apr 7th, 2008
If you need to write custom code during the shutdown of the application and need to check to see if the user is logging off or if the machine is shutting down, use the forms QueryUnload event.

Form_QueryUnload(cancel As Integer, unloadmode As Integer)
UnloadMode will identify HOW the request to shutdown was received. You can set Cancel to True to halt the process, but in the event of a system shutdown, Windows may terminate the process.

The list of UnloadMode constants can be found on the Microsoft MSDN site.
http://msdn2.microsoft.com/en-us/lib...36(VS.60).aspx
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 2
Reputation: yuvi_mis is an unknown quantity at this point 
Solved Threads: 0
yuvi_mis yuvi_mis is offline Offline
Newbie Poster

Re: How to know the User Log off or Shutdown the system Using VB

 
0
  #7
Apr 26th, 2009
Dear Experts,
I have developed the one vb project in my machine.It's Working fine. my problem is My form(alert) has been disaplayed when i run the exe but it was showing in background so i couldn't see in my form(alert) in foreground bcoz i have working another application at the time.hence how to display the form in foreground in runtime when i using the another apllication.

Thank you,
V.Yuvi@Shiva
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: How to know the User Log off or Shutdown the system Using VB

 
0
  #8
Apr 26th, 2009
your intension is not clear from your explanation....plz explain it in more detail...

regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC