Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application to collect computer name

Status
Not open for further replies.

guitardave78

Programmer
Sep 5, 2001
1,294
GB
Hi there. I work at a college and am writing an app to monitor and capture student usage of computers.
The app works fine, all it does is capture the username the computer name and the date.
It sends this to a database and then the teacher can view a web page that will show the picture of the user and allow them to send a message or boot the student.

What I want is a way of programatically hiding the app.

I have been looking into running the app as a service. Is that possible as I have forms that will pop up to display certain messages from the teacher and also it is polling to a database every 30 seconds.


Cheers


}...the bane of my life!
 
Gotta love allapi.net!

The code snip below is pretty self-explainatory, however, I'd to some research into Services before implementing it. It works differently depending on the flavour of Windows you're running. Also, from a VB point of view, I believe you can't actually comiple and run a "true" Service - Though I'd very much like to be proved wrong on that one!

Code:
Const RSP_SIMPLE_SERVICE = 1
Const RSP_UNREGISTER_SERVICE = 0
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Public Sub MakeMeService()
    Dim pid As Long, reserv As Long
    'Get the current process ID
    pid = GetCurrentProcessId()
    'Register as service
    regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
End Sub
Public Sub UnMakeMeService()
    Dim pid As Long, reserv As Long
    'Get the current process ID
    pid = GetCurrentProcessId()
    'Unregister as service
    regserv = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
End Sub
Private Sub Form_Load()
    'KPD-Team 1999
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    MakeMeService
    'Right now, you're program is hidden from the CTRL-ALT-DEL-list
End Sub
Private Sub Form_Unload(Cancel As Integer)
    UnMakeMeService
End Sub
 
But i need this to work for NT based machines.
Also I can make the service, i need to know how only run a funciton in the service after someone has logged in

}...the bane of my life!
 
Then I think you're going have to learn C/C++ or a variant. AFAIK, the VB compiler can not compile service executables.

I'd be glad to be proved wrong though.
 
Well, talk about learning something new every day! That page could have saved me AGES of mucking about a couple of years ago! However, I'm confused. Surely all the information you need is on that link? When you say "programatically hiding the app" ... from what? The Services List? Processes List? Could you expand a little more?
 
The more important par tof the question was about collection the username etc only once there has been a log in as the service runs before anyone logs in :)

}...the bane of my life!
 
Well, I can't understand that. Is your app having to do something else before login?

Surely it would be easier to launch "normally" at startup and grab the username then rather than polling the system...

Anyway, see if the snippet below helps. KPD Team rocks...

Code:
Private Enum EXTENDED_NAME_FORMAT
    NameUnknown = 0
    NameFullyQualifiedDN = 1
    NameSamCompatible = 2
    NameDisplay = 3
    NameUniqueId = 6
    NameCanonical = 7
    NameUserPrincipal = 8
    NameCanonicalEx = 9
    NameServicePrincipal = 10
End Enum
Private Declare Function GetUserNameEx Lib "secur32.dll" Alias "GetUserNameExA" (ByVal NameFormat As EXTENDED_NAME_FORMAT, ByVal lpNameBuffer As String, ByRef nSize As Long) As Long
Private Sub Form_Load()
    'KPD-Team 2001
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@allapi.net
    Dim sBuffer As String, Ret As Long
    sBuffer = String(256, 0)
    Ret = Len(sBuffer)
    If GetUserNameEx(NameSamCompatible, sBuffer, Ret) <> 0 Then
        MsgBox "Username: " + Left$(sBuffer, Ret)
    Else
        MsgBox "Error while retrieving the username"
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top