Any replacement for IAutomaticUpdates :: pause in Windows 10? - winapi

In earlier versions of Windows this paused automatic updates:
IAutomaticUpdates *automaticUpdates = 0;
HRESULT hr = CoCreateInstance(CLSID_AutomaticUpdates, NULL, CLSCTX_ALL, IID_IAutomaticUpdates, (void**)&automaticUpdates);
if (automaticUpdates != NULL)
{
hr = automaticUpdates->Pause();
}
According to MSDN, "IAutomaticUpdates::Pause is no longer supported. Starting with Windows 10 Insider Preview calls to Pause always return S_OK, but do nothing." IAutomaticUpdates::Pause
We don't want Windows Update interrupting our program. Does anyone know of a workaround?

With Windows 10 a bunch of settings are no longer available. Here the settings of the update service are now no longer free to set by the user.
Because you need administrative rights to even call Pause, you may stop the Windows Update Service at all. But this is a very harsh way to prevent the update service to interrupt you. I wouldn't recommend this a a real practical solution for me. But it may help you.

Related

Direct3DCreate9Ex returns D3DERR_NOTAVAILABLE (0x8876086a) when running as Windows Service

For some reasons, I have to create D3D9 in my program, which is running as a service.
But I got D3DERR_NOTAVAILABLE for the following code:
ATL::CComPtr<IDirect3D9Ex> d3d9 = nullptr;
HRESULT hr = ::Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9);
And it works if it's not running in a service.
I saw someone success to do this by checking Allow service to interact with desktop in the Control Panel, but it doesn't work for me.
Is there any setting I have to mention?
In Windows Vista and later, Windows Services run in an isolated context (called 'session 0 isolation') to reduce threats from malware. In some cases, you can create a NULL device and possibly a WARP device, but Direct3D GPU access from a Windows Service is not available until Windows 8.
See KB 978635

Visual Studio C++ RegOpenKeyEx() registry Access is denied error Windows 7 64 bit

I'm running a C++ program (which works great on 32 bit Win XP) on Windows 7 64 bit in debugger under Visual Studio 2010 and I am unable to open an existing registry key with the following code:
#define ACCESS (KEY_WRITE | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS)
HKEY hKey;
long dwErrorCode = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\MYTHING", 0, ACCESS|KEY_WOW64_64KEY, &hKey);
if (dwErrorCode != ERROR_SUCCESS)
{
// display error message
}
The error code returned is: 5 with the system message being "Access is Denied".
This does work if I run the Visual Studio 2010 as Admin, however I'd rather not have to do that. Can anybody offer a suggestion?
Update: I forgot to mention, what I am doing here is porting legacy code from Windows XP. As such, I don't have the option of changing the fundamental structure of how this software was written. Since the legacy code uses the registry, that is what the ported code must do also.
Also, I would rather not make changes to my specific computer -- since that means I would have to change every computer that I want to run this on. This could get messy as there are a lot of machines affected. For example, I don't want to turn off UAC for the entire machine.
Further update: I haven't found a solution that I'm happy with. Have decided to ignore error code 5 for purposes of debugging and that seems to be working well enough for now. I'm trying to understand how standard apps like Word, Firefox, etc appear to be using the registry for all kinds of settings and yet are not elevated nor do I have to give them special permissions to make changes to the registry?
Ok, I found the answer to my question so I'll post it here in case anybody else needs it for future reference. This thread turned out to be helpful even though it is actually on the topic of C#:
http://social.msdn.microsoft.com/Forums/da-DK/netfx64bit/thread/92f962d6-7f5e-4e62-ac0a-b8b0c9f552a3
Basically, I needed to change my permission to read the 32 bit registry instead of the 64 bit one like so:
HKEY hKey;
long dwErrorCode = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\MYTHING", 0, ACCESS|KEY_WOW64_32KEY, &hKey);
if (dwErrorCode != ERROR_SUCCESS)
{
// display error message
}
Voila, everything works now! Thanks for your efforts everyone.
Update: it turns out this didn't work as well on my other machine, which led me to discover that someone must have changed access rights to the 32 bit registry on one of my machines. So it is still necessary to give the User access rights to the registry key you want to work with.
You need to run the process in elevated mode, or turn off UAC. You can of course assign access rights to your specific registry key that allows you access.
I have faced same issue. I have solved using following:
LPCTSTR subKey = TEXT("Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths");
LONG openRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, subKey, 0, KEY_WOW64_32KEY && KEY_ALL_ACCESS, &hKey);

