Check Privilege Level for .exe files - windows

I've an application to deploy on ~300 Windows 7 computers.
I don't have a setup to install this app, just need to copy/paste in program files directory.
In the binaries dir, I've 9 executable files.
For each .exe, I need to check the box : "Run this program as an administrator" for all users. I've the local admin credentials.
My need is the do that in batch or VBScript or Regedit or any language (Python, C/C++, Java, others...) but NOT in AutoIt / AutoHotkey.
Can you help me to find the solution?

Yes, it is possible to do by setting a simple registry key. In this case, use REG.exe's ADD option to set this registry value via a batch file.
Command: REG ADD [ROOT\]RegKey /v ValueName [/t DataType] [/S Separator] [/d Data] [/f]
For current user only:
REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v << 'FULL (DOUBLE QUOTED) PATH TO YOUR APPLICATION'S EXECUTABLE FILE >> /d "RUNASADMIN"
For all users:
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v << 'FULL (DOUBLE QUOTED) PATH TO YOUR APPLICATION'S EXECUTABLE FILE >> /d "RUNASADMIN"
Example (for all users):
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\My Program\MyProgram.exe" /d "RUNASADMIN"
If you want to set this for all users, you should run your batch file with administrator privileges.

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).

How do I automatically launch a non-Surface application in Windows Embedded 8?

