VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Copy specified file to terminals of a workgroup

by H W Samuel (4 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 10th July 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Copy specified file to terminals of a workgroup

API Declarations


'This is a simple logic program that tries to copy a file onto terminals on a workgroup.
'It utilizes a simple flaw in terminal naming in my part of the world
'that gives a general name to each terminal followed by an incremental number
'e.g.USER1, USER2, etc.
'It is assumed that all computers in the workgroup will have the same operating system
'All this won't work if file sharing is disabled on the destination computers

'You will need to paste these codes into a module, and then call the SPREAD_POX from an activation point
'e.g.Form_Load, CommandButton1_Click,etc.
'-----------------------------------------------------------------------------------------------------
Option Explicit
'I got this function from the API-Guide on www.allapi.net
'This function gets the name of the computer on which this code is running
Private Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, ByRef nSize As Long) As Long
Private Const MAX_COMPUTERNAME_LENGTH As Long = 31


Rate Copy specified file to terminals of a workgroup



Public Sub SPREAD_POX _
(stFileName As String, _
iTerminalNum As Integer)

Dim Counter As Integer
Dim stDestiny As String
Dim stSource As String
Dim stComputer As String
Dim FileSysObj, FileObj

    Set FileSysObj = CreateObject("Scripting.FileSystemObject")
    Set FileObj = FileSysObj.GetSpecialFolder(2)
        
    stSource = FileObj & "\" & stFileName
    
    On Error Resume Next    'If an error occurs, just ignore it
    For Counter = 1 To iTerminalNum
        'Try getting naming conventions of terminals
        stComputer = GET_COMPUTER_NAME & Counter
        stDestiny = "\\" & stComputer & "\" & stSource 'e.g.\\USER1\C:        'Copy file into temporary folders of host computers
        FileSysObj.CopyFile stSource, stDestiny, True
    Next Counter
    On Error GoTo 0
End Sub

'This function gets the host computer's name and truncates numerals from it
Function GET_COMPUTER_NAME() As String
Dim dwLen As Long
Dim strString As String
Dim stTemp As Variant
Dim Counter As Integer

    dwLen = MAX_COMPUTERNAME_LENGTH + 1
    strString = String(dwLen, "X")
    GetComputerName strString, dwLen
    strString = Left(strString, dwLen)
    
    Counter = 0
    Do
        Counter = Counter + 1
        stTemp = Mid(strString, Counter, 1)
        If IsNumeric(stTemp) Then Exit Do
    Loop Until Counter > Len(strString)
    
    GET_COMPUTER_NAME = Left$(strString, Counter - 1)
End Function



Download this snippet    Add to My Saved Code

Copy specified file to terminals of a workgroup Comments

No comments have been posted about Copy specified file to terminals of a workgroup. Why not be the first to post a comment about Copy specified file to terminals of a workgroup.

Post your comment

Subject:
Message:
0/1000 characters