How can I interpret this VB6 code? - vb6

I inherited a VB program that prints shipping labels. We need to update the barcode that gets printed and I'm trying to understand what the existing program is doing. There is a bunch of "WrittenData" (stored as "s") that seems to contain the Postscript code to produce the labels, but I haven't found anywhere that specifies the meaning of half this stuff.
Public Function PostScriptItem(address As Variant, Optional intPageNumberOut As Integer = 1, Optional intPageNumberIn As Integer = 2) As String
' 0 - MatchUpId
' 1 - Our Barcode
' 2 - Outgoing PostNet Code
' 3 - Outgoing Line 1
' 4 - Outgoing Line 2 (optionally EMPTY)
' 5 - Outgoing Line 3
' 6 - Outgoing Line 4
' 7 - Outgoing PlaNET Code
' 8 - Incoming PostNet Code
' 9 - Incoming Line 1
'10 - Incoming Line 2 (optionally EMPTY)
'11 - Incoming Line 3
'12 - Incoming Line 4
'13 - Incoming PlaNET Code
'14 - Title Id
'Escape Parenthesis and Backslashes
Dim tPos As Integer
For tPos = 0 To 14 Step 1
address(tPos) = Replace(address(tPos), "\", "\\")
address(tPos) = Replace(address(tPos), "(", "\(")
address(tPos) = Replace(address(tPos), ")", "\)")
Next tPos
Dim s As String
Dim pos As Integer
Dim fsize As Integer
Dim strBarcodeCaption As String
strBarcodeCaption = address(1) & " " & address(14) & " " & address(0)
pos = 50
fsize = 12
s = s & "%%Page: " & CStr(intPageNumberOut) & " " & CStr(intPageNumberOut) & vbCrLf & _
"<< /Duplex true >> setpagedevice" & vbCrLf & _
"<< /Tumble true >> setpagedevice" & vbCrLf & _
"%%BeginPageSetup" & vbCrLf & _
"180 rotate" & vbCrLf & _
"/pagelevel save def" & vbCrLf & _
"%%EndPageSetup" & vbCrLf & _
"newpath" & vbCrLf & _
"-338 -205 translate" & vbCrLf & _
"/Courier-Bold findfont 6 scalefont setfont" & vbCrLf & _
"newpath" & vbCrLf
s = s & "32 104 moveto (" & strBarcodeCaption & ") show" & vbCrLf & _
"newpath" & vbCrLf
s = s & "12 -450 translate" & vbCrLf & _
"62 104 moveto (" & strBarcodeCaption & ") show" & vbCrLf & _
"newpath" & vbCrLf & _
"30 80 moveto (^104" & address(1) & ") (height=0.3) code128 barcode" & vbCrLf & _
"newpath" & vbCrLf
s = s & "/Helvetica findfont 11 scalefont setfont" & vbCrLf & _
"0 " & CStr(pos) & " moveto (" & address(3) & ") show" & vbCrLf & _
"newpath" & vbCrLf
pos = pos - fsize
If address(4) <> Empty Then
s = s & "0 " & CStr(pos) & " moveto (" & address(4) & ") show" & vbCrLf & _
"newpath" & vbCrLf
pos = pos - fsize
End If
s = s & "0 " & CStr(pos) & " moveto (" & address(5) & ") show" & vbCrLf & _
"newpath" & vbCrLf
pos = pos - fsize
s = s & "0 " & CStr(pos) & " moveto (" & address(6) & ") show" & vbCrLf & _
"newpath" & vbCrLf
pos = pos - fsize - 5
s = s & "1 " & CStr(pos) & " moveto (" & address(2) & ") () postnet barcode" & vbCrLf & _
"%%PageTrailer" & vbCrLf & _
"pagelevel restore" & vbCrLf & _
"showpage" & vbCrLf
s = s & "%%Page: " & CStr(intPageNumberIn) & " " & CStr(intPageNumberIn) & vbCrLf & _
"<< /Duplex true >> setpagedevice" & vbCrLf & _
"<< /Tumble true >> setpagedevice" & vbCrLf & _
"%%BeginPageSetup" & vbCrLf & _
"/pagelevel save def" & vbCrLf & _
"210 711 translate" & vbCrLf & _
"%%EndPageSetup" & vbCrLf & _
"newpath" & vbCrLf & _
"/Courier-Bold findfont 6 scalefont setfont" & vbCrLf & _
"0 21 moveto (" & address(1) & " " & address(0) & ") show" & vbCrLf & _
"gsave" & vbCrLf & _
"0.5 0.5 scale" & vbCrLf & _
"0 12 moveto (^104" & address(1) & ") (height=0.3) code128 barcode" & vbCrLf & _
"grestore" & vbCrLf & _
"newpath" & vbCrLf & _
"32 0 moveto (" & address(14) & ") show" & vbCrLf & _
"newpath" & vbCrLf & _
"/Helvetica findfont 11 scalefont setfont" & vbCrLf & _
"-70 -180 translate" & vbCrLf
pos = 56
s = s & "0 " & CStr(pos) & " moveto (" & address(9) & ") show" & vbCrLf & _
"newpath" & vbCrLf
pos = pos - fsize
If address(10) <> Empty Then
s = s & "0 " & CStr(pos) & " moveto (" & address(10) & ") show" & vbCrLf & _
"newpath" & vbCrLf
pos = pos - fsize
End If
s = s & "0 " & CStr(pos) & " moveto (" & address(11) & ") show" & vbCrLf & _
"newpath" & vbCrLf
pos = pos - fsize
s = s & "0 " & CStr(pos) & " moveto (" & address(12) & ") show" & vbCrLf & _
"newpath" & vbCrLf
pos = pos - fsize - 5
s = s & "1 " & CStr(pos) & " moveto (" & address(8) & ") () postnet barcode" & vbCrLf & _
"%%PageTrailer" & vbCrLf & _
"pagelevel restore" & vbCrLf & _
"showpage" & vbCrLf
PostScriptItem = s
End Function
I need to change the contents of "address(2)" and "address(8)" and use a different font to print those. I tried putting the new font in the projects fonts folder and referencing it the way "postnet" and "code128" are referenced but that left me with an entirely blank label.
The "code128" font seems to get defined in a separate file called "postscript_main.ps" and I have no idea how to incorporate the new font into that, I am really lost and hoping for a clue or a link to some documentation that might get me going in the right direction.

Related

vbscript not accessing outlook 2013/2016 subfolder off the inbox using redemption

I am running the below vbscript on outlook 2013/2016 and having issues trying to read emails in sub folders off the Inbox. I can read the Inbox emails. . Can anyone point me in the right directions?
thanks in advance.
Function CheckMail(strMailBox,strFolder,strFolderAbbr,strDetails)
'
olFolderInbox = 6
set Session = CreateObject("Redemption.RDOSession")
'
Set objOutlook = CreateObject("Outlook.Application")
Session.MAPIOBJECT = objOutlook.Session.MAPIOBJECT
set Store = Session.Stores.GetSharedMailbox(strMailBox)
set Inbox = Store.GetDefaultFolder(olFolderInbox)
'
Wscript.Echo "MailBox: " & Store.Name & " - " & Inbox.Name
If strFolder = "" then
set SubFolder = Inbox
strFolderAbbr = strMailBox & " Inbox"
Else
'set SubFolder = Inbox.Folders(strFolder)
'
set SubFolder = Inbox.Folders.Item(strFolder)
'
strFolderAbbr = strMailBox & " Inbox\" & strFolder
Wscript.Echo " Sub Folder: " & SubFolder
End If
'
nItems = SubFolder.Items.Count
If nHowlong > 1 Then
nHowlong = Round((nItems/110)/60,0)
strTime = " Hour(s)!!"
Else
nHowlong = Round(nItems/110,0)
strTime = " Minute(s)!!"
End If
Wscript.Echo nItems & " - Emails in folder " & strFolderAbbr & " About " & nHowlong & strTime
'" - " & nItems
'
for each Msg in SubFolder.Items
nCounter = nCounter + 1
'Wscript.Echo "Item " & nCounter & "/" & nItems & vbCRLF & "EID: " & Msg.EntryID & vbCRLF & "ABOUT: " & Msg.Subject & vbCRLF & "FROM: " & Msg.SenderName & vbCRLF & "LEVEL: " & IIf(Msg.Importance=2,"High",IIf(Msg.Importance=1,"Normal","Low")) & vbCRLF & "Status: " & IIf(Msg.UnRead, "Not Read", "Read") & vbCRLF & "Received: " & Msg.ReceivedTime & vbCRLF & "Body: " & Msg.Body
'& nCounter & "/" & nItems & vbCRLF & "EID: " & Msg.EntryID & vbCRLF & "ABOUT: " & Msg.Subject & vbCRLF & "FROM: " & Msg.SenderName & vbCRLF & "LEVEL: " & IIf(Msg.Importance=2,"High",IIf(Msg.Importance=1,"Normal","Low")) & vbCRLF & "Status: " & IIf(Msg.UnRead, "Not Read", "Read") & vbCRLF & "Received: " & Msg.ReceivedTime & vbCRLF & "Body: " & Msg.Body
'
' process all emails in the box
strRecords = strRecords & "REG-" &strFolderAbbr & "~" & Msg.Subject & "~" & Msg.ReceivedTime & "~" & IIf(Msg.UnRead, "Not Read", "Read") & "~" & Msg.SenderName & "~" &IIf(Msg.Importance=2,"High",IIf(Msg.Importance=1,"Normal","Low")) & "*"
On Error Resume Next
err.clear
if Err Then
'WScript.Echo "ReceivedTime was null"
End If
On Error GoTo 0
next
CheckMail = strRecords
End Function
Function IIf(bClause, sTrue, sFalse)
If CBool(bClause) Then
IIf = sTrue
Else
IIf = sFalse
End If
End Function
I finally figured out the code that works. I would first like to thank Dmitry for all the help he gave me. But this was a stuburn issue. the following code solved the problem. Please dont ask me to explain it just plain ole luck and trail and error.
set Session = CreateObject("Redemption.RDOSession")
Set objOutlook = CreateObject("Outlook.Application")
Session.MAPIOBJECT = objOutlook.Session.MAPIOBJECT
'Set Root foldedr of the mail box of the stores
set IPMRoot = Session.Stores.Item(strMailBox).IPMRootFolder
'Set the subfolder to the inbox
If strFolder = "" then
set subFolder = IPMRoot.Folders("InBox")
strFolderAbbr = strMailBox & " Inbox"
Else
'Set subfolder to subfolder chosen
set subFolder = IPMRoot.Folders("InBox").Folders(strFolder)
strFolderAbbr = strMailBox & " Inbox\" & strFolder
End If
'

Read Content from Text File VBS

Hi Guys this script requires you to manually enter computer name to pull up Inventory.
If I can have all the computer's name in a text file that will be great.
I tried something like
strComputer = fso1.OpenTextFile("c:\Computers.txt",1)
But doesn't seems to work any idea?
Dim strIP, strSubnet, strDescription, lnX, strcomputer, objwmiservice, colitems, objitems
strComputer = InputBox ("Enter the Computer name to get its Inventory:-")
lnX = 1
' ********************************************************************************************
'Section to change a filename using timestamps
strPath = "C:\"
strMonth = DatePart("m", Now())
strDay = DatePart("d",Now())
if Len(strMonth) = 1 then
strMonth = "0" & strMonth
else
strMonth = strMonth
end if
if Len(strDay) = 1 then
strDay = "0" & strDay
else
strDay = strDay
end if
strFileName = DatePart("yyyy",Now()) & strMonth & strDay
strFileName = Replace(strFileName,":","")
' ********************************************************************************************
'Variable Declarations
Const ForAppending = 8
'Get CompName
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")
' ********************************************************************************************
'Get Operation System & Processor Information
' ********************************************************************************************
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
CompName = objItem.SystemName
Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.FileExists(strPath & CompName & "_" & "_Inventory.txt") then
WScript.Quit
end if
'Set the file location
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strPath & CompName & "_" & "Inventory.txt", ForAppending, True)
' ********************************************************************************************
'Print HEADER
' ********************************************************************************************
objTextFile.Write "********************************************************************************************" & VBCRLF & VBCRLF
objTextFile.Write " COMPUTER INVENTORY " & VBCRLF
objTextFile.Write " DATE: " & FormatDateTime(Now(),1) & " " & VBCRLF
objTextFile.Write " TIME: " & FormatDateTime(Now(),3) & " " & VBCRLF & VBCRLF
objTextFile.Write "******************************************************************************************** " & VBCRLF & VBCRLF
' ********************************************************************************************
'Get Processor Information
' ********************************************************************************************
objTextFile.Write "COMPUTER" & VBCRLF
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
If lnX = 1 Then
objTextFile.Write " COMPUTER NAME: " & objItem.SystemName & VBCRLF
objTextFile.Write " PROCESSOR: " & objItem.Name & vbCrLf
lnX = lnX + 1
End If
Next
' ********************************************************************************************
'Get Computer Manufacturer and RAM details
' ********************************************************************************************
Set colSystems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objSystems In colSystems
objTextFile.WriteLine " MANUFACTURER: " & objSystems.Manufacturer
objTextFile.WriteLine " MODEL: " & objSystems.Model
objTextFile.WriteLine " DOMAIN: " & objsystems.Domain
objTextFile.Write " RAM: " & Round (objSystems.TotalPhysicalMemory / 1048576, 0) & " MB "& VBCRLF
Next
' ********************************************************************************************
' Get the Serial number/ Service Tag of the system
' ********************************************************************************************
Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
objTextFile.Write " SERVICE TAG: " & objSMBIOS.SerialNumber & VBCRLF
Next
' ********************************************************************************************
'Get BIOS Information
' ********************************************************************************************
objTextFile.Write VBCRLF & "BIOS INFO" & vbCrLf
Set colBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")
For each objItem in colBIOS
objTextFile.WriteLine " BIOS MANUFACTURER: " & objItem.Manufacturer
objTextFile.WriteLine " BIOS VERSION: " & objItem.Name
Next
' ********************************************************************************************
'Get OS Information
' ********************************************************************************************
objTextFile.Write VBCRLF & "OS INFO" & vbCrLf
Set colSettings = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
objTextFile.Write " OPERATING SYSTEM: " & objOperatingSystem.Caption & " {Enter the product key}" & VBCRLF
objTextFile.Write " SERVICE PACK: " & objOperatingSystem.Caption & " Service Pack "& objOperatingSystem.ServicePackMajorVersion & "." & objOperatingSystem.ServicePackMinorVersion & VBCRLF
Next
' ********************************************************************************************
'Get Logical Disk Size and Partition Information
' ********************************************************************************************
objTextFile.Write VBCRLF & "MEMORY" & VBCRLF
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = 3")
For Each objDisk in colDisks
intFreeSpace = objDisk.FreeSpace
intTotalSpace = objDisk.Size
pctFreeSpace = intFreeSpace / intTotalSpace
objTextFile.Write objDisk.Name & "\ (" & objDisk.FileSystem & ") " & Round((objDisk.Size/1000000000),4) & " GB ("& Round((intFreeSpace/1000000000)*1.024,4) & " GB Free Space)" & VBCRLF
Next
' ********************************************************************************************
'Get NETWORK ADAPTERS information
' ********************************************************************************************
objTextFile.Write VBCRLF & "NETWORK" & VBCRLF
Set colNicConfigs = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objNicConfig In colNicConfigs
strDescription = objNicConfig.Caption
strMACAddress = objNicConfig.MACAddress
strDHCP = objNicConfig.DHCPEnabled
For Each strIPAddress In objNicConfig.IPAddress
strIP = strIPAddress 'Assign IP Address to variable
For Each strIPSubnet In objNicConfig.IPSubnet
strSubnet = strIPSubnet 'Assign Subnet to variable
Next
objTextFile.Write " NETWORK ADAPTER: " & strDescription & VBCRLF
objTextFile.Write " IP ADDRESS: " & strIP & VBCRLF
objTextFile.Write " MAC ADDRESS: " & strMACAddress & vbCrLf
objTextFile.Write " DHCP ENABLED: " & strDHCP & vbCrLf & vbCrLf
Next
Next
Set colNicConfigs = NOTHING
' ********************************************************************************************
'Get GRAPHICS ADAPTERS information
' ********************************************************************************************
objTextFile.Write VBCRLF & "GRAPHICS CARD" & VBCRLF
Set colGraphics = objWMIService.ExecQuery ("Select * from Win32_DisplayControllerConfiguration")
For Each objGraphics in colGraphics
objTextFile.WriteLine " GRAPHICS CARD: " & objGraphics.Name & VBCRLF
Next
' ********************************************************************************************
' Get the list of Installed software
' ********************************************************************************************
objTextFile.Write VBCRLF & "SOFTWARE INSTALLED" & VBCRLF
Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product")
For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.Description
Next
'Close text file after writing logs
objTextFile.Write VbCrLf
objTextFile.Close
'Clean Up
WScript.Echo "Inventory Complete "
The .OpenTextFile() call in your
strComputer = fso1.OpenTextFile("c:\Computers.txt",1)
just opens the file, but does not read the file's content that should be assigned to strComputer. So use
strComputer = fso1.OpenTextFile("c:\Computers.txt").ReadLine()