How do I automatically launch a non-Surface application in Windows Embedded 8?
I want to automatically launch a GUI application on startup in Windows Embedded 8, but I can't figure out how to do it. I've been reading Sean Liming's Professional's Guide to Windows Embedded 8 Standard, and in chapter 8 he describes how to modify the device experience. He names how there is a Windows 8 Application launcher, but for Surface apps only. He also describes a Shell Launcher module, but my app is not a shell. He also mentions a shell he wrote here, but reading through its documentation, it doesn't describe how to automatically launch a program within that shell.
As far as I can tell, he doesn't describe how to automatically launch a non-Surface application anywhere, and Google and Stack Exchange get me no results (it doesn't help that most results come back as merely Windows 8, and not Windows Embedded 8). Or am I mistaken? Is Shell Launcher sufficient to launch a non-shell app? Does the app launched become the "shell", in effect?
Side note: It's probably worth mentioning that the app I want to launch is a Java app. I will be including the module-based Java JRE installer as mentioned in the book, but if there are any other provisos to launching a Java app in WE8S, please comment.
Thanks for your time and feedback!
This works for both Windows Embedded Standard 7 and Windows Embedded 8 Standard:
I normally install Windows Embedded Standard with the standard shell. In WE8S this would be the Metro UI. Once installation and configuration is complete, and your application runs successfully, I use registry entries to modify the application launched on startup.
Custom user-specific shell
As an example, to launch VLC media player as the shell, and play media files in a folder on the d:\ e.g d:\media in a continuous loop, I use the below in a .bat file, running as administrator.
This must be run while logged into the user that will launch the custom shell
Create a new .bat file:
in Windows Explorer, Select "File" -> "New" -> "Text Document"
Rename "New Text Document.txt" to custom_shell.bat
Paste the below into the file
Save the file
Right click the file -> "Run as Administrator"
c:\Windows\system32\reg.exe DELETE "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /f
c:\Windows\system32\reg.exe ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /t REG_SZ /d explorer.exe
c:\Windows\system32\reg.exe ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /t REG_SZ /d "c:\program files\vlc\vlc.exe -f --loop ""d:\media"""
c:\Windows\system32\reg.exe DELETE "HKLM\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\system.ini\boot" /v Shell /f
c:\Windows\system32\reg.exe ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\system.ini\boot" /v Shell /t REG_SZ /d "USR:Software\Microsoft\Windows NT\CurrentVersion\Winlogon"
pause
This modifies the shell for the !Current User! (i.e. the logged on user) to launch VLC.exe on logon. (I use reg.exe because some slimmed down installations might not have regedit.exe included)
This means that you can still access the full user interface when logging on as the administrator user (via safe mode if Administrator profile is normally disabled), since the shell for all other users is still the explorer shell.
Launching the explorer shell from within the custom shell
You can still launch the explorer shell with the metro UI when the user with the custom shell is logged on. To launch the explorer shell from the user running the VLC (custom) shell:
Start the task manager (CTRL+SHIFT+ESC)
Click on the "Advanced" button at the bottom of the task manager
Select "File" -> "New Task (Run...)" from the menu bar
Enter "Explorer.exe" (This start the explorer service)
Repeat the above steps again (This will lauch an instance of Windows Explorer)
The Metro UI should be usable then
Java application as a shell
More to the point, in order to run your java app, change the below entry in the above .bat
from:
c:\Windows\system32\reg.exe ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /t REG_SZ /d "c:\program files\vlc\vlc.exe -f --loop ""d:\media"""
to
c:\Windows\system32\reg.exe ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /t REG_SZ /d "java [any other JVM options you need to give it] -jar "path\jar-file-name.jar""
If your java app does not include a manifest the above will not work!
Try this (I have not tested this):
java -cp jar-file-name.jar full.package.name.ClassName
Revert to the Explorer (default shell) i.e. Undo user-specific shell
To undo the shell changes for the user i.e. revert back to original settings:
!This must be run while logged into the user with the custom shell!
Create a new .bat file:
in Windows Explorer, Select "File" -> "New" -> "Text Document"
Rename "New Text Document.txt" to default_shell.bat
Paste the below into the file
Save the file
Right click the file -> "Run as Administrator"
c:\Windows\system32\reg.exe DELETE "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /f
c:\Windows\system32\reg.exe ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /t REG_SZ /d explorer.exe
c:\Windows\system32\reg.exe DELETE "HKLM\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\system.ini\boot" /v Shell /f
c:\Windows\system32\reg.exe ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\system.ini\boot" /v Shell /t REG_SZ /d "SYS:Microsoft\Windows NT\CurrentVersion\Winlogon"
c:\Windows\system32\reg.exe DELETE "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /f
pause
User Auto Logon:
You can configure Windows to automatically log onto a specific user profile.
Start > Search > netplwiz
OR [Windows Key + R] > netplwiz
A ‘User Account’ window will open. Highlight the account you want to automatically load when Windows starts.
Uncheck the box above it titled “Users must enter a user name and password to use this computer.”
Click OK.
You will be prompted to confirm the operation by entering your password.
Enter your password to complete the change.
The next time you start up Windows, the user account you selected will automatically be loaded
Things to consider
Play around, but use a test environment if possible
If you can launch the shell, so can someone else. Use the keyboard filter to filter out known key combinations, and create one only you, and perhaps the service technicians will know.
Remove admin rights for the user with the custom shell
Use the Unified Write Filter (or Enhanced Wright Filter/File Based Write Filter). Un-protect only when making changes.
A big THANK YOU to Sean Liming and the work that does - he inspired this.
Mark Böhmer
Windows Embedded Specialist
South Africa

Run reg command in cmd (bat file)?

