Solved

How to get System Names which are connected in Network?

Posted on 2001-08-07
11
224 Views
Last Modified: 2012-06-21
Dear Friends,
  How to get the system Names which are connected in network using API and How to Shut down the system from Remote.
Thanks In advance
0
Comment
Question by:N_K_venkat
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 1

Accepted Solution

by:
sdm395 earned 50 total points
Comment Utility
shutgui.exe
shutdown.exe

Both on the WinNt Resource Kit.  Shutdown.exe is a command line utility (you must have admin rights) which you could shell out to....


also this from vbnet - enumerates machines on the network

'--------------------------------------------------------------
' Copyright ?1996-2001 VBnet, Randy Birch, All Rights Reserved.
' Terms of use http://www.mvps.org/vbnet/terms/pages/terms.htm
'--------------------------------------------------------------


'Windows type used to call the Net API
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&

Private Const SV_TYPE_WORKSTATION         As Long = &H1
Private Const SV_TYPE_SERVER              As Long = &H2
Private Const SV_TYPE_SQLSERVER           As Long = &H4
Private Const SV_TYPE_DOMAIN_CTRL         As Long = &H8
Private Const SV_TYPE_DOMAIN_BAKCTRL      As Long = &H10
Private Const SV_TYPE_TIME_SOURCE         As Long = &H20
Private Const SV_TYPE_AFP                 As Long = &H40
Private Const SV_TYPE_NOVELL              As Long = &H80
Private Const SV_TYPE_DOMAIN_MEMBER       As Long = &H100
Private Const SV_TYPE_PRINTQ_SERVER       As Long = &H200
Private Const SV_TYPE_DIALIN_SERVER       As Long = &H400
Private Const SV_TYPE_XENIX_SERVER        As Long = &H800
Private Const SV_TYPE_SERVER_UNIX         As Long = SV_TYPE_XENIX_SERVER
Private Const SV_TYPE_NT                  As Long = &H1000
Private Const SV_TYPE_WFW                 As Long = &H2000
Private Const SV_TYPE_SERVER_MFPN         As Long = &H4000
Private Const SV_TYPE_SERVER_NT           As Long = &H8000
Private Const SV_TYPE_POTENTIAL_BROWSER   As Long = &H10000
Private Const SV_TYPE_BACKUP_BROWSER      As Long = &H20000
Private Const SV_TYPE_MASTER_BROWSER      As Long = &H40000
Private Const SV_TYPE_DOMAIN_MASTER       As Long = &H80000
Private Const SV_TYPE_SERVER_OSF          As Long = &H100000
Private Const SV_TYPE_SERVER_VMS          As Long = &H200000
Private Const SV_TYPE_WINDOWS             As Long = &H400000  'Windows95 and above
Private Const SV_TYPE_DFS                 As Long = &H800000  'Root of a DFS tree
Private Const SV_TYPE_CLUSTER_NT          As Long = &H1000000 'NT Cluster
Private Const SV_TYPE_TERMINALSERVER      As Long = &H2000000 'Terminal Server
Private Const SV_TYPE_DCE                 As Long = &H10000000'IBM DSS
Private Const SV_TYPE_ALTERNATE_XPORT     As Long = &H20000000'rtn alternate transport
Private Const SV_TYPE_LOCAL_LIST_ONLY     As Long = &H40000000'rtn local only
Private Const SV_TYPE_DOMAIN_ENUM         As Long = &H80000000
Private Const SV_TYPE_ALL                 As Long = &HFFFFFFFF

Private Const SV_PLATFORM_ID_OS2       As Long = 400
Private Const SV_PLATFORM_ID_NT        As Long = 500

'Mask applied to svX_version_major in
'order to obtain the major version number.
Private Const MAJOR_VERSION_MASK        As Long = &HF

Private Type SERVER_INFO_100
  sv100_platform_id As Long
  sv100_name As Long
End Type

Private Declare Function NetServerEnum Lib "Netapi32" _
  (ByVal servername As Long, _
   ByVal level As Long, _
   buf As Any, _
   ByVal prefmaxlen As Long, _
   entriesread As Long, _
   totalentries As Long, _
   ByVal servertype As Long, _
   ByVal domain As Long, _
   resume_handle As Long) As Long

