• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

Script error

Getting error Line 39 Char 3 error ox80041001 on the following script that was working but now is not.  Also does anyone know how to pass my login credintials to the computer just for this job

'Script to get Programs install on list of Computer on a Network
'
'connect to doman
'
 
  Const FOR_APPENDING = 8
  Const FOR_READING = 1
   
  strFilename = "c:\hosts.txt"
  strOutputFile = "xpsp.txt"
   
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objTextStream = objFSO.OpenTextFile(strFilename, FOR_READING)
   
    Set objFSO2 = CreateObject("Scripting.FileSystemObject")
        If objFSO2.FileExists(strOutputFile) Then
                Set objTextStream2 = objFSO2.OpenTextFile(strOutputFile, FOR_APPENDING)
        Else
                Set objTextStream2 = objFSO2.CreateTextFile(strOutputFile)
        End If
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
'
'Read list of computer, get installed products
'
Do Until objTextStream.AtEndOfStream
  strComputer = objTextStream.readline
  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  Set colItems = objWMIService.ExecQuery("Select * from Win32_Product")
'
'
'Output to file
'
  objTextStream2.WriteLine "The Computer:" & strComputer
  For Each objItem in colItems
    objTextStream2.WriteLine objItem.Description &  " (v." & objItem.Version & ")"
  Next
Loop
0
terryshort77
Asked:
terryshort77
1 Solution
 
RobSampsonCommented:
Hi, the script looks like it should work fine, provided that the account you use to run it as (presumably your user account) has admin access to the remote machine, and also that WMI is functioning correctly on each remote machine.

I have added a bit of error checking just in case there is a WMI problem, but as far as passing your login credentials....that's already done as soon as you run the script while logged in as yourself.

You don't need the AD connection part of this script either....WMI doesn't use that.

Regards,

Rob.
Const FOR_APPENDING = 8 
Const FOR_READING = 1 

strFilename = "c:\hosts.txt" 
strOutputFile = "xpsp.txt" 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objTextStream = objFSO.OpenTextFile(strFilename, FOR_READING, False)
   
Set objTextStream2 = objFSO.OpenTextFile(strOutputFile, FOR_APPENDING, True)

' 
'Read list of computer, get installed products 
' 
Do Until objTextStream.AtEndOfStream 
	strComputer = objTextStream.readline 
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
	Set colItems = objWMIService.ExecQuery("Select * from Win32_Product") 
	' 
	'Output to file 
	' 
	objTextStream2.WriteLine "The Computer:" & strComputer 
	On Error Resume Next
	For Each objItem In colItems 
		objTextStream2.WriteLine objItem.Description &  " (v." & objItem.Version & ")" 
	Next
	If Err.Number <> 0 Then
		objTextStream2.WriteLine "ERROR " & Err.Number & ": " & Err.Description
		Err.Clear
	End If
	On Error GoTo 0
Loop
objTextStream2.Close
objTextStream.Close

Open in new window

0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now