ReadEventLog() API fails with error code 87 on Windows Server 2008 R2 while reading Application/System/Security event logs from system - windows-server-2008

I have an MFC application which reads system (i.e. Application/System/Security) event logs on Windows Server 2008 R2 in WOW64 environment. I am facing a problem with std SDK ::ReadEventLog() function in Windows Server 2008 R2. Below I have provided the code snippet, but the same code/API works perfectly in Windows XP WOW64 & x64 environment. Error code '87' refers to "The parameter is incorrect" but according me the parameters which I passed to ::ReadEventLog() function seems to be correct.
[Code]
//BufferSize.
const int BUFFER_SIZE = 1024*10
BYTE l_bBufferSize[BUFFER_SIZE];
EVENTLOGRECORD* l_pEvntLogRecord = NULL;
l_pEvntLogRecord = (EVENTLOGRECORD *) &l_bBufferSize;
::SetLastError(0);
/*
Adjust the 'counter' to read logs. 'l_nReadRecordIndex' is mapped with the list control, e.g. on key down, 'l_nReadRecordIndex' is set as "GetCountPerPage() + 1" this is one case as their are many case.
*/
DWORD l_dwLogCounter = (GetTotalNumberOfRecords() - l_nReadRecordIndex) + 1;
//Read logs as per "nCntToReadRecords".
for(l_dwLogCounter;l_nNoOfRecTobeRead <= nCntToReadRecords;l_dwLogCounter--, l_nNoOfRecTobeRead++)
{
//Get Actual position to read.
if(0 != ::ReadEventLog( m_hEventLogHandle, EVENTLOG_SEEK_READ|EVENTLOG_FORWARDS_READ,
l_dwLogCounter, l_pEvntLogRecord, BUFFER_SIZE,
&l_dwReadBytes, &l_dwNeedBytes))
{
DWORD l_dwErrCode = 0;
l_dwErrCode = ::GetLastError(); //87 is returned
return FALSE
}
}
//Data population code
If any one is aware of similar problem or worked on the similar issue please let me know the solution. Please refer the above code snippet and let me know the following things, a) What are the incorrect parameters. b) Is their any another way to read event logs.
Thanks in advance.
--
Ganesh

It is a bug, check this entry in MS's KB http://support.microsoft.com/kb/177199

Related

SQL Error -4903 when trying to connect to DB2 database

