Hello,
I have some code that I wrote which checks for the existence of a string
value under a specific registry key.
If the key exists then it will output "key exists" to the console.
If the key does not exist then it will create the key using the
SetStringValue method of the StdRegProv WMI Class.
This script is being used to create string values on remote servers.
The values written to the registry are pulled from a hash that is created
in the first part of the script.
My script is able to write about 7 out of 10 hash values to the registry
successfully.
Each of these values is a string containg letters, numbers, or both and
each of these string types has been successfully written to the registry.
The other 3 string values were successfully created however they were
empty.
Upon seeing this I ran the script using -w and the following error appeared
Win32::OLE(0.1703) error 0x800703e6: "Invalid access to memory
location" in METHOD/PROPERTYGET "SetStringValue" at SrvInvGetData.pl line
771
This error only appears when I try to write a hash value to the registry.
If I supply a static string such as "Test" to the SetStringValue method
then "Test" is successfully written to the registry. Also, this error only
appears when the string value does not already exist. If the string value
does exist then it will successfully write the hash value to the registry.
Any ideas on why I am getting the "Invalid access to memory location"
error when trying to write certain hash values to the registry if the
string value does not already exist?
Thank you to everyone!
Here is my source code:
use Win32::OLE('in');
use Win32::OLE::Variant;
use Win32::File::Ver;
use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;
use constant HKEY_LOCAL_MACHINE => 0x80000002;
%TestHash = ();
$TestHash{'String_Val'} = "Hello";
$WMIreg =
Win32::OLE->GetObject("winmgmts:\\\\SERVERNAME\\root\\default:StdRegProv");
$KeyPath = "SOFTWARE\\TEST";
$ValueName = "String_Val";
$Value = Variant(VT_BSTR | VT_BYREF, "");
$WMIreg->GetStringValue(HKEY_LOCAL_MACHINE,$KeyPath,$ValueName,$Value);
if (not Win32::OLE->LastError)
{
print "Value exists\n";
}
else
{
print "Value does NOT exist\n";
$HashKeyVal = $TestHash{'String_Val'};
$WMIreg->SetStringValue(HKEY_LOCAL_MACHINE,$KeyPath,$ValueName,$HashKeyVal);
}
*******************************************************************
This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity
to whom they are addressed. If you have received this
email in error please notify the sender by replying to this
email and then delete it from your system.
No reliance may be placed upon this email without written
confirmation of its contents and any liability arising from
such reliance without written confirmation is hereby
excluded.
JRI America
*******************************************************************
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs