User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 361,551 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,077 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser:
Views: 419 | Replies: 5
Reply
Join Date: Apr 2008
Location: Saudi Arabia
Posts: 11
Reputation: mafaisal is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
mafaisal mafaisal is offline Offline
Newbie Poster

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

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 493
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 45
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro in Training

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

  #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  
Join Date: Nov 2007
Location: Jogja
Posts: 2,259
Reputation: Jx_Man is just really nice Jx_Man is just really nice Jx_Man is just really nice Jx_Man is just really nice Jx_Man is just really nice 
Rep Power: 9
Solved Threads: 191
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Nearly a Posting Maven

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

  #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 1:56 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 493
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 45
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro in Training

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

  #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
Option Explicit

Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey _
As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData _
As Any, ByVal cbData As Long) As Long

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Public Const REG_SZ = 1
Public Const HKEY_LOCAL_MACHINE = &H80000002

Public Sub IncludeAtStartup(hKey As Long, strPath As String, strValue As String, _
strdata As String)

Dim keyhand As Long
Dim r As Long

r = RegCreateKey(hKey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
End Sub

NOW IN YOUR FORM_LOAD EVENT() PLACE THIS CODE
Dim strname as String

strname = App.EXEName & ".Exe"
            Call IncludeAtStartup(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
            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  
Join Date: Nov 2007
Location: Jogja
Posts: 2,259
Reputation: Jx_Man is just really nice Jx_Man is just really nice Jx_Man is just really nice Jx_Man is just really nice Jx_Man is just really nice 
Rep Power: 9
Solved Threads: 191
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Nearly a Posting Maven

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

  #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 :
Private Sub GetStartUp()
    Dim mShell
    Dim txtFStartUp As String
    Set mShell = CreateObject("WScript.Shell")
    txtFStartUp = mShell.SpecialFolders("Startup")
    
    FileCopy App.Path & "\" & App.EXEName & _
    ".exe", txtFStartUp & "\YourAppName.exe"
End Sub
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Apr 2008
Posts: 20
Reputation: techtix is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
techtix techtix is offline Offline
Newbie Poster

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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 1:55 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC