vbscript replacing text without overwriting in a text file - vbscript

Below is part of a script I already wrote:
For i = 1 to arrsize
strText=""
Set objFile = objFSO.OpenTextFile(filetable(i), ForReading)
wscript.echo filetable(i)
On Error Resume Next
Do Until objFile.AtEndOfStream
strline = objFile.ReadLine
If instr(strline, source_string) > 0 Then
wscript.echo strline
Do Until instr(strline, " TEXT ") > 0 or instr(strline, Chr(9) & "TEXT ")
strline = objFile.ReadLine
Loop
strNewText = Replace(strline, "TEXT " & Chr(34), "TEXT " & Chr(34) & "Critical: ",1,-1,0)
wscript.echo strNewText
'up to here everything is OK
Set objFile = objFSO.OpenTextFile(filetable(i), ForWriting)
objFile.WriteLine strNewText
objFile.close
'The three line above are overwriting the text file
End If`enter code here`
Loop
Next
My script is to search in an array of files for a specific string registered in source_string variable, then if it matches it should search for "TEXT" word preceded by space or tab, when matches and it should it will then replace the line with the same line as per the following format:
TEXT "Critical: ****".
I hope it is clear and thanks in advanced

I think here you open the text file again and you start at the start of stream and thus the first line (and not the found line) :
Set objFile = objFSO.OpenTextFile(filetable(i), ForWriting)
objFile.WriteLine strNewText
objFile.close
Maybe you should try opening the file for reading&writing, readline, when you str is found, then change that line and move on ...

For i = 1 to arrsize
Set objFile = objFSO.OpenTextFile(filetable(i), ForReading)
wscript.echo filetable(i)
On Error Resume Next
Dim filearray()
Linenb = 0
Do Until objFile.AtEndOfStream
Linenb = Linenb + 1
Redim Preserve filearray(Linenb)
filearray(Linenb) = objFile.ReadLine
' wscript.echo filearray(Linenb)
If instr(filearray(Linenb), source_string) > 0 Then
' wscript.echo filearray(Linenb)
Do Until instr(filearray(Linenb), " TEXT ") > 0 or instr(filearray(Linenb), Chr(9) & "TEXT ")
Linenb = Linenb + 1
Redim Preserve filearray (Linenb)
filearray(Linenb) = objFile.ReadLine
' wscript.echo filearray(Linenb)
Loop
filearray(Linenb) = Replace(filearray(Linenb), "TEXT " & Chr(34), "TEXT " & Chr(34) & "Critical: ",1,-1,0)
' wscript.echo filearray(Linenb)
End If
Loop
For j = 1 to Linenb
Set objFile = objFSO.OpenTextFile(filetable(i), ForWriting)
objfile.WriteLine filearray(j)
Next
Redim Preserve filearray (1)
Next

Related

What's wrong with my VBscript code?

I write the vbscript code to monitor system starting and ending time but it's not logging in same day 'That means not open and writing the same date file how to solve this
Dim objFS, objFile
Dim crdate,ckdate,fname
Set objFS = CreateObject("Scripting.FileSystemObject")
do
crdate = Day(now) & "-" & Month(now) & "-" & Year(now)
fname = crdate & ".txt"
if (objFS.FileExists(fname)) Then
do
ckdate = Day(now) & "-" & Month(now) & "-" & Year(now)
objFile.WriteLine(Time & "\n")
wscript.sleep 300000
loop until ckdate <> crdate
else
Set objFile = objFS.CreateTextFile(fname)
end if
loop
I found the answer in google that is closing the file with
objFile.Close
Dim objFS, objFile
Dim crdate,ckdate,fname
Set objFS = CreateObject("Scripting.FileSystemObject")
do
crdate = Day(now) & "-" & Month(now) & "-" & Year(now)
fname = crdate & ".txt"
if (objFS.FileExists(fname)) Then
Set objFile = objFS.OpenTextFile(fname, 8, True)
objFile.WriteLine("-------------------------------")
do
ckdate = Day(now) & "-" & Month(now) & "-" & Year(now)
objFile.WriteLine(Time)
wscript.sleep 300000
loop until ckdate <> crdate
objFile.Close
else
Set objFile = objFS.CreateTextFile(fname)
objFile.Close
end if
loop
Windows does this natively... you don't have to reinvent the wheel. You can pull this locally or remotely and more ACCURATELY with the windows events.
PS C:\Users\steve> Get-WinEvent -Log System | where {($_.ID -eq "12" -or $_.ID -eq "13")} | format-table -property Message
Message
-------
The operating system started at system time ?2017?-?01?-?01T00:51:20.610798500Z.
The operating system is shutting down at system time ?2017?-?01?-?01T00:50:53.812034600Z.

Upload and download a file using FTP without ActiveX

I want VBScript to upload and download a file using FTP without using ActiveX program.
Notice please give me download code alone and upload code alone and must upload file not folder.
For example:
Set oShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
path = "test.txt"
FTPUpload(path)
Sub FTPUpload(path)
On Error Resume Next
Const copyType = 16
waitTime = 80000
FTPUser = "user"
FTPPass = "pass"
FTPHost = "www.domain.com"
FTPDir = "/htdocs/"
strFTP = "ftp://" & FTPUser & ":" & FTPPass & "#" & FTPHost & FTPDir
Set objFTP = oShell.NameSpace(strFTP)
'objFTP.NewFolder "FTP Backup"
If objFSO.FileExists(path) Then
Set objFile = objFSO.getFile(path)
strParent = objFile.ParentFolder
Set objFolder = oShell.NameSpace(strParent)
Set objItem = objFolder.ParseName(objFile.Name)
Wscript.Echo "Uploading file " & objItem.Name & " to " & strFTP
objFTP.CopyHere objItem, copyType
End If
If objFSO.FolderExists(path) Then
Set objFolder = oShell.NameSpace(path)
Wscript.Echo "Uploading folder " & path & " to " & strFTP
objFTP.CopyHere objFolder.Items, copyType
End If
If Err.Number <> 0 Then
Wscript.Echo "Error: " & Err.Description
End If
WScript.Sleep waitTime
End Sub

How can we programmatically know the syntax error using msscript.ocx?

I have implemented msscript.ocx using c# and it works for VBScript.
Consider the following VBScript code:
For i = 0 To 5
'The following line has missing 'Then'. It should show an error.
If i = 2
Exit For
End If
Next
How can we tell if there is an error in line containing If (missing Then) without running the script?
You get the error when loading.
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Sub VBSCmd
RawScript = Arg(1)
'Remove ^ from quoting command line and replace : with vbcrlf so get line number if error
Script = Replace(RawScript, "^", "")
Script = Replace(Script, "'", chr(34))
Script = Replace(Script, ":", vbcrlf)
'Building the script with predefined statements and the user's code
Script = "Dim gU" & vbcrlf & "Dim gdU" & vbcrlf & "Set gdU = CreateObject(" & chr(34) & "Scripting.Dictionary" & chr(34) & ")" & vbcrlf & "Function UF(L, LC)" & vbcrlf & "Set greU = New RegExp" & vbcrlf & "On Error Resume Next" & vbcrlf & Script & vbcrlf & "End Function" & vbcrlf
'Testing the script for syntax errors
On Error Resume Next
set ScriptControl1 = wscript.createObject("MSScriptControl.ScriptControl",SC)
With ScriptControl1
.Language = "VBScript"
.UseSafeSubset = False
.AllowUI = True
.AddCode Script
End With
With ScriptControl1.Error
If .number <> 0 then
Outp.WriteBlankLines(1)
Outp.WriteLine "User function syntax error"
Outp.WriteLine "=========================="
Outp.WriteBlankLines(1)
Outp.Write NumberScript(Script)
Outp.WriteBlankLines(2)
Outp.WriteLine "Error " & .number & " " & .description
Outp.WriteLine "Line " & .line & " " & "Col " & .column
Exit Sub
End If
End With
ExecuteGlobal(Script)
'Remove the first line as the parameters are the first line
'Line=Inp.readline
Do Until Inp.AtEndOfStream
Line=Inp.readline
LineCount = Inp.Line
temp = UF(Line, LineCount)
If err.number <> 0 then
outp.writeline ""
outp.writeline ""
outp.writeline "User function runtime error"
outp.writeline "==========================="
Outp.WriteBlankLines(1)
Outp.Write NumberScript(Script)
Outp.WriteBlankLines(2)
Outp.WriteLine "Error " & err.number & " " & err.description
Outp.WriteLine "Source " & err.source
Outp.WriteLine "Line number and column not available for runtime errors"
wscript.quit
End If
outp.writeline temp
Loop
End Sub
Vbs
filter vbs "text of a vbs script"
Use colons to seperate statements and lines. Use single quotes in place of double quotes, if you need a single quote use chr(39). Escape brackets and ampersand with the ^ character. If you need a caret use chr(136).
The function is called UF (for UserFunction). It has two parameters, L which contains the current line and LC which contains the linecount. Set the results of the script to UF. See example.
There are three global objects available. An undeclared global variable gU to maintain state. Use it as an array if you need more than one variable. A Dictionary object gdU for saving and accessing previous lines. And a RegExp object greU ready for use.
Example
This vbs script inserts the line number and sets the line to the function UF which Filter prints.
filter vbs "uf=LC ^& ' ' ^& L"<"%systemroot%\win.ini"
This is how it looks in memory
Dim gU
Set gdU = CreateObject("Scripting.Dictionary")
Set greU = New RegExp
Function UF(L, LC)
---from command line---
uf=LC & " " & L
---end from command line---
End Function
If there is a syntax error Filter will display debugging details.