Private Declare Function NetApiBufferFree Lib "netapi32.dll" _
   (ByVal Buffer As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
  (pTo As Any, uFrom As Any, _
   ByVal lSize As Long)
   
Private Declare Function lstrlenW Lib "kernel32" _
  (ByVal lpString As Long) As Long  


Private Sub Form_Load()

   Command1.Caption = "Net Server Enum"

End Sub
   

Private Sub Command1_Click()

   Call GetServers(vbNullString)
 
End Sub


Private Function GetServers(sDomain As String) As Long

  'lists all servers of the specified type
  'that are visible in a domain.
 
   Dim bufptr          As Long
   Dim dwEntriesread   As Long
   Dim dwTotalentries  As Long
   Dim dwResumehandle  As Long
   Dim se100           As SERVER_INFO_100
   Dim success         As Long
   Dim nStructSize     As Long
   Dim cnt             As Long

   nStructSize = LenB(se100)
   
  'Call passing MAX_PREFERRED_LENGTH to have the
  'API allocate required memory for the return values.
  '
  'The call is enumerating all machines on the
  'network (SV_TYPE_ALL); however, by Or'ing
  'specific bit masks for defined types you can
  'customize the returned data. For example, a
  'value of 0x00000003 combines the bit masks for
  'SV_TYPE_WORKSTATION (0x00000001) and
  'SV_TYPE_SERVER (0x00000002).
  '
  'dwServerName must be Null. The level parameter
  '(100 here) specifies the data structure being
  'used (in this case a SERVER_INFO_100 structure).
  '
  'The domain member is passed as Null, indicating
  'machines on the primary domain are to be retrieved.
  'If you decide to use this member, pass
  'StrPtr("domain name"), not the string itself.
   success = NetServerEnum(0&, _
                           100, _
                           bufptr, _
                           MAX_PREFERRED_LENGTH, _
                           dwEntriesread, _
                           dwTotalentries, _
                           SV_TYPE_ALL, _
                           0&, _
                           dwResumehandle)

  'if all goes well
   If success = NERR_SUCCESS And _
      success <> ERROR_MORE_DATA Then
     
    'loop through the returned data, adding each
    'machine to the list
      For cnt = 0 To dwEntriesread - 1
         
        'get one chunk of data and cast
        'into an SERVER_INFO_100 struct
        'in order to add the name to a list
         CopyMemory se100, ByVal bufptr + (nStructSize * cnt), nStructSize
           
         List1.AddItem GetPointerToByteStringW(se100.sv100_name)
         
      Next
     
   End If
   
  'clean up regardless of success
   Call NetApiBufferFree(bufptr)
   
  'return entries as sign of success
   GetServers = dwEntriesread

End Function


Public Function GetPointerToByteStringW(ByVal dwData As Long) As String
 
   Dim tmp() As Byte
   Dim tmplen As Long
   
   If dwData <> 0 Then
   
      tmplen = lstrlenW(dwData) * 2
     
      If tmplen <> 0 Then
     
         ReDim tmp(0 To (tmplen - 1)) As Byte
         CopyMemory tmp(0), ByVal dwData, tmplen
         GetPointerToByteStringW = tmp
         
     End If
     
   End If
   
End Function

Hope this helps

0
 

Author Comment

by:N_K_venkat
Comment Utility
Dear sdm395 ,
  Hi here is my problem i am having nearly 10 machines which are in my network.I want some code to shut down all the machines in my network thru VB coding(from the server).
From the code which u gave just now i am unable to Find the machine names Under My network.if its there please post it
waiting for Ur Reply
Thanks in advance
0
 

Author Comment

by:N_K_venkat
Comment Utility
Dear sdm395 ,
  Hi here is my problem i am having nearly 10 machines which are in my network.I want some code to shut down all the machines in my network thru VB coding(from the server).
From the code which u gave just now i am unable to Find the machine names Under My network.if its there please post it
waiting for Ur Reply
Thanks in advance
0
 
LVL 1

Expert Comment

by:sdm395
Comment Utility
Add a command button (command1) and a list box (list1) to a form in a standard exe.  Copy the code, and then run it - when you click the button you should get a list of the machines on your network.  

If you do, then you can replace the

 List1.AddItem GetPointerToByteStringW(se100.sv100_name)

line and replace it with a shell to the shutdown.exe
(I can't remember the switches you need)

Otherwise let me know what you get.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Listening...
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Expert Comment

by:mike1234
Comment Utility
To enumerate network resources you can use WNet for VB from www.snark-soft.com

To shutdown remote machine you can use WinAPI. However the remote shutdown doesn't work always -- you can find the descriptions of known problems in MSDN.

The best way to guarantee the remote shutdown is to lunch a service on remote mashine which will perform shutdown locally. However it requires much more code...
0
 

Author Comment

by:N_K_venkat
Comment Utility
Dear mike1234 ,
  where from U?and where are Working ?In that snark soft???
0
 

Expert Comment

by:mike1234
Comment Utility
Dear N K venkat,
I'm from Russia, I'm not working for that company.
0
 

Author Comment

by:N_K_venkat
Comment Utility
Dear mike1234 ,
i am from India.How is the market there?if u dont mind please give me ur personal id
Bye from
N.K.venkat
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Hi _K_venkat, any progress on this?
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20106428.html
http://www.experts-exchange.com/questions/Q.20162135.html
http://www.experts-exchange.com/questions/Q.20164399.html
http://www.experts-exchange.com/questions/Q.20165106.html
http://www.experts-exchange.com/questions/Q.20193420.html
http://www.experts-exchange.com/questions/Q.20262325.html
http://www.experts-exchange.com/questions/Q.20267916.html
http://www.experts-exchange.com/questions/Q.20281031.html
http://www.experts-exchange.com/questions/Q.20285275.html
http://www.experts-exchange.com/questions/Q.20291239.html
http://www.experts-exchange.com/questions/Q.20292191.html
http://www.experts-exchange.com/questions/Q.20292203.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now