Results 1 to 8 of 8

Thread: NT Services

  1. #1

    Thread Starter
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016

    NT Services

    Is there an API I can use that will return a list of services currently running on a given NT server? There has to be someway to do this.

    Chris
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  2. #2
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534
    Hi,

    i dont know whether we have an API for this , but you can go ahead with "net start" command on the prompt.. If you want to use it in your application.. then i suggest you to use this command as a create process and use a pipe to redirect it into your application... If you want the code i will develope it by today evening IST..

    Pradeep
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  3. #3
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Here is the code

    add this in your form
    create a multi line text box name it as status
    create a button with name start

    Private Sub Cancle_Click()
    Unload Me
    End Sub

    Private Sub start_Click()
    Dim str As String

    str = "net start"

    status = ExecCmdPipe(str)

    End Sub

    Private Sub status_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF5 Then status = ""
    End Sub


    Here goes your code for the module.bas file..

    Public Declare Function CreatePipe Lib "kernel32" ( _
    phReadPipe As Long, _
    phWritePipe As Long, _
    lpPipeAttributes As Any, _
    ByVal nSize As Long) As Long

    Public Declare Function ReadFile Lib "kernel32" ( _
    ByVal hFile As Long, _
    ByVal lpBuffer As String, _
    ByVal nNumberOfBytesToRead As Long, _
    lpNumberOfBytesRead As Long, _
    ByVal lpOverlapped As Any) As Long

    Public Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
    End Type

    Public Type STARTUPINFO
    cb As Long
    lpReserved As Long
    lpDesktop As Long
    lpTitle As Long
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
    End Type

    Public Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadID As Long
    End Type

    Public Declare Function CreateProcessA Lib "kernel32" (ByVal _
    lpApplicationName As Long, ByVal lpCommandLine As String, _
    lpProcessAttributes As Any, lpThreadAttributes As Any, _
    ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
    lpStartupInfo As Any, lpProcessInformation As Any) As Long

    Public Declare Function WaitForSingleObject Lib "kernel32" _
    (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

    Public Declare Function CloseHandle Lib "kernel32" (ByVal _
    hObject As Long) As Long

    Public Const SW_HIDE = 0
    Const SW_SHOWMINNOACTIVE = 7
    Const STARTF_USESHOWWINDOW = &H1
    Const INFINITE = -1&
    Public Const NORMAL_PRIORITY_CLASS = &H20&
    Public Const STARTF_USESTDHANDLES = &H100&

    Public Function ExecCmdPipe(ByVal CmdLine As String) As String

    Dim proc As PROCESS_INFORMATION, ret As Long, bSuccess As Long
    Dim start As STARTUPINFO
    Dim sa As SECURITY_ATTRIBUTES
    Dim hReadPipe As Long, hWritePipe As Long
    Dim bytesread As Long, mybuff As String
    Dim i As Integer

    Dim sReturnStr As String

    mybuff = String(10 * 1024, Chr$(65))
    sa.nLength = Len(sa)
    sa.bInheritHandle = 1&
    sa.lpSecurityDescriptor = 0&
    ret = CreatePipe(hReadPipe, hWritePipe, sa, 0)
    If ret = 0 Then
    execcmd = "Error: CreatePipe failed. " & Err.LastDllError
    Exit Function
    End If
    start.cb = Len(start)
    start.hStdOutput = hWritePipe
    start.dwFlags = STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW
    start.wShowWindow = SW_HIDE


    ret& = CreateProcessA(0&, CmdLine$, sa, sa, 1&, _
    NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
    If ret <> 1 Then
    sReturnStr = "Error: CreateProcess failed. " & Err.LastDllError
    End If

    ret = WaitForSingleObject(proc.hProcess, INFINITE)

    bSuccess = ReadFile(hReadPipe, mybuff, Len(mybuff), bytesread, 0&)
    If bSuccess = 1 Then
    sReturnStr = Left(mybuff, bytesread)
    Else

    sReturnStr = "Error: ReadFile failed. " & Err.LastDllError
    End If
    ret = CloseHandle(proc.hProcess)
    ret = CloseHandle(proc.hThread)
    ret = CloseHandle(hReadPipe)
    ret = CloseHandle(hWritePipe)

    ExecCmdPipe = sReturnStr
    End Function




    Tell me if you have any doubts....


    Regards,
    Pradeep
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  4. #4
    TheSarlacc
    Guest
    will this code redirect ANY dos command into ur app? or is it only for "net start" ? and will it work on any 95/98, or only NT?

  5. #5

    Thread Starter
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    pradeepkrao,

    Thanks for the code...

    I did find an example using the EnumServicesStatus API that returns the running services on a machine. If you're interested go to this link: http://support.microsoft.com/support.../q183/4/78.asp

    I use another API to scan the network for all of the NT servers, NT workstations, and Windows 2000 desktops, then run the Services API to find out what these machines are running. If "net start" can be used to retrieve the services of remote machines, I am more than interested in knowing how. Please let me know if it is possible.

    Thanks again,

    Chris
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  6. #6
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    hi

    Chris,

    I dont think net start will by some means give a remort machines services... well i think there is some api's which can give you the processes on a remort machine in your network. You can also kill the process running on the remort machine... i will catch you later...

    Pradeep
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  7. #7
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    I am attaching a good set of malacious tools try it
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  8. #8
    TheSarlacc
    Guest

    take a look at this site

    some nitfy NT tools can be found here! just what ur lookin for...

    www.sysinternals.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width