Results 1 to 7 of 7

Thread: Dead easy 'loop' question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66
    (well if it's so easy, why can't I do it then!)


    I have a list of machine names in a text file. Eg:

    machine1
    machine2
    machine3
    etc

    I need to be able to call each machine name in turn and insert it in the .sendto line below.

    Any ideas?

    Simon

    With mNetSend
    .Message = "Shutting down in 5 mins"
    .SendTo = "machine1"
    .NetSendMessage
    End With

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    1. Load the text into a big string (Open, Get, Close)
    2. Use the Split() function to cut it into an array
    If you only have vb5 you can get a good version of split() by searching this forum, I've seen it quite a few times
    3. loop the net send through the loop

    ta daa !

    tell me if you need me to be more specific
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  3. #3
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    I believe you are looking for something like this.

    Code:
      Dim str_Data As String
      Open "C:\TestFile.Txt" For Input As #1
      
      Do While Not EOF(1)
    
        Input #1, str_Data
        
        With mNetSend
          .Message = "Shutting down in 5 mins"
          .SendTo = Trim(str_Data)
          .NetSendMessage
        End With
    
        Doevents
      Loop
      Close #1

    I think I know what you are doing. Are you trying to send messages across the network using Net Send?

    If that is the case, there is an easier way to this. Your method only sends the message to one person at a time. If you are interest, I can show you how to send it as a batch file, so that everyone pretty much gets the message at the same time. I did it with about 20 lines of code in Excel VBA.

    Good Night...
    Chemically Formulated As:
    Dr. Nitro

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66
    That's exactly what I'm trying to do Nitro!

    I would appreciate that code if you have it available.

    Simon

  5. #5
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Hello Simon!

    I will post search and post that code up in about 2.5 hours. I have to attend a meeting right now.

    As I said before, it is in Excel VBA and I don't mind converting it to Visual Basic 6.0 codes for you. Also keep in mind, I am using Net View to send the results of every computer to a file and run Net Send against the file.

    See you in about 2.5 hours.
    Chemically Formulated As:
    Dr. Nitro

  6. #6
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    Sorry, I forgot all about you. I am back now.

    You might have to tweak the code around to customize to your network. This is the basic idea. Just paste it into an Excel module and do a step through.

    Code:
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Const INFINITE = -1&
    Private Const SYNCHRONIZE = &H100000
    
    Sub Macro1()
    '  Application.Run Macro:="ATTMACRO"
      Application.DisplayAlerts = False
      
      Dim lngShell As Long
      Dim ret As Long
      Dim pHandle As Long
      
      lngShell = Shell(Environ("COMSPEC") & " /C Net View > " & """" & "C:\People.txt" & """", vbNormalFocus)
      pHandle = OpenProcess(SYNCHRONIZE, False, lngShell)
      ret = WaitForSingleObject(pHandle, INFINITE)
      ret = CloseHandle(pHandle)
    
      
     'PURPOSE:Open the file People.txt and manipulate the data
      Workbooks.OpenText FileName:="C:\People.txt", Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth
      Rows("1:4").Delete
      Columns("B:B").Delete Shift:=xlToLeft
      Do Until Left(ActiveCell.Value, 2) <> "\\"
        ActiveCell.Offset(0, 1).Value = "Net Send " & Mid(ActiveCell.Value, 3) & " """ & "Howdy!" & """"
        ActiveCell.Offset(1, 0).Select
      Loop
      Columns("A:A").Delete Shift:=xlToLeft
      
     'PURPOSE:Write the data from People.txt out to Send.bat
      Range("A1").Select
      Open "C:\Send.Bat" For Output As #1
      Do Until ActiveCell.Value = ""
        Print #1, ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
      Loop
      Close #1
      
      Call Shell("C:\Send.Bat", vbHide)
      
      Application.Quit
    End Sub

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66
    Thanks Nitro - I'll have a play now!

    Cheers

    Simon

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