|
-
Sep 26th, 2001, 03:10 PM
#1
Thread Starter
Fanatic Member
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
-
Sep 28th, 2001, 12:43 AM
#2
Fanatic Member
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
-
Sep 28th, 2001, 01:33 AM
#3
Fanatic Member
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
-
Sep 28th, 2001, 05:50 AM
#4
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?
-
Sep 28th, 2001, 06:16 AM
#5
Thread Starter
Fanatic Member
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
-
Sep 28th, 2001, 07:00 AM
#6
Fanatic Member
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
-
Sep 28th, 2001, 07:20 AM
#7
Fanatic Member
Hi
I am attaching a good set of malacious tools try it
-
Sep 28th, 2001, 11:50 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|