Sunday, August 19, 2018

windows - Batch File to Set Default Programs Without Administrator Rights


UPDATE 7/15/2016: A couple days ago, all the Group Policies pertaining to our OU stopped applying - meaning that there are no more restrictions. I now have full Command Line and Registry access which means I can use assoc and ftype after all. But I still get access is denied - is there some way to change the scope of the command? Although the GPOs stopped applying, I am still not an administrator. Can I use ftype/assoc without admin rights?


*Unfortunately, the GPO for Chrome mandating itself as the default browser is STILL there. But I still need to somehow ensure IE is the default, and then set .html, .css, .js etc - with Notepad++.


Our organization has the Chrome policy enabled for setting Chrome as the default browser. This setting is mandatory, and cannot be disabled like many of the other policies we have that are "Suggested". I use both Chrome and Internet Explorer, but for different purposes. I use Chrome for logging into websites and such and I use Internet Explorer for a lot of development and for opening local files and shortcuts to Internet Sites (.url files)


I have a batch script that runs at logon across our domain to automatically perform a variety tasks, including opening Chrome to a specific webpage. Whenever this happens, Chrome is obviously set to the default browser because of Group Policy settings.


I do a fair amount of web development, and I use Notepad++ for these purposes. I want all my html and css files, etc... to open in that program by default. In edition, I want Internet Explorer to be the default browser, so if I open a shortcut, it opens in IE, and once I close the browser, the history is deleted (the checkbox for Delete Browsing History on Exit in IE is checked.) If it opens in Chrome, it opens in a regular Chrome window and I ONLY use Incognito mode.


With IE, it isn't as necessary to use InPrivate browsing because history and cookies are automatically cleared once I close the browser. It isn't that I'm opening questionable links - I just want to be able to open links quickly and not have them in my history at all. Otherwise I need to clear it manually every time so I don't see the url of random pages I have visited in the address bar. In addition, IE shows the favicon of the website as the icon for the file, whereas I get a small Chrome logo for every url with Chrome as the default browser, which is pretty useless.


Right now, every time I logon, I have to manually select an .html file, go to Open With>Notepad++, and check Always use this program for this file type, etc... Before that, I have to open IE and click Yes when it says "Set IE as default browser?" If I do it second, then .html files automatically open in Internet Explorer, which is not what I want.


I have tried various batch files at this point to automatically set Internet Explorer as the default browser after Chrome opens, and then set Notepad++ as the default. I have found very few solutions, and the ones I have found have not worked. What I want to know is is this possible? And if so, how should I do this? Right now, the only solution is just stop using Chrome and never use it again, which is feasible but not necessarily preferable. I live in a Microsoft ecosystem, but Chrome isn't a terrible browser by any means,


Please keep the following in mind:



  1. Registry Editing is disabled. Any actions that involve/invoke the registry at all will fail.

  2. Batch files are allowed to run, but cmd is not. Powershell and Command.com are permitted (or rather, not blocked).

  3. This should be automated somehow (I add a line into a batch file and it will run seamlessly without pop-ups confirming something)

  4. I don't have administrative rights on any PCs, so it needs to work with a standard user account (and many of those standard user rights are also denied to us). In addition, the majority of the control panel and many system settings are not editable by domain non-administrators (pretty much our OU).


I would also like a standalone solution that I could afix to the shortcut. Part of my logon script replaces the regular Google Chrome shortcut on my desktop with an incognito shortcut, but opening Chrome again will obviously change it to the default browser. So it would be helpful if I could add another line to the Chrome shortcut so that it automatically executes the batch file.


Our domain uses Windows 7 Professional, if that helps, but I have heard they are piloting Windows 10 for next year so a solution that works for Windows 7+ would be great!


Thanks for all of your help in advance - I am looking for any solution that will work, even if it is tedious,


UPDATES:



  • I can't use ftype (I get: Access is denied)

  • Access to rsop.msc is denied (same for gpedit.msc, secpol, etc...)

  • Clarification: I can't use the reg functionality within cmd/batch files, etc... I will get ERROR: Registry editing has been disabled by your administrator

  • Thanks to w32sh for pointing out this resource - but what I want is to be able to just double-click the .url file and it will open in the browser I set (Internet Explorer.) These steps all require you to right-click and go to Open or Open With. I might add that right-clicking is disabled, and it's a hassle to go to the Menu Bar every time. In addition, I can't do Steps 3 or 4 from this link at all because they involve the Registry, and I can't do Method 2 because I can't open shell:sendto and even if I could, that's not quite helpful to me. And Method 1 is what I'm already do every time manually every single time I logon.

  • It could also be a powershell script or VBScript or another type of script as long as it can run without administrative rights.


Here are some pictures that illustrate that process:
enter image description here


enter image description here


enter image description here


Clarification: I realize that the default browsers are stored within the registry. But I can manually go to Open With>open with program>always use this program for files of this type, etc... and that will change the default browser - so there are ways to do it without using the Registry. But I am looking for a non GUI option that can be automated every time I logon.


-----REG FILE I TRIED-----


Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\.CSS]
@="Notepad++"
[HKEY_CURRENT_USER\Software\Classes\.HTM]
@="Notepad++"
[HKEY_CURRENT_USER\Software\Classes\.HTML]
@="Notepad++"
[HKEY_CURRENT_USER\Software\Classes\Notepad++\shell\open\command]
@="T:\Notepad plus plus\Notepad plus plus.exe \"%1\""
[-HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.css]
[-HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.htm]
[-HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html]

Answer



Here is a REG file that sets IE as the default browser (except for HTM and HTML file types), and then associates HTM HTML and CSS files with Notepad++


Note: This registry edit won't work if you're using Windows 10.. as Windows 10 imposes strict rules pertaining file type associations - with the hashing algorithm in place to detect any tampering with User Choice key.


Windows Registry Editor Version 5.00
; Set IE as default & associate CSS / HTM / HTML with Notepad Plus
; Made for Windows 7
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mht\UserChoice]
"Progid"="IE.AssocFile.MHT"
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mhtml\UserChoice]
"Progid"="IE.AssocFile.MHT"
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.url\UserChoice]
"Progid"="IE.AssocFile.URL"
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice]
"Progid"="IE.HTTP"
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice]
"Progid"="IE.HTTPS"
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\ftp\UserChoice]
"Progid"="IE.FTP"
;Associate CSS / HTM / HTML with Notepad Plus
[HKEY_CURRENT_USER\Software\Classes\.CSS]
@="Notepad++"
[HKEY_CURRENT_USER\Software\Classes\.HTM]
@="Notepad++"
[HKEY_CURRENT_USER\Software\Classes\.HTML]
@="Notepad++"
[HKEY_CURRENT_USER\Software\Classes\Notepad++\shell\open\command]
@="d:\\Tools\\NPP\\notepad++.exe \"%1\""
[-HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.css]
[-HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.htm]
[-HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html]

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...