Getting & Managing/updating local built-in accounts for some Windows domain & standalone servers (vbscript)

**
Hi!
I was wondering if someone tried something similar, I have some code merged with a lot of glue...but as i'm a newby in vbs I can be sure that most of it is wrong. Basically I wanted to save a lot time during built-in admin accounts review /update with an automatic vbscript for this task.
I have like 6 account names and each one with an specific passwords.
I'm not 100% sure of which local account name is being used into each server but that might be something that i will need to verify manually or try to see if I can use another file where this script will read the possible accounts names and passwords and use some kind of brute force
Here is what I have :**
**update 8-29-12 a (deleted)
**update 8-29-12 b "THIS ONE IS WORKING..but i need to test & use cpau for NDC's"
Option Explicit
Dim strExcelPath, objExcel, objSheet, intRow, strUserDN, strPassword, comp
Dim objUser
' Spreadsheet file.
strExcelPath = "c:\List.xls"
' Bind to Excel object.
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Excel application not found."
Wscript.Quit
End If
On Error GoTo 0
' Open spreadsheet.
On Error Resume Next
objExcel.Workbooks.Open strExcelPath
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Spreadsheet cannot be opened: " & strExcelPath
Wscript.Quit
End If
On Error GoTo 0
' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
intRow = 2
Do While objSheet.Cells(intRow, 1).Value <> ""
comp = objSheet.Cells(intRow, 1).Value
strUserDN = objSheet.Cells(intRow, 2).Value
strPassword = objSheet.Cells(intRow, 3).Value
On Error Resume Next
Set objuser = GetObject ("WinNT://" & comp & "/" & strUserDN & ",user")
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Data NOT found: "
Else
objUser.SetPassword strPassword
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Password NOT set for: " & strUserDN
Else
End If
End If
intRow = intRow + 1
Loop
' Close the workbook.
objExcel.ActiveWorkbook.Close
' Quit Excel.
objExcel.Application.Quit
Wscript.Echo "Done"
My option "B" could be start over using something like this:
#echo off
for /F "delims=" %%i in (servers.txt) do (
psexec \%%i NET USER > %%i.txt
)
**
There might hundreds of ways to solve this and the my idea it's avoid having someone manually modifying the admin passwords for the servers listed and not listed in the AD after one month.
Any help would be appreciated.
Regards
This code will list the local users for one computer, specified by the variable server, and then print the user id of each user.
server = "YourServerName"
Set oComputer = GetObject("WinNT://" & server & "")
oComputer.Filter = Array("User")
For Each oUser in oComputer
WScript.Echo oUser.Name
Next
'Objective: check multiple servers for admin accounts status and report to html file
Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FilesyStemObject")
InputFile = WScript.Arguments.Named("servers")
if len(InputFile) < 1 then
wscript.echo "Error: Servers Parameter not found" & vbCrLf
show_usage
wscript.quit
end if
Outputfile= InputFile & "_guest_admins_" + cstr(Month(now()))+"_"+cstr(day(now()))+".htm"
if not ofso.FileExists(inputfile) then
wscript.echo "Error: Server list file not Found."
wscript.quit
end if
Set ofile = ofso.createTextFile(OutputFile, True)
Set ifile = iFSO.OpenTextFile(inputfile)
ofile.writeline "<html>" & html_head & "<body>"
ofile.writeline "<table border=1 cellpadding=1 cellspacing=0>"
ofile.writeline o
ofile.writeline "<tr><td>Hostname</td><td>User</td><td>Disabled</td><td>Locked</td><td>Expiration Date</td><td>Flags</td><td>BuiltIn</td></tr>"
Do until ifile.AtEndOfLine
Computer = ifile.ReadLine
if ping(Computer) then
Builtin = ""
if Check_WMI(Computer) then
Builtin = GetBuiltInAccount(Computer)
else
Builtin = "WMI Fail"
end if
strt = now
wscript.echo "Checking Users for server: " & Computer
on error resume next
Set objGroup = GetObject("WinNT://" & Computer & "/Administrators,group")
if err.number <> 0 then
wscript.echo "GetObject WinNT Failed"
ofile.writeline "<tr><td>" & computer & "</td><td colspan=6 align=center>GetObject WinNT Fail: "& err.number &"</td></tr>"
else
on error goto 0
For Each objUser in objGroup.Members
ofile.writeline GetUserNT(computer, objUser.Name, Builtin)
Next
wscript.echo "Elapsed Time: " & datediff("s", strt, now) & " seconds"
end if
else
wscript.echo computer & " does not reply ping"
ofile.writeline "<tr><td>" & computer & "</td><td colspan=6 align=center>No Ping Reply</td></tr>"
end if
Loop
ofile.writeline "</table>"
ofile.writeline "</body></html>"
function ping(target)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPingedComputers = objWMIService.ExecQuery("Select * from Win32_PingStatus Where Address = '"& target & "'")
For each objComputer in colPingedComputers
' If the status code is Null or Not 0 then the ping failed
If IsNull( objComputer.StatusCode ) Or objComputer.StatusCode <> 0 Then
' Set the function to return Boolean FALSE
Ping = False
Else
' Set the function to return Boolean TRUE
Ping = True
End If
Next
end function
sub show_usage
wscript.echo "Usage: cscript chkusers /servers:list.txt" & vbcrlf
wscript.echo vbtab & "/servers Parameter is a Text File one Servername per Line" & vbcrlf
wscript.echo "Notes: This script generates an html report of server admin accounts."
wscript.echo " Results are saved in a file named + date + htm extension."
wscript.echo " Output example filename: list_guest_admins_" + cstr(Month(now()))+"_"+cstr(day(now()))+".htm"
end sub
Function Check_WMI(strServer)
On Error Resume Next ' error handling off
' create object reference, connect to namespace root\default
Set oCimOmId = GetObject("winmgmts:"& strServer & "\root\default:__cimomidentification=#")
' Test whether WMI is present or not.
If Err <> 0 then
Check_WMI= true
else
Check_WMI= false
end if
on error goto 0
end function
Sub EnumNameSpaces(strNameSpace)
'call enumnamespaces("root")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")
For Each objNameSpace In colNameSpaces
Call EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)
Next
End Sub
function CSS
tt = "<style type=""text/css"">" & vbcrlf
tt=tt & " body {font-family:Verdana;font-size: 10px;color: #49403B;background: #EFEFEF;}" & vbcrlf
tt=tt & "table {font-family:Verdana;font-size: 12px; empty-cells:show; }" & vbcrlf
tt=tt & "</style>" & vbcrlf
CSS = tt
end function
function html_head
tt="<head>" & vbcrlf
tt=tt & CSS
html_head = tt & "</head>" & vbcrlf
end function
function GetUserNT(strComputer, usr, bltin)
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
o=""
On Error Resume Next
Set objUser = GetObject("WinNT:// " & strComputer & "/" & usr & " ")
o=o& "<tr><td>"& strcomputer &"</td><td>"& usr &"</td>"
if len(objUser.AccountDisabled) = 0 then exit function
o=o& "<td> "& StrDisabled(objUser.AccountDisabled) &"</td>"
o=o& "<td> "& StrLocked(objUser.IsAccountLocked) &"</td>"
o=o& "<td> "
o=o& objUser.Get("UserFlags") AND ADS_UF_DONT_EXPIRE_PASSWD
o=o& "</td>"
o=o& "<td> "
o=o& objUser.AccountExpirationDate
o=o& "</td>"
if lcase(bltin) = lcase(usr) then
o=o & "<td> Built-In</td>"
elseif instr(bltin, "[[Fail]]") > 0 then
o=o & "<td> "& bltin &"</td>"
else
o=o & "<td> </td>"
end if
o = o & "</tr>"
GetUserNT = o
end function
function StrLocked(str)
if str = "True" then
StrLocked = "Locked"
else
StrLocked = "Unlocked"
end if
end function
function StrDisabled(str)
if str = "True" then
StrDisabled = "Disabled"
else
StrDisabled = "Enabled"
end if
end function
function GetUsers(strComputer,grp,usr)
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_UserAccount Where name = '"& usr &"'")
o=""
For Each objItem in colItems
o=o& "<tr>"
o=o& "<td>" & strComputer & "</td>"
o=o& "<td>" & grp & "</td>"
o=o& "<td>" & objItem.AccountType & "</td>"
o=o& "<td>" & objItem.Caption & "</td>"
o=o& "<td>" & objItem.Description & "</td>"
o=o& "<td>" & objItem.Disabled & "</td>"
o=o& "<td>" & objItem.Domain & "</td>"
o=o& "<td>" & objItem.FullName & "</td>"
o=o& "<td>" & objItem.LocalAccount & "</td>"
o=o& "<td>" & objItem.Lockout & "</td>"
o=o& "<td>" & objItem.Name & "</td>"
o=o& "<td>" & objItem.PasswordChangeable & "</td>"
o=o& "<td>" & objItem.PasswordExpires & "</td>"
o=o& "<td>" & objItem.PasswordRequired & "</td>"
o=o& "<td>" & objItem.SID & "</td>"
o=o& "<td>" & objItem.SIDType & "</td>"
o=o& "<td>" & objItem.Status & "</td>"
o=o& "</tr>"
Next
on error goto 0
GetUsers = o
end function
Function getlcl(srvname)
Set objComputer = GetObject("WinNT://" & srvname & "/Administrators,group")
wscript.echo "Local Accounts on " & srvname
wscript.echo "-------------------------------------------------"
For Each objUser in objComputer.Members
Wscript.Echo vbTab & objUser.Name
Next
wscript.echo "-------------------------------------------------"
end Function
function GetBuiltInAccount(strComputer)
on error resume next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
if err.number <> 0 then
GetBuiltInAccout = "Get Object WMI [[Fail]]: " & err.number & ":: " & err.description
err.clear
exit function
end if
on error goto 0
on error resume next
Set colAccounts = objWMIService.ExecQuery("Select * From Win32_UserAccount Where Domain = '" & strComputer & "'")
if err.number <> 0 then
GetBuiltInAccout = "WMI_ExecQuery [[Fail]]: " & err.number & ":: " & err.description
err.clear
exit function
end if
on error goto 0
on error resume next
For Each objAccount in colAccounts
if err.number <> 0 then
GetBuiltInAccout = "WMI_ExecQuery_ForEachAccount [[Fail]]: " & err.number & ":: " & err.description
wscript.echo "WMI_ExecQuery_ForEachAccount [[Fail]]: " & err.number & ":: " & err.description
err.clear
exit function
end if
on error goto 0
If Left (objAccount.SID, 6) = "S-1-5-" and Right(objAccount.SID, 4) = "-500" Then
GetBuiltInAccount = objAccount.Name
exit function
End If
Next
end function
Special instructions
For Domain servers:
Create a batch/cmd file (something like admins.cmd) containing the line below:
cscript admin.vbs /servers:list.txt
For Standalone server:
-Download CPAU.exe
Create a batch/cmd file (something like adminsNDC.cmd) conteninig the line below:
CPAU -u %COMPUTERNAME%\administrator -p mypassword -ex "cscript.exe Admins.vbs /servers:list.txt" -nowarn
-Local Admin report v1-
Instructions
For Domain servers:
1-Add the servers to be scaned into: "list.txt"
2-Run/create a scheduled task for "one" of the following files :
admins.cmd <-------> (you will get: |Hostname|User| Disabled |Locked |Expiration Date| Flags |BuiltIn |)
3-Check the html report(you can sent it to excel through IE)
For a Standalone server:
1-Add the server to be scaned into: "list.txt"
2-Edit the account name and password info into adminsNDC.cmd
3-Run adminsNDC.cmd <-------> (you will get: |Hostname|User| Disabled |Locked |Expiration Date| Flags |BuiltIn |)
3-Check the html report
After getting a report of the servers and accounts, this script could be used to perform password's update.
Option Explicit
Dim strExcelPath, objExcel, objSheet, intRow, strUserDN, strPassword, comp
Dim objUser
' Spreadsheet file.
strExcelPath = "c:\List.xls"
' Bind to Excel object.
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Excel application not found."
Wscript.Quit
End If
On Error GoTo 0
' Open spreadsheet.
On Error Resume Next
objExcel.Workbooks.Open strExcelPath
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Spreadsheet cannot be opened: " & strExcelPath
Wscript.Quit
End If
On Error GoTo 0
' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
intRow = 2
Do While objSheet.Cells(intRow, 1).Value <> ""
comp = objSheet.Cells(intRow, 1).Value
strUserDN = objSheet.Cells(intRow, 2).Value
strPassword = objSheet.Cells(intRow, 3).Value
On Error Resume Next
Set objuser = GetObject ("WinNT://" & comp & "/" & strUserDN & ",user")
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Data NOT found: "
Else
objUser.SetPassword strPassword
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Password NOT set for: " & strUserDN
Else
End If
End If
intRow = intRow + 1
Loop
' Close the workbook.
objExcel.ActiveWorkbook.Close
' Quit Excel.
objExcel.Application.Quit
Wscript.Echo "Done"

