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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help adding copying file based on IP

Status
Not open for further replies.

Guji

MIS
Oct 27, 2009
2
ZA
Hi there,

I am fairly new to VBScripts and require some help please.

I have a script that copies users PST files from a network share to the local machine and then a batch file imports this into outlook.

THe script currently work well at head office as it is set to copy from the file server. The problem I know face is that I need to do this for remote sites. These sites have site servers on them and the plan is to dump the pst files in a share and for users to to copy this.

I would like to create a single script which will look at the IP Address of the pc, if the PC has an IP range for the Newcastle Site that user must copy their pst from the Newcastle Server and so on for the other sites.

The script currently does the following:

Option Explicit

Const PST_SOURCE = "\\10.17.0.2\EASPST\"

Const NEW_PST_FLDR = "C:\PST"

Const FOR_APPENDING = 8

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell : Set objShell = CreateObject("Wscript.Shell")
Dim objNetwork : Set objNetwork = WScript.CreateObject("WScript.Network")

Dim strUser : strUser = objNetwork.UserName
Dim strFileName : strFileName = PST_SOURCE & strUser & ".pst"
Dim strPSTDestinationPath : strPSTDestinationPath = objShell.ExpandEnvironmentStrings("C:\PST\")

Dim objLog : Set objLog = objFSO.OpenTextFile("\\10.17.0.2\Log\PST_IMPORT_" & struser & ".LOG", FOR_APPENDING, True)

If Not objFSO.FolderExists(NEW_PST_FLDR) Then
Dim objNewFolder : Set objNewFolder = objFSO.CreateFolder(NEW_PST_FLDR)
'Response.Write("A new folder has been created at: " NEW_PST_FLDR)
End If

MSGbox "Please be patient. Do not reboot or shutdown your pc. Your PST file is being copied, do not open OUTLOOK!!!!"

'Create a log header
objLog.WriteLine String(50, "*")
objLog.WriteLine "PST Import log for: " & strUser
objLog.WriteLine "Script started at: " & Now()
objLog.WriteLine String(50, "*")
objLog.WriteBlankLines(1)
If Not objFSO.FileExists(NEW_PST_FLDR & "\" & strUser & ".pst") Then
objLog.WriteLine Now() & vbTab & "Initiating file copy from " & strFileName & " to " & strPSTDestinationPath
On Error Resume Next
objFSO.CopyFile strFileName, strPSTDestinationPath
If Err.Number = 0 Then
objLog.WriteLine Now() & vbTab & "File copy operation completed successfully"
objLog.WriteLine Now() & vbTab & "Initiating " & PST_SOURCE & "script\outlookimport.bat"
objShell.run "CMD /C " & PST_SOURCE & "script\outlookimport.bat", 0, True
Else
objLog.WriteLine Now() & vbTab & "ERROR " & Err.Number & " - File Copy operation failed. " & Err.Description
End If
On Error GoTo 0
Else
objLog.WriteLine Now() & vbTab & "File already exists, operation aborted"
End If
objLog.WriteLine Now() & vbTab & WScript.ScriptFullName & " completed"
objLog.Close


If someone could help me with the IP based stuff will really appreciate it.

Thanks
 
changing ipaddress to long function below, should allow you to determine if a machines ip address within a range (i presume you dont have Active Directory sites to make use of?)

'########################################################################################
'############ change ipaddress to long ##################################################
'########################################################################################
Private Function Dot2LongIP (ByVal DottedIP)
On Error Resume Next
Dim i, pos
Dim PrevPos, num
If DottedIP = "" Then
Dot2LongIP = 0
Else
For i = 1 To 4
pos = InStr(PrevPos + 1, DottedIP, ".", 1)
If i = 4 Then
pos = Len(DottedIP) + 1
End If
num = Int(Mid(DottedIP, PrevPos + 1, pos - PrevPos - 1))
PrevPos = pos
Dot2LongIP = ((num Mod 256) * (256 ^ (4 - i))) + Dot2LongIP
Next
End If
End Function
 
mrmovie sorry to sound stupid but I dont understand what your script does.

With regards to the AD Sites, the clients IT Dept is being taken over by the Portugal office and they have messed up the sites and services.
 
mrmovie, I think I've already posted this function:
Code:
Public Function ip2num(ip)
Dim i, a, N
a = Split(ip, ".")
N = CDbl(0)
For i = 0 To UBound(a)
  N = N * 256 + a(i)
Next
ip2num = N
End Function
 
you code post looks different from mine PHV?
the code i posted was pulled from a GetRAS script which i authored about 10 years. from re-collection i do believe i googled or was pushed in right direction from posts on forums.
are you suggesting i am deliberately stealing your thunder PHV?, i merely posted the code i did not claim property rights or bragging points over it.

my aim is only to assist the poster.

Guji, the functions posted by PHV and myself convert something like 172.11.24.54 into a numeric value something like 2345896090, this would then allow a comparison along the lines of > < to determine if the ipaddress falls within some range that you define
 
are you suggesting i am deliberately stealing your thunder PHV
No, no, mrmovie ...
I just said that a conversion routine already was here:
thread329-1282015
 
beg your pardon PHV, i am a little bit sensitive at the moment, must be that time of the month
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top