VB Error "object required" - vbscript

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 & """"

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
'

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.

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"

How to launch a Vb script that runs in 64 bit mode from a vbscript running under Wow64

I have a VB script that's being forced to run in Wow64 mode. I'd like to have it start either another script, or itself, in native 64 bit mode. Is there anyway to do that?
The initial script is being called by an explicit call to cscript.exe (not sure if this makes a difference or not)
Thanks
Apparently its pretty simple.
In Windows Vista and newer there is an alias folder at C:\Windows\Sysnative. If you call it it will not redirect to the c:\windows\SysWow64 32 bit folder but will force the native 64 bit executables to be called
http://msdn.microsoft.com/en-us/library/aa384187(VS.85).aspx
Therefore, you can run a vbscript in 64 bit mode from a vbscript running in wow64 mode by calling %windir%\Sysnative\cscript.exe and then providing the name of your script as a parameter.
However, this only works in Windows Vista or newer. There is a hotfix which can enable this Sysnative folder in Windows XP/2003
http://support.microsoft.com/kb/942589
Place the following code at the top of your script to detect if the OS is 64bit then re-run in 32bit mode
' ***************
' *** 64bit check
' ***************
' check to see if we are on 64bit OS -> re-run this script with 32bit cscript
Function RestartWithCScript32(extraargs)
Dim strCMD, iCount
strCMD = r32wShell.ExpandEnvironmentStrings("%SYSTEMROOT%") & "\SysWOW64\cscript.exe"
If NOT r32fso.FileExists(strCMD) Then strCMD = "cscript.exe" ' This probably won't work if we can't find the SysWOW64 Version
strCMD = strCMD & Chr(32) & Wscript.ScriptFullName & Chr(32)
If Wscript.Arguments.Count > 0 Then
For iCount = 0 To WScript.Arguments.Count - 1
if Instr(Wscript.Arguments(iCount), " ") = 0 Then ' add unspaced args
strCMD = strCMD & " " & Wscript.Arguments(iCount) & " "
Else
If Instr("/-\", Left(Wscript.Arguments(iCount), 1)) > 0 Then ' quote spaced args
If InStr(WScript.Arguments(iCount),"=") > 0 Then
strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") + 1) & """ "
ElseIf Instr(WScript.Arguments(iCount),":") > 0 Then
strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") + 1) & """ "
Else
strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
End If
Else
strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
End If
End If
Next
End If
r32wShell.Run strCMD & " " & extraargs, 0, False
End Function
Dim r32wShell, r32env1, r32env2, r32iCount
Dim r32fso
SET r32fso = CreateObject("Scripting.FileSystemObject")
Set r32wShell = WScript.CreateObject("WScript.Shell")
r32env1 = r32wShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
If r32env1 <> "x86" Then
' we are not running in x86 mode, so run in that mode; check if we have done this already
For r32iCount = 0 To WScript.Arguments.Count - 1
r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
Next
' MsgBox "64bit (restarting) " & r32env2
If InStr(r32env2,"restart32") = 0 Then RestartWithCScript32 "restart32" Else MsgBox "Cannot find 32bit version of cscript.exe or unknown OS type " & r32env1
Set r32wShell = Nothing
WScript.Quit
Else
For r32iCount = 0 To WScript.Arguments.Count - 1
r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
Next
' MsgBox "32bit! " & r32env2
End If
'MsgBox "OS: " & r32env1 & VbCrLf & "Param: " & r32env2 & VbCrLf & "Script: " & WScript.FullName & VbCrLf & "Fullname: " & " " & Wscript.ScriptFullName
Set r32wShell = Nothing
Set r32fso = Nothing
' WScript.Quit
' *******************
' *** END 64bit check
' *******************

Ping script with email in vbs

i know i asked already the question about the ping script but now i have a new question about it :-) I hope someone can help me again.
strText = "here comes the mail message"
strFile = "test.log"
PingForever strHost, strFile
Sub PingForever(strHost, outputfile)
Dim Output, Shell, strCommand, ReturnCode
Set Output = CreateObject("Scripting.FileSystemObject").OpenTextFile(outputfile, 8, True)
Set Shell = CreateObject("wscript.shell")
strCommand = "ping -n 1 -w 300 " & strHost
While(True)
ReturnCode = Shell.Run(strCommand, 0, True)
If ReturnCode = 0 Then
Output.WriteLine Date() & " - " & Time & " | " & strHost & " - ONLINE"
Else
Output.WriteLine Date() & " - " & Time & " | " & strHost & " - OFFLINE"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "noreply#test.net"
objEmail.To = "test#test.net"
objEmail.Subject = "Computer" & strHost & " is offline"
objEmail.Textbody = strText
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtpadress"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If
Wscript.Sleep 2000
Wend
End Sub
My problem is now, the mail comes all 2 seconds, when the computer are offline. Can someone show me how to make it with flags? So only one mail comes when its offline?
Thanks for your help.
Use a flag and report only when state changes
FLAG0 = "ON"
While(True)
ReturnCode = Shell.Run(strCommand, 0, True)
If ReturnCode = 0 Then
Output.WriteLine Date() & " - " & Time & " | " & strHost & " - ONLINE"
FLAG0 = "ON"
Else
Output.WriteLine Date() & " - " & Time & " | " & strHost & " - OFFLINE"
IF FLAG0 = "ON" THEN
FLAG0 = "OFF"
Set objEmail = CreateObject("CDO.Message")
...... rest of mailing code
END IF
End If

Resources