Copy and paste problems with Word 2010 and Windows 7

I have a program which is able to exchange data with MS Office applications, via the clipboard.
This works fine in Office 2007 and Windows Vista/XP, but fails with Office 2010/Windows 7
IDataObject *d = NULL;
HRESULT hr = ::OleGetClipboard(&d);
if (hr == S_OK)
{
FORMATETC formatEtc;
formatEtc.cfFormat = ::RegisterClipboardFormat("Native");
formatEtc.ptd = NULL;
formatEtc.dwAspect = DVASPECT_CONTENT;
formatEtc.lindex = -1;
STGMEDIUM stgMedium;
hr = d->QueryGetData(&formatEtc);
Following this call, I am returned an error - 0x8004006a Invalid clipboard format
I have tried searching the web, but haven't found any relevant information. Any advice/suggestions would be gratefully received.
Thanks.
i have a similar issue in Office 2007 and Windows-server-2008, my guess the problem is not the office but rather the windows 7/2008. are you running your program as a service? or an as executable?
I'm still waiting for an answer for my question over here:
Clipboard Copy-Paste doesn't work in a service on Win Server 2008/Vista 64bit
please let me know if you have resolved your issue!
Update: i have found out that this is a sessions issue. try finding out if your app and the word/ other office app is running in the same session (try using process explorer for that).

Sending the message Ctrl+Alt+Del from my application

I want to write a small utility in MFC which sends the Ctrl+Alt+Del message to OS. Can any one help me how do I achieve this? I tried:
::PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG( MOD_CONTROL | MOD_ALT, VK_DELETE));
But this is not working.
I want to send Ctrl+Alt+Del not to invoke TaskMgr.exe. Also, it is for my local OS (Windows XP Service pack 2). Basically I want to use this application to lock my machine and schedule some actions along with locking.
This is not a keystroke you can simulate. It's called the "Secure Attention Sequence".
Here's how to invoke it FROM A REMOTE DESKTOP (XP+ solution):
include <shldisp.h>
IShellDispatch4 *pShell;
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER,
IID_IShellDispatch, (void**)&pShell);
if(SUCCEEDED(hr))
pShell->WindowsSecurity();
CoUninitialize();
The only solution to invoke it from the local desktop is to use SASLib. It's not public. Write a note to saslib#microsoft.com to request it.
EDIT: Wait! You want to lock the machine? Just call LockWorkStation()! Click the link for more info about header file, lib file et all other details.
Since VNC can let you do this to a remote system, it must be possible. If I were you, I'd trawl through the source to UltraVNC. Then I'd post the answer the here :)
Do you need to send control+alt+delete or do you just want to bring up the task manager?
If you just need to bring up the task manager you can simply run \Windows\System32\taskmgr.exe
I know it's an old questions but I am posting my solutions here in case someone looking for a solution arrives here. The part1 and part2 articles explain how Winlogon registers the CAD sequence and provides code examples on how to use it.
Send CAD and Unlock workstation for Windows XP - Part 1 (free)
Send CAD and Unlock workstation for Windows XP - Part 2 (free)
SasLibEx for Vista and higher (sorry, this is not free)
Wouldn't it be easier to just ask the machine to shut down or logout? That key combination isn't really a good idea? You can send these messages.
Can't you start a screensaver and it will take care of the locking for you? I don't have a Windows machine available right now, but I recall one could lock the workstation like this.
Call the SendSAS function to achieve this.

