C# how to do a custom shell to replace explore.exe - c#

I would like to do a custom shell(.exe) that would replace explore.exe on startup, that verifies if mstsc.exe (with a .rdp configured) is running, to check if the remote desktop is running. If not then there would be a logoff activated.
My question is what type of application should I make? I was thinking of a Console App.
And how do I make sure it replaces explore.exe on startup ? I am new at this...

You will have to find what are the requirments to program a Windows Shell Remplacement. There a many good tutorials online to know where to start. It's not a small thing to build so I won't go into detail here an start coding it for you. For this part, do your homework and read about it you won't have any difficulties finding what you are looking for.
As for :
And how do I make sure it replaces explore.exe on startup ?
You can set the vReg_Sz string value of
// Replace by your custom .exe shell
"Shell"="Explorer.exe"
to the full path of the program you wish to start by default.
This string is located at :
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
If you want to set it depending on which user is logged in, refer to HCKU\.. instead of HKML\..:
HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

Related

C# application which installs and allows for global command line

I would like to build a simple .NET application that installs on a windows machine which will allow the end user to open a command prompt and type "google test" which will open google and search for test. But I'm not sure how to install a global "keyword" such as "google". Is this down via Environment variables? How does this link up to my .NET application?
Any advice or pointers is appreciated.
Thanks
This is beyond a .NET application and belongs into the Area of Setup programms. Visual Studio used to have a Installer Project, but as there are so many 3rd party ways this was removed.
Having "google test" parsed as a google search for "test" is tricky, but possible. However it depends entirely on how the commandline is parsed in a Windows. Wich is pretty much the way it was parsed since DOS 1.0.
If you just enter a word like "google", the commandline will look if there is a Excetuable file (.exe, .com, .bat) of that name in the current folder (working directory). It will then look into all the folders defined in the path variables. However using path variables is so dated, I could find only a single entry in my Windows Path variable now. And it is for MS backward compatibility: "%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;"
Most starting of programms is done via file associations with a specific type. And protocoll associations with a protocoll (like http, https, steam). Indeed my advise would be to make a .NET Programm named "google" whose sole purpose is to to format the proper URL, then send it to console parsing via ProcessStart. And let Windows solve wich programm to use from there.
Edit: And as I only realized after wirting this, apparently Windwos finally supports commandline aliases. https://learn.microsoft.com/en-us/windows/console/console-aliases
Apparently they even added a way to make them via the WinAPI in Windows 2000. However that requires moving to unmanaged code. And I have no experience, but it appears those aliases might only be valid for one console instance. So you might have to put it into a place like hte autoexec.bat to be called everytime a console is created.

Detect machine change

I'm developing a small tool that is going to be distributed via executable.
The first time it is executed I want a tutorial to be displayed. As users are supposed to copy/paste the tool to theirs coworkers it would be nice if I detect that the machine has been changed and display the tutorial again for the new user.
If I could identify the machine ID somehow I could store it (as a setting for example) and compare it at startup in order to display or not the tutorial.
Is there a way to identify somehow the current machine?
Have a look at LocalStorage - which basically stores information per user. Write a small file on startup und check for it every time. If it's there, you know the user otherwise he is new.
The Process Class has a property which indicates the machine name.
Process.GetCurrentProcess().MachineName
Edit
Or get the machine name from System.Environment.MachineName
(thanks to Andreas Niedermair for mentioning it)

Use PolicyKit to give my application access to restricted files