I'm trying to run this reg code in cmd (bat file), but I couldn't make it work. Where am I doing wrong?
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Control Panel]
"HomePage"=dword:00000001
It works if I make it a reg file and double click.
Bat file code (this doesn't work, no errors):
#echo off
reg add "HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel" /V HomePage /T REG_DWORD /F /D 1
You will probably get an UAC prompt when importing the reg file. If you accept that, you have more rights.
Since you are writing to the 'policies' key, you need to have elevated rights. This part of the registry protected, because it contains settings that are administered by your system administrator.
Alternatively, you may try to run regedit.exe from the command prompt.
regedit.exe /S yourfile.reg
.. should silently import the reg file. See RegEdit Command Line Options Syntax for more command line options.
In command line it's better to use REG tool rather than REGEDIT:
REG IMPORT yourfile.reg
REG is designed for console mode, while REGEDIT is for graphical mode.
This is why running regedit.exe /S yourfile.reg is a bad idea, since you will not be notified if the there's an error, whereas REG Tool will prompt:
> REG IMPORT missing_file.reg
ERROR: Error opening the file. There may be a disk or file system error.
> %windir%\System32\reg.exe /?
REG Operation [Parameter List]
Operation [ QUERY | ADD | DELETE | COPY |
SAVE | LOAD | UNLOAD | RESTORE |
COMPARE | EXPORT | IMPORT | FLAGS ]
Return Code: (Except for REG COMPARE)
0 - Successful
1 - Failed
For help on a specific operation type:
REG Operation /?
Examples:
REG QUERY /?
REG ADD /?
REG DELETE /?
REG COPY /?
REG SAVE /?
REG RESTORE /?
REG LOAD /?
REG UNLOAD /?
REG COMPARE /?
REG EXPORT /?
REG IMPORT /?
REG FLAGS /?
If memory serves correct, the reg add command will NOT create the entire directory path if it does not exist. Meaning that if any of the parent registry keys do not exist then they must be created manually one by one. It is really annoying, I know! Example:
#echo off
reg add "HKCU\Software\Policies"
reg add "HKCU\Software\Policies\Microsoft"
reg add "HKCU\Software\Policies\Microsoft\Internet Explorer"
reg add "HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel"
reg add "HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel" /v HomePage /t REG_DWORD /d 1 /f
pause
You could also just create a Group Policy Preference and have it create the reg key for you. (no scripting involved)

How to Create Registry key using a batfile

Need to Create a Registry Key using bat file.Can I create Reg Key using Command prompt or a bat file.
The main purpose behind this , I want to create envoirment variable using bat file.
You can use the Windows built-in command line tools, either regedit.exe or reg.exe, see:
Regedit
REG Command in Windows XP
Reading NT's Registry with REG.EXE
Yes u can create Registry Key using Batch file
here is an example:
for disabling task manager using .bat file:
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /f /v DisableTaskMgr /t REG_DWORD /d 1
for enabling task manager:
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableTaskMgr /f
You can take Help by entering reg/? in command prompt for various options.
Enjoy.........
SET variable=string
If you want to create a persistent environment variable (i.e. one that not only applies to the current session) you can use setx. No need to mess around with the registry directly if there is a program to do it for you:
SetX has three ways of working:
Syntax 1:
SETX [/S system [/U [domain\]user [/P [password]]]] var value [/M]
Syntax 2:
SETX [/S system [/U [domain\]user [/P [password]]]] var /K regpath [/M]
Syntax 3:
SETX [/S system [/U [domain\]user [/P [password]]]]
/F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]
Description:
Creates or modifies environment variables in the user or system
environment. Can set variables based on arguments, regkeys or
file input.

How to associate a file extension to a program without making it the default program

I'm deploying a small conversion tool on some systems, and want the users to be able to run it from the right click Open with menu. But I don't want to change the default program users have associated to this file type.
It is easy to associate a file extension/type to a program, but how to do it (programatically of course) without changing the default program?
Setting the following keys worked for me:
key HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths/<progname>: "" = <appPath>
key HKCR/Applications/<progname>/SupportedTypes: <fileExt> = ""
key HKCR/<fileExt>: "" = <progID>
key HKCR/<progID>/OpenWithList/<progName>
key HKCR/<fileExt>/OpenWithList/<progName>
key HKCR/SystemFileAssociations/<fileExt>/OpenWithList/<progName>
delete key and subkey at HKCU/SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/fileExts/<fileExt>
You can add scripts to the context menu (below Open with) by adding it in the windows registry:
Open regedit
Goto HKEY_CLASSES_ROOT\your_class\Shell
Add a new key and give it a name
Edit the (Default) value of this key and insert the text you want to show in the context menu
Add a new key named Command under your newly created key
Edit the (Default) value of this key and insert the command you want to execute
Enjoy!
In the "File Types" Windows Dialog you can click "Advanced" on your file type and there create a custom action tied to your application.
Possibly you can also find a way to do this in a programmatic manner, or at least create a .REG file with the equivalent registry options.
I have achieved the correct FILE ASSOCIATION using these cmd commands.
(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)
here's a worked example for XP adding a command prompt option to folders. Create a .reg file
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt]
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt\command]
#="cmd.exe /k cd \"%1\""

Resources