Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

1 file, 85 users....

Status
Not open for further replies.

mojo1979

Technical User
Nov 17, 2003
138
US
Hi,

Basically I have one file that needs to be updated to 85 users laptops everyday. I thought about offline files etc, but is there an easier way?

Otherwise manually, its a nightmare task...

Thanks!
 
Do you want to replace the file?
would this help

Code:
On error resume Next
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const fileName = "c:\backup\ping.csv" 'Create a Path to a log file, if you do not specify a path it will create one
Dim WshShell,WshEnv

'Configures Variables
Set WshShell = CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")

SysDrive = WshEnv("SYSTEMDRIVE")
fname = "new 4.vbs"
SFile = SysDrive & "\backup\" & fname
DFile = SysDrive & "\Backup\folder\"
wscript.echo sfile
wscript.echo dfile

Set objTextFile = objFSO.OpenTextFile("c:\backup\ip.txt", 1) 'Open ip.txt for reading Ip address

'Log Success and Failure
Set fso = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(Data_Path & filename) Then
 Set f = fso.OpenTextFile(Data_Path & fileName,2, True)
Else
 Set f = fso.OpenTextFile(Data_Path & fileName,8)
End If 
'Read the IP.txt file line by line
Do Until objTextFile.AtEndOfStream
  strNextLine = objTextFile.Readline
  objDictionary.Add i, strNextLine
  i = i + 1
Loop
'Ping the IP address read from the ip.txt file
For Each objItem In objDictionary
   Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
   Set colItems = objWMIService.ExecQuery _
       ("Select * from Win32_PingStatus " & _
       "Where Address = '" & objDictionary(objItem) & "'")
'If a computer is found do somthing and log the IP address to the logfile success or failure
   For Each ipItem In colItems
       If ipItem.StatusCode = 0 Then
           'WScript.Echo objDictionary(objItem) & " responded."
		   f.WriteLine VbCrLf & objDictionary(objItem) & " responded."
		   objfso.CopyFile SFile, DFile, overwrite = TRUE		   
       Else
           'WScript.Echo objDictionary(objItem) & " did not respond."
		    f.WriteLine VbCrLf & objDictionary(objItem) &" did not respond."
       End If
   Next
Next

objTextFile.Close
objDictionary.RemoveAll


 
where would you publish this script?
The file would need to be replaced with the updated version.

Thanks
 
If this file is to be updated on user's machines you have a couple of avenues;

1. Copy the file to the user's laptop through a logon script
2. Have you considered e-mailing the file to users who are remote and not logging on.

More information regarding the file would be helpful
 
You can add if file exists yourfile delete file

e.g

pathstring = sysDrive & "\name.txt"
'if the file is older than 2 days
daysBack = 2

Set file = fso.GetFile(pathstring)
If DateValue(file.datelastModified) < DateValue(Now - daysBack) Then
fso.DeleteFile file.Path
End If
 
here we go

Code:
On error resume Next
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const fileName = "c:\backup\ping.csv" 'Create a Path to a log file, if you do not specify a path it will create one
Dim WshShell,WshEnv

'Configures Variables
Set WshShell = CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
SysDrive = WshEnv("SYSTEMDRIVE")
Set objTextFile = objFSO.OpenTextFile("c:\backup\ip.txt", 1) 'Open ip.txt for reading Ip address
fname = "new 4.vbs"
SFile = SysDrive & "\backup\" & fname
DFile = SysDrive & "\Backup\folder\"

'Delete The file
path = SysDrive & "\backup\folder\" & fname

Set file = objFSO.GetFile(path)
If objFSO.FileExists(path) Then
	objFSO.DeleteFile file.Path
End if
'Wait 5 seconds
wscript.sleep 5000

'Log Success and Failure
Set fso = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(Data_Path & filename) Then
 Set f = fso.OpenTextFile(Data_Path & fileName,2, True)
Else
 Set f = fso.OpenTextFile(Data_Path & fileName,8)
End If 
'Read the IP.txt file line by line
Do Until objTextFile.AtEndOfStream
  strNextLine = objTextFile.Readline
  objDictionary.Add i, strNextLine
  i = i + 1
Loop
'Ping the IP address read from the ip.txt file
For Each objItem In objDictionary
   Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
   Set colItems = objWMIService.ExecQuery _
       ("Select * from Win32_PingStatus " & _
       "Where Address = '" & objDictionary(objItem) & "'")
'If a computer is found do somthing and log the IP address to the logfile success or failure
   For Each ipItem In colItems
       If ipItem.StatusCode = 0 Then
           'WScript.Echo objDictionary(objItem) & " responded."
		   f.WriteLine VbCrLf & objDictionary(objItem) & " responded."   
		   objfso.CopyFile SFile, DFile, overwrite = TRUE		   
       Else
           'WScript.Echo objDictionary(objItem) & " did not respond."
		    f.WriteLine VbCrLf & objDictionary(objItem) &" did not respond."
       End If
	 
   Next
Next

objTextFile.Close
objDictionary.RemoveAll
 
It will be an excel spreadsheet, not a large file...

I would paste the above into my batch file?
 
forgot you will need to add this
strComputer = "."

e.g.
Dim WshShell,WshEnv
strComputer = ".
 
Try this as a login script.

Code:
On error resume Next
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'Create a Path to a log file
Const fileName = "c:\backup\log.txt"
 
