vbscript help

Posted on 2013-05-23
Medium Priority
Last Modified: 2013-06-04
I have created this script that will reside on the server, it will run from a server account.  The point of this script is that it will be a schedule task, it will check the txt file every 15 minutes and if it the file has a computer name it will check against active directory...if it finds it..it will install McAfee, after its done it it reverts back the original computers.txt file to blank until some one puts another computer name on it again....
MY question is,,,is this correct what do i need to fix it and if some one could help me out on log files such as after its done it creates a text file of the out put code..also i was wondering if i don't have permissions to the server to run as a share, is there a way to copy the file to the local machine and execute it from there....any help would be appreciated...

'This will check Active Directory for a computer

Const ForReading = 1

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\Scripts\Computers.txt")

Do Until objFile.AtEndOfStream
    strComputer = objFile.ReadLine
    objCommand.CommandText = "SELECT Name FROM 'LDAP://dc=microsoft,dc=contoso,dc=com' " & _
        "WHERE objectCategory='computer' AND Name = '" & strComputer & "'"
    Set objRecordset = objCommand.Execute
    If objRecordset.RecordCount = 0 Then
        Wscript.Echo strComputer & " does not exist."
        'Wscript.Echo strComputer & " is in Active Directory."
       Wscript.Echo "ReturnValue = " & ReturnValue
    End If

'this code will load MaCafee
'Install Software on a Remote Computer

Function Install(strComputer)
Const wbemImpersonationLevelDelegate = 4

Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConnection = objwbemLocator.ConnectServer ("NOSTROVOS", "root\cimv2")

objConnection.Security_.ImpersonationLevel = wbemImpersonationLevelDelegate
Set objSoftware = objConnection.Get("Win32_Product")
errReturn = objSoftware.Install("\\NOSTROVOS\smspackages$\MCafee\4_6_FramePkg_Install_for_MS_Windows_20130211.exe",,True)
End Function

'Last step in the script

'Create a new file after everything is done
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Scripts\Computers.txt")
Question by:erwin_miranda
  • 6
  • 4
LVL 43

Expert Comment

ID: 39193300
Are you running McAfee ePolicy Orchestrator?  This should remove the need for your scripts

Author Comment

ID: 39194142
I am but its something else we are trying to do..

Author Comment

ID: 39200544
I've requested that this question be deleted for the following reason:

It did not make anysense..and the script is not completed

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 43

Expert Comment

ID: 39200545
Sorry I wasn't notified with your response. What are you trying to do other than deploying the agent etc?

Author Comment

ID: 39200783
Other than automate the process and not have a need for the McAfee policy administrators or myself have to do..nothing...but again if you want the points, they are yours..u responded.
LVL 43

Expert Comment

ID: 39203128
See the confusing thing for me is, epo should automatically deploy when a new machine appears in active directory. In other words you should not have to do anything anyway.
I'd like to answer this properly before getting any points ;-)
LVL 43

Expert Comment

ID: 39203129
Do you have ad sync on?

Author Comment

ID: 39210603
Okay...come to find out and apparently I am not a McAfee Admin...the people that are Mcafee Admin do not administrative priviliges..so I need the script..or help with it..
LVL 43

Expert Comment

ID: 39212145
Ok I understand your predicament. Now I'm not trying to be difficult but it seems you are trying to mimic what epo does. My concern it's with ongoing Maintenance. Do the agents automatically register with epo after installing using your script?
Instead of giving admin permissions to the McAfee guys, work with them to set up an automated task and enter your credentials (or a specific admin one set up by you for this purpose) and save the username And hidden password as part of the task. It's that a viable option?
More than happy to help with the script but I wanted us clear on the consequences of doing so.
LVL 43

Accepted Solution

Rob earned 600 total points
ID: 39218135
Going down the script route:
You are going to need to make sure you're installing the right version / architecture of McAfee for the machine.  It looks like you're assuming it's Windows and relying on the executable to determine 32/64bit architecture.  
Are you also planning to notify the McAfee guys when you do install a new machine? Are you sure that the new machine will be placed in the right "group" for policy administration?
Adding in a log file is easy, just requires you to have a text file you append to and add in your logs between lines of code.  A simple solution would be to create a simple function at the bottom of your script that takes an input, which is the log text, and outputs to a file.  You can build on that later if need be
You may want to include email notification when your install fails for whatever reason (can't access file share, can't access remote machine etc etc)
I'm sure there's other issues you'll come across going down this path that really ePO does for you... sorry to bang on about it but I don't see the point in reinventing the wheel, unless I"m missing something??

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question