Write Double Quotation Mark

I am trying to overwrite specific lines in a sequential file
For example if file has:
"1"
"Kii"
"Kii"
"Kii"
"Kii"
"2"
"Troy Martinez"
"Edoy"
"Edoy"
"69"
"3"
"Snoop Dogg"
"Weed"
"President Troy"
"420"
And I have this code to overwrite
Private Sub OverWrite()
Dim Count As Integer
On Error GoTo ErrSub
LineCount = 1
Open App.Path & "\Data.txt" For Input As #1
Do While Not EOF(1)
If LineCount < ((IDCount - 1) * 5) + 1 Or LineCount >= (IDCount * 5) + 1 Then
For Count = 0 To 4
Input #1, TextTemp
FileText = FileText & """ & Text1(Count) & """ & vbCrLf
LineCount = LineCount + 1
Next Count
Else
For Count = 0 To 4
Input #1, TextTemp
FileText = FileText & """ & TextTemp & """ & vbCrLf
LineCount = LineCount + 1
Next Count
End If
Loop
Close
Open App.Path & "\Data.txt" For Output As #1
Print #1, FileText
Close
ErrSub:
Resume Next
End Sub
Assuming my IDCount is 2, the text file becomes
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & TextTemp & "
" & TextTemp & "
" & TextTemp & "
" & TextTemp & "
" & TextTemp & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
How do I fix this? Thanks
I am very noob
Edit: My Option Explicit Is
Option Explicit
Dim IDCount As Integer
Dim LineCount As Integer
Dim FileText As String
Dim TextTemp
4 quotes ("""") escape a single quote (") so:
FileText = FileText & """" & Text1(Count) & """" & vbCrLf
(chr$(34) also outputs a ")

VBscript to target specific IP of NIC and change its DNS settings

I have currently been tasked to put together a script that will change the DNS settings of 15,000 ish servers. However, there is no common unique identifer of these NIC's other than their current DNS IP. My Question, Is it possible to somehow have my script do an ipfonfig /all and then if one of the NIC's reports back with the current DNS settings target that NIC for the new updated settings?
I was currently using the below script until i was made aware that some of the NIC will not be called "Production". Any suggestions are welcome! (powershell was not an option as we may be targeting some very old servers)
Dim strDns1
Dim strDns2
strDns1 = "10.10.10.10"
strDns2 = "10.10.10.10"
Set objShell = WScript.CreateObject("Wscript.Shell")
objShell.Run "netsh interface ip set dns name=""Production"" static "& strDns1, 0, True
objShell.Run "netsh interface ip add dns name=""Production"" addr="& strDns2, 0, True
Set objShell = Nothing
WScript.Quit
You can do the ipconfig query with a script like this:
Set wso = CreateObject("WScript.Shell")
Set execo = wso.Exec("ipconfig /all")
Set stdout = execo.StdOut
While Not stdout.AtEndOfStream
cmdOutput = cmdOutput & VbCrLf & stdout.ReadLine
Wend
wscript.echo cmdOutput
The main problem is this is just a string, so you have to parse it yourself, which is annoying and probably error prone.
I would rather suggest you take a look at the wmi class
Win32_NetworkAdapterConfiguration
which has a lot of information on the network connections. Only caveat with this WMI class is that it stores many values in arrays instead of strings so you can not just query for everything easily. Either pick something to query against that is a string like DNSDomain or just handle the logic within the script.
I'm agree with Syberdoor , You should use the Wmi Class
Win32_NetworkAdapterConfiguration
This code give you some informations :
Call ListDNSInfo()
'********************************************************************
Sub ListDNSInfo()
Dim ComputerName,IPConfigSet,IPConfig,BailObtenu,BailExpirant
ComputerName="."
On error resume next
set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & ComputerName).ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE")
If Err.Number <> 0 Then
wscript.echo " - non accessible -"
Else
for each IPConfig in IPConfigSet
BailObtenu = IPConfig.DHCPLeaseObtained
BailExpirant = IPConfig.DHCPLeaseExpires
'---- Convertion des date et heure d'obtention et d'expiration des baux DHCP en un format lisible par l'utilisateur. ----
BailObtenu = mid(BailObtenu, 7, 2) & "/" & mid(BailObtenu, 5, 2) & "/" & mid(BailObtenu, 1, 4) & " - " & mid(BailObtenu, 9, 2)& ":" & mid(BailObtenu, 11, 2)& ":" & mid(BailObtenu, 13, 2)
BailExpirant = mid(BailExpirant, 7, 2) & "/" & mid(BailExpirant, 5, 2) & "/" & mid(BailExpirant, 1, 4) & " - " & mid(BailExpirant, 9, 2)& ":" & mid(BailExpirant, 11, 2)& ":" & mid(BailExpirant, 13, 2)
MsgBox " Configuration réseau de l'ordinateur " & ComputerName & vbcrlf & vbcrlf & _
"Nom Machine " & vbtab & " : " & IPConfig.DNSHostName & vbcrlf & _
"Carte active" & vbtab & " : " & IPConfig.Description & vbcrlf & _
"Adresse MAC " & vbtab & " : " & IPConfig.MACAddress & vbcrlf & _
"DHCP Activé" & vbtab & " : " & IPConfig.DHCPEnabled & vbcrlf & _
"Adresse IP " & vbtab & " : " & IPConfig.IPAddress(0) & vbcrlf & _
"Masque " & vbtab & vbtab & " : " & IPConfig.IPSubnet(0) & vbcrlf & _
"Passerelle " & vbtab & " : " & IPConfig.DefaultIPGateway(0) & vbcrlf & _
"Serveur DHCP " & vbtab & " : " & IPConfig.DHCPServer & vbcrlf & vbcrlf & _
"Serveur DNS " & vbtab & " : " & IPConfig.DNSServerSearchOrder(0) & vbcrlf & _
" " & vbtab & vbtab & " : " & IPConfig.DNSServerSearchOrder(1) & vbcrlf & _
"Serveur WINS " & vbtab & " : " & IPConfig.WINSPrimaryServer(0) & vbcrlf & _
" " & vbtab & vbtab & " : " & IPConfig.WINSSecondaryServer(0) & vbcrlf & vbcrlf & _
" Bail obtenu " & vbtab & " : " & BailObtenu & vbcrlf & _
" Bail expirant " & vbtab & " : " & BailExpirant _
,VbInformation,"Configuration réseau de l'ordinateur "
Next
End If
End Sub

Vbscript logging into ftp

I am attempting to log into ftp host and download files. I am not sure how to locate the file as it is stored in directories under the date and will change every day. this is what I have so far
Option Explicit
Dim objFSO, objMyFile, objShell, strFTPScriptFileName, strFilePut
Dim strLocalFolderName, strFTPServerName, strLoginID
Dim strPassword, strFTPServerFolder
strLocalFolderName = "c:\foldername"
strFTPServerName = "ftp.host.com"
strLoginID = "somelogin"
strPassword = "password8"
so after the password how would I log into the date file and locate so for example the file would be under
20130722/filename.ftp
The usual way to do this in VBScript is to generate an FTP script and run that with ftp.exe:
'variable definitions
...
Function qq(str)
qq = Chr(34) & str & Chr(34)
End Function
Set fso = CreateObject("Scripting.FileSystemObject")
Set sh = CreateObject("WScript.Shell")
remoteDir = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2)
tempDir = sh.ExpandEnvironmentStrings("%TEMP%")
script = fso.BuildPath(tempDir, "download.ftp")
logfile = fso.BuildPath(tempDir, "ftp.log")
Set f = fso.OpenTextFile(script, 2, True)
f.WriteLine "open" & strFTPServerName & vbNewLine _
& "user" & strLoginID & vbNewLine _
& strPassword & vbNewLine _
& "prompt no" & vbNewLine _
& "lcd " & strLocalFolderName & vbNewLine _
& "cd " & remoteDir & vbNewLine _
& "get cs.ftp" & vbNewLine _
& "bye"
f.Close
rc=sh.Run("%COMSPEC% /c ftp -s:" & qq(script) & " >" & qq(logfile), 0, True)
WScript.Echo "FTP finished with exit code " & rc & "."
fso.DeleteFile script, True
The above should work out of the box. If you're free to install additional software, the FTP client included with ActiveXperts' Network Component might be another option.

Resources