Read and set Group Policy settings from MFC program? - winapi

I want to be able to read and later set the Group Policy settings via a MFC program.
Here's what I would do manually. Run gpedit.msc as administrator and in the "Local Group Policy Editor" I'll go to
Computer Configuration->Administrative Templates->windows Components->Windows Update->Specify intranet Microsoft update service location
and set the update service location http://192.168.1.1:8530
Is there any way to do the same form a MFC program? Any code samples would be greatly appricated!

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\UseWuServer: REG_DWORD set to 1
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUServer: REG_SZ set to http://192.168.1.1:8530
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUStatusServer: REG_SZ set to http://192.168.1.1:8530
i run gpedit.msc and look (under debugger and in regedit finally, on several windows versions(from xp up to win 10)) what is doing if Microsoft update service location set - new 2 keys created(if yet not exist) - HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate and HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU and WUServer, WUStatusServer, UseWuServer is set
than by key/value names - found this - Configure Automatic Updates using Registry Editor

Related

Windows 10 Compatibility Mode | Registry Key

I'm currently packaging an application to run in compatibility mode. I easily found the location where the registry keys are created in the HKLM (for all users) or HKCU (for only the logged on user).
The problem is; which I really don't know if it's a problem, I can set the registry key in HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers. I create a REG_SZ with the name of the key being the path.
E.G.: C:\Program Files (x86)\MyApplicationDirectory\MyApp.exe
The value of this key is ~WIN7RTM
The problem is this, when I install the application and I create a registry key with this path. I can click on the shortcut properties and go into the Compatibility Tab and noticed it does not appear it's set to run in Compatibility Mode in Windows 7.
I know I created the correct registry key because I originally created the shortcut through the compatibility tab and clicked "Change Settings for All Users" and then set it to run in Windows 7 there. If I set compatibility mode within the shortcut, I can see it checked. (highlighted in yellow)
But if I try to set compatibility mode via the registry key and I go into the properties of the EXE or shortcut, the box is not checked.
If I set the registry key, how do I verify the application is running in compatibility mode?
Is there another way I can set the registry key and be sure it's running in compatibility mode?
Never mind folks. I did a stare and compare on the registry keys that is created. I did not add a space between the ~ and WIN7RTM. Once I added a white space, it worked fine.
Before: ~WIN7RTM (not correct)
After: ~ WIN7RTM (correct)
Overlooked it.

Crashing Windows 7 using batch

I came across this link : https://vmxp.wordpress.com/2014/10/29/stress-testing-an-esxi-host-with-windows-server-vms/
.Since I am not so good in powershell i turned the whole thing to a simple batch script:
:loop
start testlimit64 -d
timeout /t 15
taskkill /f /im "testlimit64.exe"
timeout /t 9
goto loop
Note that I got into SYSTEM ACCOUNT before doing that using PsExec. The system I am using is a VM under ESXi. But nothing is happening, even the vm is not crashing. My aim is to crash whole esxi server.
I have two VMs under the ESXi and I ran the above scripts in both of them.
Still no luck. Am I missing something?
Windows 2000 Feature Allows a Memory.dmp File to Be Generated with Keyboard
Q244139
The information in this article applies to:
Microsoft Windows 2000 Advanced Server
Microsoft Windows 2000 Datacenter Server
Microsoft Windows 2000 Professional
Microsoft Windows 2000 Server
IMPORTANT: This article contains information about editing the registry. Before you edit the registry, make sure you understand how to restore it if a problem occurs. For information about how to do this, view the "Restoring the Registry" Help topic in Regedit.exe or the "Restoring a Registry Key" Help topic in Regedt32.exe.
SUMMARY
Microsoft Windows 2000 includes a feature that enables you to have the system stop responding and generate a Memory.dmp file (if configured to do so). The "Stop" screen that generates contains the following parameters:
*** STOP: 0x000000E2 (0x00000000,0x00000000,0x00000000,0x00000000)
The end-user manually generated the crashdump.
MORE INFORMATION
WARNING: Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use Registry Editor at your own risk.
For information about how to edit the registry, view the "Changing Keys and Values" Help topic in Registry Editor (Regedit.exe) or the "Add and Delete Information in the Registry" and "Edit Registry Data" Help topics in Regedt32.exe. Note that you should back up the registry before you edit it. If you are running Windows NT or Windows 2000, you should also update your Emergency Repair Disk (ERD).
This feature is disabled by default. To enable this feature, you must edit the registry as indicated below and restart the computer. After restarting the computer, you can generate a system to stop responding by holding down the right CTRL key and pressing the SCROLL LOCK key twice. Pressing left CTRL key does not generate the system to stop responding.
Please note that the steps below will not work on Legacy Free computers, i.e., those that use a USB keyboard. For those, you must attach a debugger.
Start Registry Editor (Regedt32.exe).
Locate the following key in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\i8042prt\Parameters
On the Edit menu, click Add Value, and then add the following registry value:
Value Name: CrashOnCtrlScroll
Data Type: REG_DWORD
Value: 1
Quit Registry Editor.
Additional query words: blue screen force dump bluescreen crash memory.dmp
For USB keyboards a USB one was added in a later OS. This sets Left Ctrl + Space, Spece for both USB (kbdhid) and PS/2 (i8042) keyboards.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\i8042prt\crashdump]
"Dump1Keys"=dword:00000020
"Dump2Key"=dword:0000003D
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\kbdhid\crashdump]
"Dump1Keys"=dword:00000020
"Dump2Key"=dword:0000003D
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\i8042prt\Parameters]
"CrashOnCtrlScroll"=-
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\kbdhid\Parameters]
"CrashOnCtrlScroll"=-

