Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Services Script

Status
Not open for further replies.

BB69

MIS
Jun 23, 2003
37
0
0
US
Hello,

I am trying to get this script to run. It is from the windows powershell scripting guide but I keep getting an error. I have Office 2003 installed and using Windows 7 64bit. I tried it on XP sp3 also.

The script is:
$strcomputer = (new-object -comobject wscript.network).computername
$strdomain = (new-object -comobject wscript.network).domain
$strwmiquery = "select * from win32_service"
$objservice = get-wmiobject -query $strwmiquery

write-host -foregroundcolor yellow "obtaining service info..."

foreach ($service in $objservice)
{
if ($service.state -eq "running")
{
$strservicename = $service.name
$strstatus = $service.status
$adopenstatic = 3
$adlockoptimistic = 3
$strdb = "c:\mytest\services.mdb"
$strtable = "runningservices"
$objconnection = New-object -comobject adodb.connection
$objrecordset = new-object -comobject adodb.recordset
$objconnection.open("Provider = Microsoft.Jet.OLEDB.4.0;data source= $srtdb")
$objrecordset.open("select * from runningservices", $objconnection, $adopenstatic, $adlockoptimistic)
$objrecordset.addnew()
$objrecordset.fields.item("timestamp") = get-date
$objrecordset.fields.item("strcomputer") = $strcomputer
$objrecordset.fields.item("strdomain") = $strdomain
$objrecordset.fields.item("strservice") = $strservicename
$objrecordset.fields.item("strstatus") = $strstatus
$objrecorset.update()
write-host -foregroundcolor yellow "/\" -nonewline
}

}
$objrecordset.close()
$objconnection.close()


And the error I get is:

Exception calling "Open" with "1" argument(s): "Provider cannot be found. It may not be properly installed."
At C:\mytest\writerunningservicestoaccess.ps1:20 char:21
+ $objconnection.open <<<< ("Provider = Microsoft.Jet.OLEDB.4.0;data source= $srtdb")
+ CategoryInfo : NotSpecified: :)) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation


On XP I get the error:

Exception calling "Open" with "1" argument(s): "Authentication failed."
At C:\mytest\writerunningservicestoaccess.ps1:20 char:21
+ $objconnection.open( <<<< "Provider=Microsoft.Jet.OLEDB.4.0;data source= $srtdb")

I know the error happens with $objconnection.open("Provider = Microsoft.Jet.OLEDB.4.0;data source= $srtdb") but I don't know what is the cause.

Can anyone tell me what is missing?

Thanks.
 
I noticed a typo on my script:
$objconnection.open("Provider = Microsoft.Jet.OLEDB.4.0;data source= $srtdb")
It should be
$objconnection.open("Provider = Microsoft.Jet.OLEDB.4.0;data source= $strdb")
 
having these lines within your ForEach loop is the most efficient i would say?

$objconnection = New-object -comobject adodb.connection
$objrecordset = new-object -comobject adodb.recordset
$objconnection.open("Provider = Microsoft.Jet.OLEDB.4.0;data source= $srtdb")
$objrecordset.open("select * from runningservices", $objconnection, $adopenstatic, $adlockoptimistic)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top