I'm writing an application for Ubuntu, which allows you to customize the Unity 2D desktop environment.
Some settings, I can change using Dconf, which is user-specific. So if one user changes a setting, it only applies for that user.
For other settings, however, I need to edit text files which are located in /usr/share/unity-2d/, to which a normal user can't write. To solve this problem, I thought it was a good idea to have users run the application as root, which makes sure they have access to /usr/share/unity-2d/. Only, when the application is running as root, and one of the Dconf settings is changed, it gets changed in the root user's Dconf, so the changes don't apply to the actual user.
I need to find a solution to this problem, and my first realistic idea was to use PolicyKit. I need to make sure that my application runs as the current user (so not always as root), but that it does have access to /usr/share/unity-2d/ and the files inside it. I'm writing the application in C#, using the Mono framework. I don't really have any experience with PolicyKit, and to be honest this is my first attempt in making a serious Linux application.
My idea was PolicyKit, but if one of you has another (realistic) way to achieve this, that fine with me as well. If it comes down to using PolicyKit, I'd like to have a bit more information on how to do this, and what everything does, please. I know I can probably just run my application using pkexec, but I was actually thinking more among the lines of a button in my application to unlock the features which need access to that directory, which at that moment asks for a password to get writing access to the files in the folder. In this way, people who don't have special permissions on the system the application is running on, can still customize some basic settings.
Well, the obvious solution is to have two processes, one normal user app with the GUI, and something that runs as root that manipulates files as root.
E.g. as an analog "commandline only" issue would writing a file as root:
sudo echo Hello World >/root/hello.txt
Does not work because the redirection is done by the interactive shell and it does not have root's access.
The classical solution is to use two processes:
echo Hello World | sudo tee /root/hello.txt
Now the /root/hello.txt file is opened by tee which runs as root (via sudo), which is allowed.

How do I configure a C# program to run when the Operating System is first started?

How do I configure a C# program to run when the operating system is first started?
If you want to run the program when the user logs on, then the "Startup" folder or Run registry key methods both work.
If you want the program to run when the computer is turned on (ie Windows starts), without waiting for the user to log on, you will need to install it as a service, and configure it to start automatically.
Just add the program to the Startup folder in the Start Menu.
add to registry
private void AddToRegistry()
{
RegistryKey regKey = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\Run", true);
regKey.SetValue(Application.ProductName, Application.ExecutablePath);
}
I believe you are going to have to convert this C# application into a Windows service and set its startup type to Automatic. That seems to be the approach most people use.
The easiest answer would be to add it to the Startup folder in your Start Menu. As far as I know simply dropping it in there should be enough (since it is just a little exe).
For a simple C# app, putting the app's .exe or a shortcut to it, in the start folder is the easiest approach.
To build it in a little bit more, you could add it to the registry, under "Software\Microsoft\Windows\CurrentVersion\" then the subkey that you require. For more info on the registry approach read this - http://support.microsoft.com/kb/179365
For a more complex approach which may/maynot be needed depending on your application you can create it as a service, and have it set to run automatically. For a simple app this isn't needed so I won't expand further on this point.
You can develop this program as a Windows service. Then you can configure it to re-start after a failure or subsequent failures which increases robustness. Just an idea...
I'm using Inno Setup for my installer and adding the following line will accomplish this:
Name: "{commonstartup}\YourFolder"; Filename: "{app}\YourApp.exe"; IconFilename: "{app}\YourApp.ico"
Also add this to your [setup] section
PrivilegesRequired=admin
Documentation http://www.jrsoftware.org/iskb.php?startup

start .net application from start menu search

bla.exe (application alias) points to a .net application called wpfapp1.exe.
When i add a key&value to eg. this key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\bla.exe
and then start application using Run -> bla.exe it starts
however when i start application using windows search i get an "windows cannot find wpfapp1.exe. make sure you typed the name correctly, and then try again."
I have successfully identified problem: this error only occurs to .net applications while native one start normally (eg. firefox.exe).
So is there any .net config that i've missed during development?
From MSDN:
The App Paths key is not used when
computing the DLL search path.
Maybe you're missing some dependent DLL...
I don't really understand your "points to" or if Windows search is specific to using the explorer search or using the start menu search.
I've had a similar problem with another application that the search could not find at all, neither in Explorer or Start menu (since it did not have an indexed folder to locate it) and solved it with a simple shortcut.
If you can create a shortcut of your application in your start menu or some other indexed folder, like a %PATH% folder, Windows search should be able to pick it up and then you can name your shortcut to whatever you want, for instance bla.exe.

Categories