Which api functions to install a file system driver in Windows?

I want to install a driver for Ext2 partitions under Windows XP, the installation will be done with a self written Inno Setup script. Which API functions do I need to call for this? From what I googled so far I don't seem to be needing an inf file, and therefore no call to SetupCopyOEMInf. But I don't know what to do instead...
Please enlighten me!
As you asked which API functions are required to install a driver here is some code I use to load a driver in C:
bool LoadDriver( const char * cpDriverPath, const char * cpDriverName )
{
SC_HANDLE hSCService;
SC_HANDLE hSCManager;
hSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
if( hSCManager == NULL )
return false;
hSCService = CreateService( hSCManager, cpDriverName, cpDriverName,
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
cpDriverPath, NULL, NULL, NULL, NULL, NULL );
if( hSCService == NULL && GetLastError() == ERROR_SERVICE_EXISTS )
hSCService = OpenService( hSCManager, cpDriverName, SERVICE_ALL_ACCESS );
if( hSCService == NULL )
return false;
if( !StartService( hSCService, 0, NULL ) )
{
if( GetLastError() != ERROR_SERVICE_ALREADY_RUNNING )
return false;
}
CloseServiceHandle( hSCManager );
CloseServiceHandle( hSCService );
return true;
}
You probably want to use SERVICE_ BOOT_ START for a file system driver instead of SERVICE_ DEMAND_ START. If you cant write an Inno script to do the above you could always make a small EXE from the above and have Inno run that as a post installation.
If you want to go down the INF route, check out this Microsoft article.
All right, I found some more information:
The MSDN states that 'you should install your file system drivers by using an INF file' (by calling SetupCopyOEMInf etc), but also notes that on Win2k and older systems, 'file system drivers were commonly installed by the Service Control Manager'
And I found another Ext2 driver at sourceforge that comes with an Inno Setup installation script. There they just add a few registry entries under HKLM\SYSTEM\CurrentControlSet\Services\.
I believe that adding these entries is equal to creating a service with the sc.exe tool, which internally calls the OpenSCManager and CreateService api. I prefer the registry way, because it is easier and I see no advantage in using the api calls, since a reboot is always required.
So I ended up with this solution:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\YourService]
"ErrorControl"=dword:00000001
"Start"=dword:00000003
"Type"=dword:00000001
"DisplayName"="YourServiceDisplayName"
"ImagePath"="System32\Drivers\YourService.sys"
Of course depending on the specifics of the driver in question, some more entries in a Parameters subkey may be required.
I am still hoping that someone will be able to shed some more light on this question, specifically some details on how to use an inf file for the installation, since this is the way recommended by MS.
Come on, folks! There's a nice bounty to catch here!
There are a number of ways you could approach this.
1/ See if the product has a silent install mode (e.g., using a configuration file to install). Then you just incorporate that into your own install.
2/ There are programs that can emulate a user, such as Rational Robot (I wouldn't suggest that one since it's commercial, but there's likely to be free ones around). We mostly use these for automated testing of graphical applications but they can just as easily use it to run an installer.
3/ Contact the developer to see what the actual install process entails, then copy that.
4/ Microsoft has a number of system tools (here) that can track changes to the filesystem, registry and so on. You could use these to reverse-engineer the install process and do those same things in your own install.
Personally, I'd go with number 3 first. The developer would be happy to know their product is being used and may provide the information readily. They may even write a silent installer for you as this would be an extra selling point for their product in a corporate environment (suggest this to them).
I wrote a TDI filter driver.
When I came to write the .inf file, it took two weeks of sheer pain to get something working and I still didn't really understand it, because it didn't really make sense; what you had to do seemed very arbitrary. INF files were, when I was trying to use them, almost wholly undocumented and bizzarely complex.

Resources