List Separator script - vbscript

How can I change the List separator from the command line?
Normally I have to edit a field in: Control Panel → Change keyboards or other input methods → Additional settings
I would love to create a VBScript that I click which automatically changes from , to ;, and another one that goes back.

A single script should suffice. The setting is stored in the registry value HKCU\ControlPanel\International\sList and can be toggled with something like this:
Set sh = CreateObject("WScript.Shell")
path = "HKCU\Control Panel\International\sList"
Set separator = CreateObject("Scripting.Dictionary")
separator.Add True , ";"
separator.Add False, ","
sh.RegWrite path, separator(sh.RegRead(path) = ","), "REG_SZ"

An even easier way to do this is via a .bat file
open notepad, and save the below as semi.bat or whatever you want to call it.
REG ADD "HKEY_CURRENT_USER\Control Panel\International" /f /v "sList" /t "REG_SZ" /d ";"
PAUSE
REG ADD "HKEY_CURRENT_USER\Control Panel\International" /f /v "sList" /t "REG_SZ" /d ","
This will allow you to open the .bat file it will change it to what you need then when you are finished it will change it back.

Related

Can I Assign a Custom Icon to a File Type

Is there a way i can associate a file type like (.php, .css, .js) to a custom icon, even when the file has been associate with a program.
for example on my computer .php is associated to sublime text, and when i encounter .php on my file system it show ST's icon, is there a way to make it change to a custom icon like the good ol' elephant, but still be associated with ST i.e when i click the file it still open's in ST(== sublime text).
I know how to do it for filetypes assigned to Notepad++.
In Windows 10, Notepad++ keeps hijacking the icons of filetypes that you open (by default) in Notepad++. It was very difficult to break that behaviour, but I finally got it working!
Preparations
1. Registry permissions
Open the Windos registry, and give yourself enough "permissions" for the folders HKEY_CLASSES_ROOT and HKEY_CURRENT_USER. I'm not sure myself what are the minimum settings for the whole procedure to succeed. You've got to play a bit with the settings. Anytime you get an error message in the coming procedure, go back to this step and increase your registry permissions.
2. Make some custom icons
Make some custom icons, for example in the folder C:\ICONS\. I use the following website https://iconverticons.com/online/ to convert 256x256 png-files into ico-files.
3. Install Notepad++
Just get Notepad++. Nothing special here.
4. Open a terminal with admin rights
Type cmd in the windows search bar. Right click on the CMD-icon that appears and choose "Run as administrator" in the popup window.
Registry hacking
Disclaimer: changing your registry can potentially cause damage to your Windows installation. I have written down the procedure below with best intentions, but I deny any responsibility in case something goes wrong.
Note: I DON'T recommend to use this procedure for .bat files. This is a very important file-type for Windows. So I don't know what would happen if you delete its standard registry keys.
The procedure below describes how to assign a custom icon - which you created in C:\ICONS\abcfile.ico - to all *.abc files.
1. Registry hacking, part one
The first registry key you should add is HKEY_CLASSES_ROOT\.abc. In case this key already exists, you might want to delete it. Use the following command to delete the key and all its subkeys:
> REG DELETE HKEY_CLASSES_ROOT\.abc /f
The following figure shows how we will (re)build this registry key and all its subkeys:
You can do it manually or run the following commands:
> REG ADD HKEY_CLASSES_ROOT\.abc /ve /t REG_SZ /d "abc_auto_file"
> REG ADD HKEY_CLASSES_ROOT\.abc /v BrowserFlags /t REG_DWORD /d 0x00000000
> REG ADD HKEY_CLASSES_ROOT\.abc /v EditFlags /t REG_DWORD /d 0x00000000
> REG ADD HKEY_CLASSES_ROOT\.abc /v PerceivedType /t REG_SZ /d "text"
> REG ADD HKEY_CLASSES_ROOT\.abc\DefaultIcon /ve /t REG_SZ /d "C:\ICONS\abcfile.ico,0"
2. Registry hacking, part two
The second registry key you should add is HKEY_CLASSES_ROOT\abc_auto_file. In case this key already exists, you might want to delete it. Use the following command to delete the key and all its subkeys:
> REG DELETE HKEY_CLASSES_ROOT\abc_auto_file /f
The following figure shows how we will (re)build this registry key and all its subkeys:
You can do it manually or run the following commands:
> REG ADD HKEY_CLASSES_ROOT\abc_auto_file /ve /t REG_SZ
> REG ADD HKEY_CLASSES_ROOT\abc_auto_file\DefaultIcon /ve /t REG_SZ /d "C:\ICONS\abcfile.ico"
> REG ADD HKEY_CLASSES_ROOT\abc_auto_file\shell /ve /t REG_SZ
> REG ADD HKEY_CLASSES_ROOT\abc_auto_file\shell\edit /ve /t REG_SZ
> REG ADD HKEY_CLASSES_ROOT\abc_auto_file\shell\edit\command /ve /t
> REG_EXPAND_SZ /d "\"C:\Program Files (x86)\Notepad++\notepad++.exe\" \"^%1\""
> REG ADD HKEY_CLASSES_ROOT\abc_auto_file\shell\open /ve /t REG_SZ
> REG ADD HKEY_CLASSES_ROOT\abc_auto_file\shell\open\command /ve /t
> REG_EXPAND_SZ /d "\"C:\Program Files (x86)\Notepad++\notepad++.exe\" \"^%1\""
3. Registry hacking, part three
The second registry key you should add is HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.abc. In case this key already exists, you might want to delete it. Use the following command to delete the key and all its subkeys:
> REG DELETE HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.abc /f
The following figure shows how we will (re)build this registry key and all its subkeys:
You can do it manually or run the following commands:
> REG ADD HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.abc /ve /t REG_SZ
> REG ADD HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.abc\OpenWithList /ve /t REG_SZ
> REG ADD HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.abc\OpenWithProgids /ve /t REG_SZ
> REG ADD HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.abc\OpenWithProgids /v "C:\Program Files (x86)\Notepad++\notepad++.exe" /t REG_NONE /d 0
> REG ADD HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.abc\OpenWithProgids /v abc_auto_file /t REG_NONE /d 0
Refresh icon cache
The following command should refresh the Windows icon cache:
> %windir%\system32\ie4uinit.exe -show
Assign Notepad++ to the filetype
I've noticed that - sometimes - the changes only take effect after assigning Notepad++ as the default program to open the filetype.
This is how to do that:
Create a file with the given filetype, eg: myFile.abc
Right click on the file, and select "open with" >> "another app"
You should get a popup window like:
Select Notepad++ as the default program
Finish
Normally the icon has changed now! And all files of that particular filetype will have the custom icon. They will open by default in Notepad++.
Perhaps you should again refresh the icon cache:
> %windir%\system32\ie4uinit.exe -show
or restart your system to let it take effect (although restarting wasn't needed for me).

Running a command with ActiveX only tries to create a file named my command

I run this vbscript on an html page
Dim WinScriptHost
Set WinScriptHost = CreateObject("WScript.shell")
WinScriptHost.Run Chr(34) & reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v name_of_key /d C:\path\to\exe /f" & Chr(34), 0
And it's not working. I look in Procmon and see that it ran a create file command to the path C:\root\directory\of\html\file\reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v name_of_key /d C:\path\to\exe /
Why would it try to create a file? Why isn't it just running it?
(I think the real command should have a cmd /C prepended, but the same problem occurs. It tries creating a file, just with cmd /C prepended)
I got it working by taking away the Char(24)'s
the new code is:
WinScriptHost
Set WinScriptHost = CreateObject("WScript.shell")
WinScriptHost.Run "reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v name_of_key /d C:\path\to\exe /f", 0

How to set value in registry via batch file in Windows?

I am going to set a value to windows registry.
I want to set variable shit for StupidMS in registry, but the result is wrong. Following is my code.
set stupidMS=shit
echo %stupidMS%
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v "StupidMS" /t REG_SZ /d ^%stupidMS^%
I think the problem is ^%stupidMS^%, but I quite have no idea how to correct it.
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v "StupidMS" /t REG_SZ /d "%stupidMS%"

How to make permanent system variable using BATCH or VBS?

I am making an installer which will be 100% depending on system variable such as %TEMP% or %Path%, users first double click windows.bat file.
But, How can i setup permanent system variable in Windows XP, Vista, 7, 8 using VBS or BATCH?
I tried with BATCH but in Windows XP, most users do not have setx by default, so i want to avoid using that technique. Is there better way to do that?
C:\Documents and Settings\sun>REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Ses
sion Manager\Environment" /v MyApplicationWillUsetThis /d "C:\WhatEverPathToIncl
udeHereQuestionMark"
The operation completed successfully
C:\Documents and Settings\sun>REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Ses
sion Manager\Environment" /v MyApplicationWillUsetThis /d "C:\WhatEverPathToIncl
udeHereQuestionMark"
Value MyApplicationWillUsetThis exists, overwrite(Y/N)? Y
The operation completed successfully
You can create a REG_SZ value under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment in the registry. The name of the value specifies the name of the environment variable, the value specifies the value of the environment variable.
You can also modify existing values.
In order to modify the registry you can use the RegRead and RegWrite method of the WScript.Shell object. For an example have a look at Manipulating the System Registry.
Edit: You could at first delete the existing value and recreate it afterwards.
REG DELETE "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v MyApplicationWillUsetThis /f
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v MyApplicationWillUsetThis /d "C:\WhatEverPathToIncludeHereQuestionMark"
How to set environment variables from VBScript
Set WshShell = CreateObject("Wscript.Shell")
' set a permanent environment variable %MyVarName% for all users
WshShell.Environment.item("MyVarName") = "MyVarValue"
If the above setting isn't permanent, try this one. This will set a permanent environment variable for all users. You can try System, User, Volatile, and Process categories with the Environment collection.
With WSHShell.Environment("SYSTEM")
.item("MyVarName") = "MyVarValue"
End With
You can also use ExpandEnvironmentStrings to read environment variables or replace them with their values in long command line type strings.
sValue = WshShell.ExpandEnvironmentStrings("%MyVarName%")
To work with the registry try
sRegKey = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\MyVarName"
sValue = WshShell.RegRead(sRegKey)
' don't write if no change is required.
If sValue <> sNewValue Then WshShell.RegWrite sRegKey , sNewValue

Is it possible to associate a file type with a .cmd file so it sends that file as an argument when double clicked

i have a dostuff.cmd file that takes one argument and looks something like this:
filepath_to_command_to_run %1
If I type dostuff.cmd FILE into the command prompt it runs fine.
Is it even remotely possible to get it so that I can associate that file type with my dostuff.cmd so that if I double click a file the .cmd will get it as an argument? Right now I've associated the file type with it, but when I double click it runs the stuff in the .cmd without getting the file as an argument.
Right click on the file -> Open With -> Choose Default Program -> Browse to and select your cmd file. ( Choose the checkbox saying always use this for this file type if you want)
Now double clicking the file will open it with the cmd file.
Alternatively, you can set it directly to filepath_to_command_to_run
Once I have achieved the correct way of FILE ASSOCIATION using these cmd commands.
this is just an example:
REG ADD "HKEY_CLASSES_ROOT\Applications\notepad++.exe\shell\open\command" /v # /t REG_SZ /d "\"C:\\Program Files\\Noteepad++\\notepad++.exe\" \"%1\"" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt" /v "Application" /t REG_SZ /d "notepad++.exe" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithList" /v "g" /t REG_SZ /d "notepad++.exe" /f
assoc .txt=MyCustomType
ftype MyCustomType="C:\Program Files\Noteepad++\notepad++.exe" "%1"
(it's better to put them in .bat file)

Resources