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

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.

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.

ERROR_INVALID_PRINTER_NAME returned by OpenPrinter() in Windows 8 when executed under "SYSTEM" account

My application deletes virtual printer when user uninstalls the application.
Application's installation and Uninstallation can be done using user interaction(wizard) or by setting group policy in Windows server 2003(domain admin sets the policy in server and the domain user in client PC need to update the group policy and restart the Client PC for installation or uninstallation of the application).
The follwing code in the application deletes printer and printer driver when uninstalling the application.
void CPrinterDriver::DeletePrinterIfExists()
{
// Delete old printer driver if existing
ControlSpoolService(TRUE);
HANDLE hPrinter = NULL;
PRINTER_DEFAULTS pDefaults = { NULL, NULL, PRINTER_ALL_ACCESS };
// Ignore error codes
OpenPrinter(m_driverInfo.pName, &hPrinter, &pDefaults);
if (hPrinter)
{
// deleting jobs
SetPrinter(hPrinter, 0, NULL, PRINTER_CONTROL_PURGE);
// Delete printer
DeletePrinter(hPrinter);
// Get printer driver name and delete it
DWORD dwNeeded = 0;
GetPrinter(hPrinter, 2, NULL, 0, &dwNeeded);
if (dwNeeded)
{
PRINTER_INFO_2 *pi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, sizeof(PRINTER_INFO_2)*dwNeeded);
if (pi2)
{
GetPrinter(hPrinter, 2, (LPBYTE)pi2, dwNeeded, &dwNeeded);
DeletePrinterDriver(NULL, NULL, pi2->pDriverName);
GlobalFree(pi2);
}
}
ClosePrinter(hPrinter);
}
}
The above code works well in Windows 7 in both cases(user interactive installation and using group policy) of uninstallation. In Windows 8, it works well using user interactive installation and uninstallation.
But in Windows 8 the above OpenPrinter() is returing ERROR_INVALID_PRINTER_NAME.
We found that the OpenPrinter() is called using the "SYSTEM" account.
Kindly help.
We found that during system startup, group policy is trying to uninstall the printer before the available printers list in the PC is populated (list is populated under the below registry key.If the list is not populated the below key does not exists).
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers"
Hence we added delay of 2 minutes(not less than 2 mins) before calling openPrinter().
After the delay the registry key exists and the OpenPrinter() succeeded.
Thus we are able to uninstall the printer.
Note: Microsoft claims that Windows 8 boot time is reduced to 7 secs for certain supported hardware. But inserting delay of 2 mins degrades the boot performance of the Windows 8 PC.
For more details regarding the improvement in the boot time of Windwos 8 OS please refer the below link.
http://blogs.msdn.com/b/b8/archive/2012/05/22/designing-for-pcs-that-boot-faster-than-ever-before.aspx
Hence delay of 2 mins can be terated as a workaround.
Need to check the behaviour in the Windows 8 OS release after 10/26.
If you suffer from the issue where:
the registry key for the shared (network) printer is missing and
the API gives you the invalid printer name error
Then you can try opening the printer by its full UNC path.
So when opening MYPRINTER does not work, then open it as \\MYSERVER\MYPRINTER .
Of course this still assumes that you can already print to this printer normally from other applications!

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

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

Can you prevent SndVol from displaying empty audio session?

I've been playing around with Vista's CoreAudio stuff, in particular IAudionSessionEvents, with the goal of monitoring the default audio session for changes to volume caused by loaded code.
However, it looks like as soon as you install an IAudioSessionEvents listener SndVol lists the program with all associated volume controls. As a good portion of the time no code has been loaded that will actually play anything, this is less than ideal.
Basically, is there some way to monitor the default audio session without causing SndVol to list it?
A solution for Vista is preferred, but something depending on new apis provided in Windows 7 is better than nothing.
Larry Osterman pointed out the ISessionManager2 and IAudioSessionNotification interfaces added in Windows 7. However, I never receive notice of new session. Is anyone aware of gotchas or problems with this API under Windows 7 build 7000?
Code registering IAudioSessionNotifications, omitting lots of error checking code*:
BOOL success = false;
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;
IAudioSessionManager2* pManager = NULL;
IClassFactory* pFactory = NULL;
hr = CoInitialize(NULL);
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
pDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&pManager);
listener = NULL;
hr = CoGetClassObject(CLSID_CustomFactory, CLSCTX_ALL, NULL, __uuidof(IClassFactory), (void**)&pFactory);
hr = pFactory->CreateInstance(NULL, __uuidof(IAudioSessionNotification), (void**)&listener);
hr = pManager->RegisterSessionNotification(listener);
*While not the purpose of this question, constructive critic of my COM code is welcome.
If you want to monitor the audio session stuff, you should use the IAudioSessionManager interface to retrieve your IAudioSessionControl object. A session only shows up in SndVol when it transitions from the inactive to the active state - that happens when when someone calls IAudioClient::Start() - as long as you don't call IAudioClient::Start you shouldn't get a session slider.
In Windows 7, there are a new set of APIs (IAudioSessionManager2) that allow you to listen for session creation and destruction.
Also for Windows 7, there is the AUDCLNT_SESSIONFLAGS_HIDE flag (the documentation for this hasn't been updated yet but it's in the headers)