VB Error "object required"

I'm getting an "object required" error on line 54, the last line, when I run the following script. What is wrong?
Option Explicit
Dim cmdString, g_strHostFile, filepath, flexnetpath, importcmd, dtmToday, dtmYesterday, dtmFileDate, param1, param2, param3, i4path, objFSO, objTextStream, g_strComputer, WshShell
'Initialize global constants and variables.
Const FOR_READING = 1
g_strHostFile = "D:\dataimports\LUM_servers.txt"
i4path = "C:\IFOR\WIN\BIN\i4blt.exe"
filepath = "D:\DataImports\"
flexnetpath = "C:\Program Files (x86)\Flexnet\Manager\Admin"
importcmd = flexnetpath & "flexnet bulkimport -uadmin -padmin -f" & filepath
dtmToday = Date()
dtmYesterday = Date() - 1
dtmFileDate = Year(Date) & padDate(Month(Date)) & padDate(Day(Date))
param1 = "-r1 -e2,4 -n "
param2 = " -v 'Dassault Systemes' -b "
param3 = " -g "
WScript.Echo "i4Path: " & i4path
WScript.Echo "FilePath: " & filepath
WScript.Echo "flexnetpath: " & flexnetpath
WScript.Echo "importcmd: " & importcmd
WScript.Echo "dtmToday: " & dtmToday
WScript.Echo "dtmYesterday: " & dtmYesterday
WScript.Echo "dtmFileDate: " & dtmFileDate
'Read LUM Server Names from text file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(g_strHostFile) Then
Set objTextStream = objFSO.OpenTextFile(g_strHostFile, FOR_READING)
Else
WScript.Echo "Input file " & g_strHostFile & " not found."
WScript.Quit
End If
'Loop through list of computers and perform tasks on each.
Do Until objTextStream.AtEndOfStream
g_strComputer = objTextStream.ReadLine
WScript.Echo "Processing Server: " & g_strComputer
Set cmdString = i4path & param1 & g_strComputer & param2 & dtmYesterday & param3 & dtmToday & filepath & g_strComputer & "_" & dtmFileDate & "_lum.lrl"
WScript.Echo "Processing Command: " & cmdString
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmdString"
Loop
objTextStream.Close
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "Processing Bulk Import: " & importcmd
WshShell.Run "importcmd"
Function padDate(intNumber)
if intNumber <= 9 Then
padDate = "0" & CStr(intNumber)
Else
padDate = CStr(intNumber)
End If
End Function
Object required is raised when you have a statement like Set x = y where x is not an object type, but is instead an simple type (Integer, Double, Date, etc. ). I think the line
Set cmdString = i4path & param1 & g_strComputer & param2 & ...
is causing the error, and I think all you have to do is remove the Set statement. I think strings do not derive from Object and thus do not need the Set statement.
There are a few problems, I think.
importcmd = flexnetpath & "flexnet bulkimport -uadmin -padmin -f" & filepath
You probably need some spaces:
importcmd = flexnetpath & " flexnet bulkimport -uadmin -padmin -f " & filepath
Set is only used with objects, not strings, so it should be removed from this line:
Set cmdString = i4path & param1 & g_strComputer & param2 & dtmYesterday & param3 & dtmToday & filepath & g_strComputer & "_" & dtmFileDate & "_lum.lrl"
I am fairly sure you either mean
WshShell.Run importcmd
Or
WshShell.Run """" & importcmd & """"

Resources