| | |
How to know the User Log off or Shutdown the system Using VB
![]() |
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.
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.
Have a problem? Don't worry just give me a call and I'll fix it for you.
hmmm....
do like shouvik suggest if u want your program automatically when windows start.
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 *
So, Please do something before post your thread.
* PM Asking will be ignored *
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
NOW IN YOUR FORM_LOAD EVENT() PLACE THIS CODE
hope this helps.
regards
Shouvik
PLACE THIS CODE IN A MODULE
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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.
Have a problem? Don't worry just give me a call and I'll fix it for you.
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 :
see this following code :
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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 *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Apr 2008
Posts: 34
Reputation:
Solved Threads: 4
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.
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
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
•
•
Join Date: Apr 2009
Posts: 2
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Remote Computer Shutdown (Windows NT / 2000 / XP)
- HELP! have HiJackThis log (Viruses, Spyware and other Nasties)
- Just ran HijackThis, new log... (Viruses, Spyware and other Nasties)
- Badly infected system, please help! (Viruses, Spyware and other Nasties)
- "lsass.exe", HOTMAIL/MSN, Trojan'd up the WAZOOOO. [Help!] (Viruses, Spyware and other Nasties)
- getting rid of Admilliserve log file (Viruses, Spyware and other Nasties)
- Hijacked! Log attached - please help! (Viruses, Spyware and other Nasties)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: In VB6.0 How do i want to find function get path windows fonts directory?
- Next Thread: How to display the form in foreground using vb6?
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