I am getting an SQL error code of -4903 when trying to connect to a DB2 database using SQC code (this is an ANSI C application so I need to use SQC for SQL queries). When I look at IBM's website to see what a -4903 means, all it says is "The length of parameter n of function name is not valid". However I have no idea which parameter or function it is referring to. I have tried looking at the SQLCA objects members, but I am unable to see them in Visual Studio 2015.
This is an ANSI C application debugging in Visual Studio 2015. I am able to connect to the same database using a DB2 command prompt (i.e, by running "db2 connect to dbname user username using password". However when I try to do this in code I get the -4903 error. I have also tried this on two different OS's, Windows 7 and Windows 10. I have colleagues who have had no trouble doing this on a Windows 7 machine.
while ((retry++ < 3)
|| (sqlca.sqlcode == -30080)
|| (sqlca.sqlcode == -900 ) )
{
EXEC SQL CONNECT TO :DBName USER :userid USING :pword;
if ((SQLCODE == 0 ) || (SQLCODE == (-1026)))
{
return(1);
}
else
{
dbLogAudit(KLCB, PLCB, KLLOGSEV(T),
"Retry DBInit/sqlca.sqlcode : %i", sqlca.sqlcode);
}
}
I expect the SQLCODE to be 0, which indicates a successful connection, and for the function to return 1 to it's caller. But instead the sqlca.sqlcode variable is -4903 (which I described above).
EDIT: I found the parameters being passed into the error message. The full error text is "The length of parameter runtime_pid of function sqlastrt_trusted is not valid".
I solved my own issue. Thanks to Mao for the help on debugging this one.
My development environment for DB2 was running version 8.1.0, which uses 162 bytes for the struct called "sqla_program_id". However, the runtime environment, which uses 292 bytes for that same struct, was version 10.5. Once I upgraded my development DB2 instance to v10.5 it worked like a charm.

EPPlus AutoFit() different column width on different machines

I am using EPPlus Version 4.1.0
I know this issue seems extremely weird but I have already wasted 2 days on this and any input is very very welcome!
I run the following code:
using (var package = new ExcelPackage())
{
ExcelWorksheet ws = package.Workbook.Worksheets.Add("Sheet1");
...
for (int i = ws.Dimension.Start.Column; i <= ws.Dimension.End.Column; i++)
{
ws.Column(i).AutoFit(0, 100);
ws.Column(i).Style.WrapText = ws.Column(i).Width > 60;
}
...
I run this code on several machines and the AutFit() function always returns the same value for the column width.
But on one machine the (unfortunately my new laptop) the width is completely off (i.e. 33 instead of expected 11).
Any clues how my machine setup can possibly effect this?
I hope somebody else can benefit from this, but as stated in the comments, it was actually the DPI settings of my new machine that caused this.
I have yet to find out if this actually affects the reports itself.

Why does my code run 2 different ways with the exact same code?

I have an application that I have started developing that monitors websocket messages from all clients connected to the websocket server by relaying all messages received from the server to this application.
Problem
When I run my program (In visual studio I hit Start), it builds and starts up perfectly, and does most of the functionality the same everytime. However, I have a common occurance of a portion of code that will not run the same. Below is the small snippet of that code.
msg = "set name monitor"
SendMessage2(socket, msg, msg.Length)
msg = "set monitor 1"
SendMessage2(socket, msg, msg.Length)
Console.WriteLine("We are after our second SendMessage2 function")
I know that the two calls to SendMessage2 are always executed because visual studio's debug console will output the following
We are at the end of the SendMessage2 Sub
We are at the end of the SendMessage2 Sub
We are after our second SendMessage2 function
I also know when it executes correctly because my websocket server will either output one of the two blocks
Output when app runs correctly
Client 4 connected
New thread created
Connection received. Parsing headers.
Message from socket #4: "set name monitor"
Message from socket #4: "set monitor 1"
Output when app runs incorrectly
Client 4 connected
New thread created
Connection received. Parsing headers.
Message from socket #4: "set name monitor"
Notice how the second output is missing the second message from the monitor application.
What have I tried
Using a string variable to call the functions
Calling the functions using static string arguments (not using the variable msg)
SyncLocking the functions separately
SyncLocking inside the SendMessage2 function
Reordering the functions (swapping the strings to change behavior)
TL;DR
Why is it that even when I do not change my code, my program will execute two separate ways? Am I doing something incorrectly when calling my SendMessage2 Sub?
I am all out of ideas. I am willing to try any recommendation to fix this problem.
All code can be found on GitHub here
So I figured it out.
It is actually not the VB application that is messing up. Nor was my server. While debugging I was looking at the number of bytes received by my server and I noticed the following:
Client 4 connected
New thread created
Connection received. Parsing headers.
bytes read: 25
Message from socket #4: "set name monitor"
bytes read: 22
Message from socket #4: "set monitor 1"
Ok great we have 25 bytes from set name monitor and 22 bytes from set monitor 1
Client 4 connected
New thread created
Connection received. Parsing headers.
bytes read: 47
Message from socket #4: "set name monitor"
And boom. Both programs were doing their jobs, sending the correct number of bytes every time and reading the correct number. However, the VB application is sending them so quickly back to back that my server was reading all 47 bytes at a time instead of the separate 25 and 22 bytes.
Solution
I solved this problem by implementing a secondary buffer in my server to store off all bytes after the first message should multiple messages by group like this. Now I check if my secondaryBuffer is empty before reading in new bytes.
Here is a portion of the code used to solve the problem
/*Byte Check*/
for (j=0; j < bytes; j++) {
if (j == 0)
continue;
if (readBuffer[j] == '\x81' && readBuffer[j-1] == '\x00' && readBuffer[j-2] == '\x00') {
secondaryBytes = bytes - j;
printf("Potential second message attached to this message\nCopying it to the secondary buffer.\n");
memcpy(secondaryBuffer, readBuffer + j, secondaryBytes);
break;
}//END IF
}//END FOR LOOP
/**/

usb cdc device driver

I have CDC device. I develop driver for him.
Part of ini file:
[ClassInstall32]
CopyFiles=ClassInstall.CopyFiles
AddReg=ClassInstall.AddReg
[ClassInstall.CopyFiles]
My_USBDriver.dll,,,0x2000
[ClassInstall.AddReg]
HKR,,,,%DEVICEMANAGERCATEGORY%
HKR,,Icon,,"102"
HKR,,Installer32,,"My_USBDriver.dll,MyUSBPortsClassInstaller"
HKR,,NoInstallClass,,1
[DriverInstall]
include=mdmcpq.inf
CopyFiles=DriverInstall.CopyFiles
AddReg=DriverInstall.AddReg
[DriverInstall.CopyFiles]
usbser.sys,,,0x2000
[DriverInstall.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,%DRIVERFILENAME%.sys
[DriverInstall.Services]
AddService=usbser, 0x00000002, DriverService
[DriverService]
DisplayName=%SERVICE%
ServiceType=1
StartType=3
ErrorControl=1
ServiceBinary=%12%\%DRIVERFILENAME%.sys
Installer function have code:
c->ConnectionIndex = iPort;
c->SetupPacket.bmRequest = 0x80;
c->SetupPacket.wValue = (USB_STRING_DESCRIPTOR_TYPE<<8)|descriptorNum;
c->SetupPacket.wLength = n;
Success = DeviceIoControl(
hRoot,
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION,
c, n,
c, n,
&returnBytes,
NULL);
///Sometime GetLastError == 31 // Device not working
This code normal work on desctop(PC) always, but only sometime work on laptop(notebook) during the installation the device(installation function calling by system). OS of these mashines is Windows7.
BUT if i call installation function from my progrm(created for debuggin) this code always work correctly (on notebook and on pc).
Does anyone have ideas on this issue?
You said Desktop and Laptop, but I don't think the shape of the computer matters. Is one 32 bit OS and the other is 64 bit? I don't see the 64bit INF section.

Unable to change the system zone setting on Windows Server 2008 R2

I have an MFC application that tries to change the system zone setting on the Windows Server 2008 R2. I am using the SetTimeZoneInformation() API which fails with the error code 1314 .i.e. “A required privilege is not held by the client.”. Please refer the sample code below:
TIME_ZONE_INFORMATION l_TimeZoneInfo;
DWORD l_dwRetVal = 0;
ZeroMemory(&l_TimeZoneInfo, sizeof(TIME_ZONE_INFORMATION));
l_TimeZoneInfo.Bias = -330;
l_TimeZoneInfo.StandardBias = 0;
l_TimeZoneInfo.StandardDate.wDay = 0;
l_TimeZoneInfo.StandardDate.wDayOfWeek = 0;
l_TimeZoneInfo.StandardDate.wHour = 0;
l_TimeZoneInfo.StandardDate.wMilliseconds = 0;
l_TimeZoneInfo.StandardDate.wMinute = 0;
l_TimeZoneInfo.StandardDate.wMonth = 0;
l_TimeZoneInfo.StandardDate.wSecond = 0;
l_TimeZoneInfo.StandardDate.wYear = 0;
CString l_csDaylightName = _T("India Daylight Time");
CString l_csStdName = _T("India Standard Time");
wcscpy(l_TimeZoneInfo.DaylightName,l_csDaylightName.GetBuffer(l_csDaylightName.GetLength()));
wcscpy(l_TimeZoneInfo.StandardName,l_csStdName.GetBuffer(l_csStdName.GetLength()));
::SetLastError(0);
if(0 == ::SetTimeZoneInformation(&l_TimeZoneInfo))
{
l_dwRetVal = ::GetLastError();
CString l_csErr = _T("");
l_csErr.Format(_T("%d"),l_dwRetVal);
}
The MFC application has been developed using Visual Studio 2008 and is UAC aware i.e. the application has UAC enabled in its manifest file with the UAC execution level set to “HighestAvailable”. I have administrator privileges and when I run the application it still fails to change the system zone setting.
Thanks in Advance,
Ganesh
You do not need to be running as an administrator to change the time zone. According to the documentation, you do need the SE_TIME_ZONE_NAME privilege, however. The document I linked to has a sample of how to enable the privilege, but it mostly involves calling AdjustTokenPrivileges on your process's access token.