I'm trying to change some registry settings using an AutoIt script. The regWrite() method returns 1, which means that it was successful and when I call RegRead() on the same key it gives me the value that I passed into RegWrite(), but the value in does not change in regedit, even if I reboot the computer. I tried it on more than 10 keys and none of them really changed.
Sample code:
This is just one of the values I tried to change:
#RequireAdmin
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\ESET\Setup\CurrentSession","RebootSignal","REG_DWORD","0x00000000")
You should use
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\ESET\Setup\CurrentSession","RebootSignal","REG_DWORD",0x00000000)
or
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\ESET\Setup\CurrentSession","RebootSignal","REG_DWORD",0)
Related
I have created a reg-file in order to change the value of an entry in the registry:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\...]
"InstallPath"="C:\kkk"
The ... above continues to the full path in my reg-file.
The data-type of this entry is REG_SZ, so I have omitted it.
Executing this file does not seem to change the value of that entry.
Does anybody recognize this problem or have any idea where it stems from?
Problem solved by changing "C:\kkk" to `"C:\\kkk" (i.e., was missing a backslash).
I store my settings using QSettings class and sometimes, it gives me a strange behavior.
I use this to add a value :
QSettings _settings("MyCompany", "AppName")
_settings.setValue("lastfile", "SomeString");
And this to remove all values :
QStringList indexes = _settings.allKeys();
foreach(QString index, indexes)
_settings->remove(index);
And it seems to work randomly. Sometimes it add or remove the value to the .plist file (I checked it using _settings.fileName()) and sometimes nothing change.
My question, which is kind of implicit, is what am I missing and how to make it work normally?
Set the format with: -
QSettings::setDefaultFormat(QSettings::NativeFormat);
In VB.NET I can create a key in the Windows Registry like this:
My.Computer.Registry.CurrentUser.CreateSubKey("TestKey")
And I can check if a value exists within a key like this:
If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\MyKey", _
"TestValue", Nothing) Is Nothing Then
MsgBox("Value does not exist.")
Else
MsgBox("Value exist.")
End If
But how can I check if a key with a specific name exists in the Registry?
One way is to use the Registry.OpenSubKey method
If Microsoft.Win32.Registry.LocalMachine.OpenSubKey("TestKey") Is Nothing Then
' Key doesn't exist
Else
' Key existed
End If
However I would advise that you do not take this path. The OpenSubKey method returning Nothing means that the key didn't exist at some point in the past. By the time the method returns another operation in another program may have caused the key to be created.
Instead of checking for the key existence and creating it after the fact, I would go straight to CreateSubKey.
I use this code. It’s simple, easy, and it works on HKEY_CURRENT_USER\Software\YourAppSettings.
Code:
string[] kyes=Registry.CurrentUser.OpenSubKey(#"Software\YourAppSettings").GetValueNames();
if (!kyes.Contains("keytoknowIfExist"))
{
}
Thanks for the information - this helped me a lot! I did notice while I am in the Visual Studio development module however, the settings were being saved under Computer\HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Elementary\Backup - not the same as the finished Installed Software. I am using ie. SaveSetting("Elementary", "Backup", "BackupFile", bdbname)
Since I didn't know exactly where my settings would be saved in the registry once my product was completed, I tried this and it worked perfect for me. I didn't have to know the exact location, which was helpful.
If GetSetting("Elementary", "Backup", "BackupFile", Nothing) <> Nothing Then
DeleteSetting("Elementary", "Backup", "BackupFile")
bdbname = ""
End If
Anyway, hope it helps someone in the future...
I've already known how to add specific extension to the New Menu in Windows 7 with regedit, but now I want to add the type FILE (i.e. pure file without an extension), how can I do it?
Ah, I got it right with google. Here is the solution:
1. Create a key of any extension or just a '.' in the HKEY_CLASSES_ROOT, and make the default value 'genericfile'
2. Create the ShellNew in the extension you just created
3.Create a string in the ShellNew with the name 'NullFile' and the value empty
4.Create the key 'Config' in the 'ShellNew' and a string in the config with the name 'NoExtension' and value empty
5.Create the key 'genericfile' in the HKEY_CLASSES_ROOT, and make the default value the text you want to display in your new context value (Such as "New Empty File")
Wish helps you a lot :-)
Here is a registry script based on lichenbo's answer.
It uses .emptyfile to avoid conflicts. Using . registry key could cause strange issues. The file will still be created with no extension due to the NoExtension value.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\emptyfile]
#="Empty File"
[HKEY_CLASSES_ROOT\.emptyfile]
#="emptyfile"
[HKEY_CLASSES_ROOT\.emptyfile\ShellNew]
"NullFile"=""
[HKEY_CLASSES_ROOT\.emptyfile\ShellNew\config]
"NoExtension"=""
I am writing a script to capture the login time. In the final production, there would be no input from any user. However I am testing it and I wanted to know how I add extra code to determine that
If its in 'debug' mode AND
The user that is logging in is me (lets say my username is joe.smith on the domain called EXAMPLE)
then present an input box to allow me to type the date, time for logging in.
All other users would never see this and it would capture today with the system time.
I would also like to hide the code so if the script is opened by the wrong person, they wouldnt be able to make heads or tails of whats going on.
You can use a command line parameter as Matt says to set the script into debug mode, eg
dim isdebug: isdebug = WScript.Arguments.Named.Exists("debug")
WScript.Echo("in debug mode: " & isdebug)
Which you can invoke with
wscript debugscript.vbs /debug
To get the current user name, you can use either the WMI Service or the WScript.Network object.
Once you have the username, you can conditionally throw up an InputBox and collect the value returned:
dim date_: date_ = Now()
if isdebug and username = "me" then
dim value: value = CDate(InputBox("enter the date and time (dd/mm/yyyy hh:mm:ss)", "please", Now()))
' validate the input here
date_ = CDate(value)
end if
And finally, to obfuscate your code you could use the Scripting.Encoder although it looks like this doesn't seem to be supported on Vista or Windows 7. There does seem to be a few hits on googling the phrase obfuscating vbscript, anyway.
Most of this sounds like it can be resolved by the logic of the script.
Have a command line parameter (debug is an appropriate name) and then have some if logic in the code to do as you wish (present the input box).
For the code obfuscation, I don't know how this could be done in vbscript. Windows scripting host works with JavaScript as well though and there are plenty of tools on the web for making JS harder to read. Maybe you want to look a using JS...
HTH,
Matt
I think you can check the property App.LogMode to see if you are in 'debug' mode or not. If it is 0 then you are running debug mode and if it is 1 you are not.