I want to set Lock Screen Wallpaper of Windows 10 and above from WPF application. I have searched and found the following links are useful.
https://stackoverflow.com/a/51785913/5523095
https://superuser.com/a/1274588
Based on the suggestion from the above answers I am trying to change the lock screen wallpaper using the following code.
RegistryKey key = Registry.CurrentUser.CreateSubKey(#"Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP", true);
key.SetValue(#"LockScreenImagePath", #"C:\Users\kumarm\Desktop\Wall.png");
key.SetValue(#"LockScreenImageUrl", #"C:\Users\kumarm\Desktop\Wall.png");
key.SetValue("LockScreenImageStatus", 1, RegistryValueKind.DWord);
key.Flush();
But the lock screen wallpaper is not changing. Am I doing anything wrong?
Your code creates the wrong key in the registry. Also instead of HKEY_LOCAL_MACHINE you use HKEY_CURRENT_USER. Should be like this:
RegistryKey key = Registry.LocalMachine.CreateSubKey(#"SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP", true);
key.SetValue(#"LockScreenImagePath", #"C:\Images\image.jpg");
key.SetValue(#"LockScreenImageUrl", #"C:\Images\image.jpg");
key.SetValue(#"LockScreenImageStatus", 1, RegistryValueKind.DWord);
key.Flush();
This code does work, but after that you cannot change the lock screen image in Windows settings - the possibility is blocked with the reference "Some of these settings are managed by your organization", which can be fixed by deleting registry keys or by setting empty "LockScreenImagePath" and "LockScreenImageUrl" values in the registry.
Related
I am trying to write a C# code, which will block exe files from running. I found a question about the same topic: example question. In the question suggested method is using these registry lines as below:
REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
"Debugger"="calc.exe"
However, this code doesn't look like any C# code I have ever seen. The answer talks about "adding a registry key" and "exported registry key". However, when I search those terminologies on the internet, I could not find any clear explanation about the topic for a beginner Windows developer like me.
For example this question add registry key question wrote a C# function with two inputs.
void exportRegistry(string strKey, string filepath)
I tried to use this function inside my main Winform constructor as below, but nothing happened - I could still open notepad.exe with no problem (which is the main aim of the code)
this.exportRegistry("\"Debugger\" = \"calc.exe\"", "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\notepad.exe]");
What am I doing wrong? I really thought I have enough coding skill for this problem, but I am stuck.
After I searched for some time, I found a way to achieve it. I can know stop programs running by changing the registery for windows. This code stops notepad.exe from running. It does it by adding several registery keys with the C# code. The logic behind it given in this link Explanation. It might not be the best way but it does stop programs running.
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true);
key.CreateSubKey("Microsoft");
key = key.OpenSubKey("Microsoft", true);
key.CreateSubKey("Windows");
key = key.OpenSubKey("Windows", true);
key.CreateSubKey("CurrentVersion");
key = key.OpenSubKey("CurrentVersion", true);
key.CreateSubKey("Policies");
key = key.OpenSubKey("Policies", true);
RegistryKey explorerKey = key.CreateSubKey("explorer");
key = key.OpenSubKey("explorer", true);
explorerKey.SetValue("DisallowRun", 0x00000001, RegistryValueKind.DWord);
RegistryKey disallowRun = key.CreateSubKey("DisallowRun");
key = key.OpenSubKey("DisallowRun", true);
disallowRun.SetValue("1", "notepad.exe", RegistryValueKind.String);
I have the following problem,
I want to open the LongPathsEnabled key to change its value using c# Registry (using Microsoft.Win32). This is the usual key that exists on windows 10.
so far reading it is no problem:
int valueoflongPaths = (int)Registry.GetValue(#"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem", "LongPathsEnabled", null);
but I get a problem when setting it. I want to set it to 1:
RegistryKey key=Registry.LocalMachine.OpenSubKey(#"SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled", true);
key.SetValue("Value", (int)1);
key.Close();
i get the following error: Object reference not set to an instance of an object.
so far when I google the problem I only find examples of creating keys that don't exist and not of existing usual keys.
Am I missing something here?
I use .NET 4.6 and windows 10
Thanks
I'm developing a desktop application, and I want to make a small browser with the possibilities of change the version of WebBrowser (obviously is IE).
I tried with change the registry of my application .exe, for example for this:
11001 (0x2AF9) or 7000 (0x1B58)
(Regkey.SetValue("myApp.exe", 0x1B58, RegistryValueKind.DWord);
If I do an "alert" of my WebBrowser, i get 11.xxxxx, but this never is changed.
I'm exhausted of try several things and nothing is working.
Someone has any idea about it?
Sorry for my english.
Thanks in advance.
Best regards,
Diego.
EDIT:
I tried with this:
RegistryKey Regkey32 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(#"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
RegistryKey Regkey64 = null;
if (Environment.Is64BitOperatingSystem)
{
Regkey64 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(#"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
}
Regkey32.SetValue(Path.GetFileName(Application.ExecutablePath), versionIE, RegistryValueKind.DWord);
if (Environment.Is64BitOperatingSystem)
{
Regkey64.SetValue(Path.GetFileName(Application.ExecutablePath), versionIE, RegistryValueKind.DWord);
}
MessageBox.Show(webBrowser1.Version.ToString())
Return: 11.0.9600.16428 (always)...
Is possible change this version when we are changing the registry?
Im developing a custom browser solution with .net's Webbrowser control.
To disable the IE-Compatibilty View, I set the registry entry
Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION:
[Sreenshot regedit] http://zbirk.mirk.at/browserreg.png "Screenshot"
i tried to use the values: dword=8000,dword=8888,dword=9000, but the webbrowser control seems to ignore these reg entries.
Maybe someone had this problems too and may help me.
The WebBrowser control definately DOES respect these keys.
Remember that while taskman may show application.exe in the name column, if you are debugging the exe name is application.vshost.exe
So in my application sI just attempt to create the key every time the app runs. If it fails to create it (because it already exists) then I continue running, if it creates the key then I inform the user that they need to restart the application.
ensure that you are not running within vshost
the app name would be different ie appname.vshost.exe
Thx for your reply, now its working.
Her is my working peace of code:
public void setIEcomp()
{
String appname = Process.GetCurrentProcess().ProcessName+".exe";
RegistryKey RK8 = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION",RegistryKeyPermissionCheck.ReadWriteSubTree);
int value9 = 9999;
int value8 = 8888;
Version ver = webBrowser1.Version;
int value = value9;
try
{
string[] parts = ver.ToString().Split('.');
int vn = 0;
int.TryParse(parts[0], out vn);
if (vn != 0)
{
if (vn == 9)
value = value9;
else
value = value8;
}
}
catch
{
value = value9;
}
//Setting the key in LocalMachine
if (RK8 != null)
{
try
{
RK8.SetValue(appname, value, RegistryValueKind.DWord);
RK8.Close();
}
catch(Exception ex)
{
//MessageBox.Show(ex.Message);
}
}
}
I too could not see that FEATURE_BROWSER_EMULATION made any difference in my application.
I was testing the FEATURE_BROWSER_EMULATION functionality by manually editing the registry with regedit. Nothing I did made any difference. My hosted page was still failing on any new-ish JavaScript and could not load external libraries.
I found my mistake:
I was editing the 64-bit view of the registry with regedit. My app was running as a 32-bit app and looking at the 32-bit view of the registry. That's why my changes to the registry seemed to have no impact on my application. By the way, the WPF project template defaults to "Prefer 32-bit."
Manually editing with regedit within the Wow6432Node key worked:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
Of course, setting the DWORD value programmatically within your application will also work, since your 32-bit application will edit within the Wow6432Node.
An older post and solution is no longer accurate.
Running procmon and watching for FEATURE_BROWSER_EMULATION shows the following registry variables actually checked. This was for WINWORD.exe but other than that - take your pick...
HKU\S-1-5-21-[my-sid-paws-off]\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\WINWORD.EXE
HKU\S-1-5-21-[my-sid-paws-off]\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION*
HKLM\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION(Default)
HKLM\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\WINWORD.EXE
HKLM\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\WINWORD.EXE
HKLM\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION*
HKLM\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION*
// Edit:
oh wow. It's odd that I've been working on this for a day now and just realized I needed to do:
key = key.OpenSubKey(#"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
And then everything worked. I did not know that you had to do that. Thanks for everyone that responded. I was just messing around and searched for my key and noticed it was being placed in the wrong spot.
// Original question:
I haven't seen a working solution for this and I'm not sure if it's a bug.
I have a C# 32-bit Windows service running on Windows 7 64-bit. My goal is to write to the 64-bit registry and not the Wow6432Node subkey since for AutoAdminLogon a 64-bit system doesn't seem to check the 32-bit view of the keys.
So my code is as follows:
static public void LoginAsGuest(EventLog eventLogger)
{
RegistrySecurity userSecurity = new RegistrySecurity();
RegistryAccessRule userRule = new RegistryAccessRule("Everyone", RegistryRights.FullControl, AccessControlType.Allow);
userSecurity.AddAccessRule(userRule);
var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
key.OpenSubKey(#"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", RegistryKeyPermissionCheck.ReadWriteSubTree);
if (key == null)
{
eventLogger.WriteEntry("Error accessing the registry key");
}
else
{
try
{
key.SetValue("AutoAdminLogon", "1", RegistryValueKind.String);
key.SetValue("DefaultUserName", "guest", RegistryValueKind.String);
key.SetValue("DefaultPassword", "password", RegistryValueKind.String);
}
catch (Exception exception)
{
eventLogger.WriteEntry("Problem setting up keys: " + exception);
}
}
key.Close();
Reboot();
}
No exception or error is thrown. Nothing is written to the registry in the 32-bit or 64-bit view. I've tried using:
key.OpenSubKey(#"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
But it has the same outcome. Now if I just write without any view then my program successfully writes to the subkey:
SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon
Basically all I want is to write to the subkey:
SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Anyone know why the above code isn't writing to the requested key? (I will point out that AutoAdminLogon and the other two keys are used by the windows default credential provider such that when windows starts it checks those keys and if AutoAdminLogon is set to 1 then it logs in automatically with the given username and password. I'm doing this to allow a computer to be logged in as guest by setting the keys then rebooting the computer).
It's odd that I've been working on this for a day now and just realized I needed to do:
key = key.OpenSubKey(#"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
And then everything worked. I did not know that you had to do that. Thanks for everyone that responded. I was just messing around and searched for my key and noticed it was being placed in the wrong spot.