Click here to Skip to main content
15,917,795 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHow to detect lost internet connection ? Pin
cheeken2u20-Jan-08 20:15
cheeken2u20-Jan-08 20:15 
GeneralRe: How to detect lost internet connection ? Pin
Vimalsoft(Pty) Ltd21-Jan-08 0:30
professionalVimalsoft(Pty) Ltd21-Jan-08 0:30 
GeneralRe: How to detect lost internet connection ? Pin
Steven J Jowett21-Jan-08 2:19
Steven J Jowett21-Jan-08 2:19 
QuestionHow to Pass a Double Quote (")in a string ? Pin
SekharOne20-Jan-08 18:44
SekharOne20-Jan-08 18:44 
AnswerRe: How to Pass a Double Quote (")in a string ? Pin
Nilesh Hapse20-Jan-08 20:38
Nilesh Hapse20-Jan-08 20:38 
AnswerRe: How to Pass a Double Quote (")in a string ? Pin
John_Adams20-Jan-08 22:45
John_Adams20-Jan-08 22:45 
AnswerRe: How to Pass a Double Quote (")in a string ? Pin
The Mighty Atom21-Jan-08 10:20
The Mighty Atom21-Jan-08 10:20 
QuestionGlobal hooks from a Windows Service Pin
Raveheart20-Jan-08 9:15
Raveheart20-Jan-08 9:15 
Can anyone help with the following? I need my Local System Service to check for the time of last user activity on an XP box with multiple logins using fast user switching. I've tried using a .dll (see link at the Imports statement) to hook the keyboard (intending to set a global TickCount variable on KeyDown events) after setting the service to interact with the desktop of the most recently logged in user. I can attach to the process from the VS debugger and step through everything without any error, but the KeyDown handler never gets called. I know the following "snippet" is still quite a bit to wade through but I'm stumped and getting desperate. Anyone see where I'm going wrong - or know an easier way of getting a global "LastInputTicks" value? How do the Windows Power Management routines know when there was last a sign that the user is still alive? Thanks in advance to anyone who spares the time.

<code>Imports WindowsHookLib	'http://www.codeproject.com/KB/vb/WindowsHookLib.aspx?

Friend WithEvents KbHook As LLKeyboardHook

Private Declare Function OpenWindowStation Lib "user32.dll" Alias "OpenWindowStationA" (ByVal lpszWinSta As String, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Int32) As Int32

Private Declare Function OpenDesktop Lib "user32.dll" Alias "OpenDesktopA" (ByVal lpszDesktop As String, ByVal dwFlags As Int32, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Int32) As Int32

Private Declare Function SetProcessWindowStation Lib "user32.dll" (ByVal hWinSta As Int32) As Int32

Private Declare Function SetThreadDesktop Lib "user32.dll" (ByVal hDesktop As Int32) As Int32


'Start the service with a login handler
Protected Overrides Sub OnStart(ByVal args() As String)
	Dim objLog As EventLog = New EventLog("Security")
	AddHandler objLog.EntryWritten, AddressOf SecurityLog_OnEntryWritten
	objLog.EnableRaisingEvents = True
End Sub 'OnStart


Private Sub SecurityLog_OnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs)

	'Only want user login events
        If e.Entry.InstanceId <> 528 OrElse e.Entry.UserName.Contains("SERVICE") Then
            Return
        End If

MakeServiceInteractive()'http://www.codeguru.com/forum/showthread.php?t=238942
'Service then does other stuff on separate threads I'd like to abort when there's no active user
End Sub 'SecurityLog_OnEntryWritten


Private Sub MakeServiceInteractive() 
    Dim lngDefaultDesktop As Int32
    Dim lngWinSta0 As Int32

    lngWinSta0 = OpenWindowStation("WinSta0", False, &H37F)
    If SetProcessWindowStation(lngWinSta0) <> 0 Then 'success
          lngDefaultDesktop = OpenDesktop("Default", 0&, False, &H8L)
          If SetThreadDesktop(lngDefaultDesktop) <> 0 Then 'success
              KbHook = New LLKeyboardHook
              KbHook.InstallHook()
              WriteLog("KbHook state: " & KbHook.GetState.ToString())
		'I can step through to a log entry of "KbHook state: Installed" so all seems well, but handler never gets hit.
          End If
    End If
End Sub 'MakeServiceInteractive


Private Sub KbHook_KeyDown(ByVal sender As Object, ByVal e As WindowsHookLib.KeyEventArgs) Handles KbHook.KeyDown
    WriteLog(e.KeyCode.ToString & " Pressed") 'never gets called :confused:
End Sub 'KbHook_KeyDown</code>

QuestionDrag and Drop from One Treeview To Another Treeview By VB.Net 2005 Pin
ejaz_pk20-Jan-08 8:07
ejaz_pk20-Jan-08 8:07 
GeneralRe: Drag and Drop from One Treeview To Another Treeview By VB.Net 2005 Pin
Paul Conrad20-Jan-08 10:18
professionalPaul Conrad20-Jan-08 10:18 
QuestionRe: Drag and Drop from One Treeview To Another Treeview By VB.Net 2005 Pin
ejaz_pk21-Jan-08 2:35
ejaz_pk21-Jan-08 2:35 
QuestionInstance Pin
roger689720-Jan-08 6:31
roger689720-Jan-08 6:31 
GeneralRe: Instance Pin
Colin Angus Mackay20-Jan-08 10:50
Colin Angus Mackay20-Jan-08 10:50 
QuestionPocket PC Connections? Pin
Widgets20-Jan-08 2:16
Widgets20-Jan-08 2:16 
GeneralSyntax Highlighting Pin
The Mighty Atom20-Jan-08 2:03
The Mighty Atom20-Jan-08 2:03 
GeneralRe: Syntax Highlighting Pin
The ANZAC20-Jan-08 18:36
The ANZAC20-Jan-08 18:36 
GeneralRe: Syntax Highlighting Pin
The Mighty Atom21-Jan-08 2:59
The Mighty Atom21-Jan-08 2:59 
GeneralRe: Syntax Highlighting Pin
The ANZAC21-Jan-08 14:06
The ANZAC21-Jan-08 14:06 
GeneralRe: Syntax Highlighting Pin
The Mighty Atom22-Jan-08 2:04
The Mighty Atom22-Jan-08 2:04 
GeneralGetting the number of rows from a table adapter query Pin
AAGTHosting19-Jan-08 17:17
AAGTHosting19-Jan-08 17:17 
GeneralQuestion about Shared modifier Pin
Alaric_19-Jan-08 11:04
professionalAlaric_19-Jan-08 11:04 
GeneralRe: Question about Shared modifier Pin
Luc Pattyn19-Jan-08 11:51
sitebuilderLuc Pattyn19-Jan-08 11:51 
GeneralRe: Question about Shared modifier [modified] Pin
Alaric_19-Jan-08 12:39
professionalAlaric_19-Jan-08 12:39 
GeneralRe: Question about Shared modifier Pin
Guffa19-Jan-08 13:02
Guffa19-Jan-08 13:02 
GeneralRe: Question about Shared modifier Pin
pmarfleet19-Jan-08 12:00
pmarfleet19-Jan-08 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.