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 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.