Dim WshShell,WshEnv
Dim wshNetwork:Set WshNetwork = CreateObject("WScript.Network")

Dim objDomain:Set objDomain = getObject("LDAP://rootDse")
Dim DomainString:DomainString = objDomain.Get("dnsHostName")

dim UserString:UserString = WshNetwork.UserName
Dim objADSysInfo:Set objADSysInfo = CreateObject("ADSystemInfo")
strComputer = WshNetwork.ComputerName


'Configures Variables
Set WshShell = CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
Set objFSO = CreateObject("Scripting.FileSystemObject")
SysDrive = WshEnv("SYSTEMDRIVE")
strComputer "."
fname = "new 4.vbs"
SFile = SysDrive & "\backup\" & fname
DFile = SysDrive & "\Backup\folder\"

'Delete The file
path = SysDrive & "\backup\folder\" & fname

Set file = objFSO.GetFile(path)
If objFSO.FileExists(path) Then
	objFSO.DeleteFile file.Path
End if
'Wait 5 seconds
wscript.sleep 5000

'Log Success and Failure
	Set fso = CreateObject("Scripting.FileSystemObject")
	If Not FSO.FileExists(Data_Path & filename) Then
	 Set f = fso.OpenTextFile(Data_Path & fileName,2, True)
	Else
	 Set f = fso.OpenTextFile(Data_Path & fileName,8)
	End If 

	If strComputer = "" Then
	 f.WriteLine VbCrLf & strComputer &" did not respond."
    Else
     f.WriteLine VbCrLf & strcomputer & " responded."   
	 objfso.CopyFile SFile, DFile, overwrite = TRUE
    End If
 
So in this vb script, my file would replace which parts in the script? i.e. my file name is update.xls found in the location \\dxbserver2\update

Thanks again
 
download Notepad++ if will help you read the file better once saved as a vbs

I have added some comments to the parts you will need to change, you could also change the log file path.

Code:
strComputer "."
'Your file name
fname = "update.xls"
'Source file location
SFile = SysDrive & "\\dxbserver2\update\" & fname
'Destination Location
DFile = SysDrive & "\Backup\folder\"
 
so the destination location, if I want the file to be saved to each users desktop, would look like this?

DFile = SysDrive & "\dxbserver1\$username$\desktop\"

(the desktop redirects to a location of the server btw)
 
Run this

Code:
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
Set objFSO = CreateObject("Scripting.FileSystemObject")
SysDrive = WshEnv("SYSTEMDRIVE")
strUserName = objNetwork.UserName
Dfile = sysDrive & "\Documents and Settings\" & strUserName & "\Desktop" 
MsgBox Dfile & vbcrlf & "=" & vbcrlf & "DESTINATION_FOLDER"
MsgBox strUserName & vbcrlf & vbcrlf & "This is strUserName"
MsgBox WshShell.SpecialFolders("Desktop") & vbcrlf & vbcrlf & "Users Desktop"
so you will use something like below.

Code:
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
Set objFSO = CreateObject("Scripting.FileSystemObject")
SysDrive = WshEnv("SYSTEMDRIVE")
strUserName = objNetwork.UserName


UserDesktop = WshShell.SpecialFolders("Desktop")
Dfile = UserDesktop
wscript.echo dfile
 
I see I had the username already UserString = WshNetwork.UserName

delete this line strUserName = objNetwork.UserName
 
Sorry, you lost me. I'm only running the script shown in your last post?

Or the original you gave, but with the parts above added/modified to it?

Thanks!
 
try this

Code:
On error resume Next
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'Create a Path to a log file
Const fileName = "c:\backup\log.txt"
 
Dim WshShell,WshEnv
Dim WshNetwork:Set WshNetwork = CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
Set objFSO = CreateObject("Scripting.FileSystemObject")
SysDrive = WshEnv("SYSTEMDRIVE")

Dim objDomain:Set objDomain = getObject("LDAP://rootDse")
Dim DomainString:DomainString = objDomain.Get("dnsHostName")

Dim UserString:UserString = WshNetwork.UserName
Dim objADSysInfo:Set objADSysInfo = CreateObject("ADSystemInfo")
strComputer = WshNetwork.ComputerName

strComputer "."
UserDesktop = WshShell.SpecialFolders("Desktop")

'Your file name
fname = "update.xls"
'Source file location
SFile = SysDrive & "\\dxbserver2\update\" & fname
'Destination Location
Dfile = UserDesktop


'Delete The file
path = UserDesktop & "\" & fname

Set file = objFSO.GetFile(path)
If objFSO.FileExists(path) Then
    objFSO.DeleteFile file.Path
End if
'Wait 5 seconds
wscript.sleep 5000

'Log Success and Failure
    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not FSO.FileExists(Data_Path & filename) Then
     Set f = fso.OpenTextFile(Data_Path & fileName,2, True)
    Else
     Set f = fso.OpenTextFile(Data_Path & fileName,8)
    End If

    If strComputer = "" Then
     f.WriteLine VbCrLf & strComputer &" did not respond."
    Else
     f.WriteLine VbCrLf & strcomputer & " responded."   
     objfso.CopyFile SFile, DFile, overwrite = TRUE
    End If
 
Ok thanks.

Next step then is seeing why it doesn't work...how can i see what stage is failing?
 
Comment out On error resume next e.g 'On error resume next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top