Windows uninstaller isn't running as Admin

I've made a custom installer / uninstaller. I register the uninstaller with the Windows Registry as described in the MSDN Library, Chaper 2. Install/Uninstall.
Namely, this means registering uninstall.exe as the UninstallString. It works, in that it runs my uninstaller. The problem is that it doesn't invoke as admin. I've set uninstall.exe's manifest to require admin using mt, and if you double-click it from explorer, it will automatically request admin as desired.
So the question is, what's the magic flag I need to set in the registry to get the Windows Add / Remove Programs dialog to run my uninstaller as admin?
You could add checking for admin privileges inside your uninstall program. Check this question for more ideas on how to do it. The easiest of the mentioned options is using a shortcut to your program and ticking the option "Run as administrator".
The other solution is to make a registry entry inside HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers and add a REG_SZ path to your executable as the value, and "RUNASADMIN" as data.
More info in this answer here.

Windows 7: Set "Copy Settings" programmatically from a batch file

I'm constructing a batch file that will auto-configure Windows 7's regional settings for all users.
So far, I've successfully been able to set (mostly) all of the regional settings for the current user, but I need to be able to apply the same settings to all new users. You can do this via the GUI, by going into Region and Language > Administrative > Copy Settings and selecting both checkboxes. I would like to do this programmatically, though. Does anyone know of a registry key I can set or something that will do this?
Failing that, I'll settle for a way to programmatically open the Region and Language > Administrative > Copy Settings window. I've been able to successfully open the Region and Language > Administrative window with start rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,3, but I would like to eliminate one more step from the process, if possible.
Update
Sorry, I seem to have forgotten to mention how I'm applying these settings. I'm doing this by executing an exported .reg file, that contains the optimal settings, with regedit.exe /s "regional.reg"
How are you applying the settings now? Via the registry?
If you put the settings under HKEY_USERS\.DEFAULT instead of (or in addition to) HKEY_CURRENT_USER, they should be used during profile creation.

Creating Windows Startup Services via REG or Command Line

I have a Java program which needs to be a startup program that runs as administrator. It seems that cannot be done without making it a service. I have tried using HKLM\SYSTEM\CurrentControlSet\Services\Services\MyService. I tried something similar to what Google Updater uses (they use ...\Services\gupdate). The process does not start (or at least it stops right away, which I cannot tell for sure.
I think it is something wrong with how I am using the registry because the service does not show up in msconfig.exe under the Services tab. Also it doe not show up in the Control Panel "View local services" (Windows 7, found in the Start Menu search for "services")
I tried a much simpler approach found here. I create a .reg file with these contents.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService]
"Description"="My Service starts the Special Process."
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\Parameters]
"Application"="C:\\Test\\MyProcess.cmd"
I am willing to consider an alternative command-line alternative if necessary, but I like the registry approach because if I tell my installer to add certain registry items, it will automatically remove those items on uninstall.
Is there any reason that above .reg file would not add an item to msconfig that is named "MyService"?
The program which I wrote is written in Java. It does not have a GUI interface.
You can create a service by editing the registry, but (as should be apparent) you must have a service executable associated with the service. Reg Add will allow for the addition of these keys/values.
The registry must be reloaded by the system before the service is recognized, I find a reboot gets the job done.
Add the key ServiceName to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\.
Next add the following values within the ServiceName key:
DisplayName - REG_SZ - Sample Service
Description - REG_SZ - This Service is the Hello World Service!
ErrorControl - REG_DWORD - 1 (decimal)
ImagePath - REG_EXPAND_SZ - C:\ProgramData\Program\service_executable.exe
ObjectName - REG_SZ - Username_For_Execution (often LocalSystem)
Start - REG_DWORD - 2 (decimal) (this varies according to the desired start behavior)
Type - REG_DWORD - 16 (decimal)
The following websites were helpful in decoding the meaning of the various values:
Using the registry editor to change the service state
What are the ErrorControl, Start and Type values under the Services subkeys?
Just root around inside the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ key for more examples!
If you want to run a program with administrative privileges, there is another way instead of using service.
You can use Task Scheduler, for example.
Also command line is available: SCHTASKS /create
You can't create a service by manipulating the registry. Nor can you run an arbitrary application as a service.
To run an arbitrary program from within a service, use the srvany.exe service available in the Windows Server 2003 resource kit. See KB137890 for instructions. If you want to write your own service, see this.
To create a service you can use the sc command line tool, or the instsrv.exe tool from the Windows Server 2003 resource kit. Or use the CreateService Win32 API function.

Resources