How to include a program on startup? - windows

I would like to have an executable file run at startup, Windows 7.
I was wondering how I may do so directly at the command line or by way of batch file.

Windows provides powershell to automatize this kind of tasks using "command prompt" or scripts.
In the case you are proposing, you can change the registry values that controls startup programs by using the new-item-property cmdlet like this
PS> New-ItemProperty HKM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ -Name <pretty beautiful name for your app> -Value <executable for your app>
You can also use PowerShell to elliminate or to change keys. But, you know
With big power comes great responsability

On a windows comp
Hit the win + r
A small dialog box appears on bottom left. In the box type
shell:startup
You are automatically redirected to the relevant folder. Just copy past ur program into this folder.

If u have a more malicious intent in mind simply use the copy command to copy the file from its current destination(A USB perhaps) to the location gotten from the aforementioned method.
However there is a slight catch. This only works if ur the admin of the computer. So you would theoretically have to include code to hand your program admin access before copying the file
[Tutorial on how to do it here1

Related

Create startup folder - Windows

I script a lot of things to manage the computers in my company. I often need to add shortcuts into the personnal startup folder of users (without a GPO).
Windows 8/8.1 doesn't have a personnal startup folder by default.
Its location is C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\
It is easy to create this folder, but it needs a desktop.ini file into it, with the correct content, for the name to be localised (else it is displayed "Startup" whatever the language).
What is the "official" way to create this folder?
Or what is the official way to add something into it?
I'd prefer a PowerShell or batch command, but whatever reliable mean is okay.
I guess you can do something with the ComObject for this special folder:
$startup = (New-Object -ComObject Shell.Application).NameSpace(0x07)
By the way, if I enter shell:startup in a run box (Win+R) on my Win 8.1 system, it directs me to my personal startup folder (C:\Users\User\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup).
As far as I know, there is no reliable way to do this.
You can get the path with [environment]::getfolderpath("Startup") but the returned string is empty if the folder was neve created. And I don't know any API entry to create it.
So you have to manually create it:
check if the former command return anything (if yes, just create you shortcut)
create yourself the startup folder. Use [environment]::getfolderpath("StartMenu") and add \startup to the path
then create the desktop.ini file and populate it yourself
and update the registry HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders (I didn't check if this is the right place. [environment]::getfolderpath("Startup") must return the right value)
UPDATE: I just found SHGetKnownFolderPath API which allow to create the required folder if needed (with dwFlags). I'm not good at PowerShell, so I don't know how to call this. Maybe Someone can give a better answer.

How to change the path for "run command" "notepad"?

Where is in the registry the path executed when I run the "notepad" command in windows "Start->run command" interface? I want to change it for notepad++ (it is required so, although could look not really good)
If you are like me you use windows run command all the time. I hate using the mouse to point and click a shortcut on the start menu. WIN-R are probably the two most over used keys on my keyboard. After thinking about if awhile I hunted down how the run command works. It turns out that it makes a call to ShellExecute, which I guess is not too surprising. The next thing I wanted to find out was exactly how the commands are resolved. The following is an ordered list of how they are resolved ([1]):
The current working directory
The Windows directory (no subdirectories are searched)
The Windows\System32 directory
Directories listed in the PATH environment variable
The App Paths registry key
Naturally the next thing I wanted to do was customize existing commands or add new commands so I do not have to type as much (standard lazy approach). After examining my options which were to put the executable in one of those paths (since it only locates executables and not shortcuts), modify the path environment variable or add a key to App Paths. The App Paths option seems to be the easiest and most flexible to me. Here is a layout of what you need to do to add an App Paths entry ([1]):
HKEY_LOCAL_MACHINE-->
SOFTWARE-->
Microsoft-->
Windows-->
CurrentVersion==>
App Paths-->
file.exe-->
(Default) = The fully-qualified path and file name
Path = A semicolon-separated list of directories
DropTarget = {CLSID}
Disclaimer: Modifying the registry can cause serious problems that may require you to reinstall your operating system. I cannot guarantee that problems resulting from modifications to the registry can be solved. Use the information provided at your own risk.
The minimum needed to add a new entry is to add the key file.exe where file is the string you want to type into the run command and to add the Default entry which is the fully-qualified path to the file you want to execute. Note that even it the file you are going to reference isn't an exe file you still need to put the .exe on the key. Here is a sample registry file that I created to add a shorter keyword for Internet Explorer:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\ie.exe] #="C:\Program Files\Internet Explorer\iexplore.exe"
After entering that entry into the registry I can simply type “ie” at
the run command to open internet explorer.
Here is a list of some common commands I use at the run command:
cmd – Command prompt winword – Microsoft Word excel – Microsoft Excel
outlook – Microsoft Outlook iexplore – Internet Explorer firefox –
Mozilla Firefox notepad – Notepad compmgmt.msc – Computer Management
Console control appwiz.cpl – Add/Remove programs dialog mstsc –
Microsoft Terminal Service Client regedit – Registry Editor
…
If there is some program that I find myself using all the time I figure out what the run command is for it and if there is not a short easy one I add one to my App Paths as described above. Does anyone else have some other common run commands they use?

How to remove file association with a program for files with no file type?

On my current Windows 7 machine, all files with no file type/extension are associated with a program. When I double click on the file, instead of prompting for which program I want to use, it tries to open it with said program (in this case Mass Effect 2). How would I remove this association, as 'File' with no extension is not listed in the Windows extension manager.
I looked at this page here, but I don't currently have a registry entry there, so it must be something else?
I'd like to either remove this association, or at least change it to Notepad++ (what I normally use to open files with no extension). I hope I've phrased this question correctly, as you can see this is my first one. Thanks!
I believe the key you are looking for is hklm:software/classes/unknown. I have mine set as Notepad2
sp hklm:software/classes/unknown/shell '(default)' edit
ni hklm:software/classes/unknown/shell/edit/command `
-f -t expandstring -va '"%programfiles%/notepad2/notepad2" %1'
Example

C: drive access permission in windows 7

In matlab, I used a windows standalone application. There is a line in this application that writes a file in C:\...\...\. When I run the output exe file produced from this windows standalone application, the exe doesn't write in C:\...\...\ neither tells me that there is a security issues in that partition. All the execution does is nothing. But, when I right-click and run the exe as administrator, it runs correctly.
I want to do it without right-click and run as administrator. Are there is a command in matlab that can do that?
If you create a shortcut to your application, you can go to the Properties of the shortcut, click on Advanced in the Shortcut tab, and select "Run as administrator". That way, whenever you start the application from the shortcut it will be run as an administrator.
(Disclaimer: applications really shouldn't "foul their own nest" by writing into Program Files. This is bad design.)
Starting from Vista, unprivileged processes are not allowed to write to protected folders such as Program Files, because Program Files is designed to store code and not data. However, since this limitation has not been enforced in XP, MS has provided a backward-compatibility hack in the form of Virtual Store. Now, when a program tries to write to protected folder, its output is being redirected into a dedicated folder. This way, the program still "thinks" it writes to its usual location, while in fact it writes to an unprotected location. However, when you later check the Program Files location, you might not see the file - because it's not really there.
You can find more details here: User Account Control Data Redirection.
If you are administrator, add full control permission for your username to the destination folder. You do that by right clicking on the folder, going to properties and then security tab. Then edit and add you username with Full Control rights. Then you don;t have to run the the program as an administrator.
There is no way you can elevate a process once it is started, so Matlab cannot possibly have a command for that. Just running Matlab elevated.

Windows shutdown dialog

Is there a way to bring up the Windows XP shutdown dialog (the one with the three buttons – Suspend, Shutdown, Restart and Hibernate when Shift is pressed) using any language (preferred: C/C++, VB, Haskell, batches)?
I think I can load the msgina.dll in my C++ program, but I dunno what to do next – what function in the dll is used to show the dialog?
Assuming that your language has a way to do basic file I/O and invoke shortcuts on Windows, try this tip from here:
Create a new txt file somewhere on your system, open it and put in this one line:
(new ActiveXObject("Shell.Application")).ShutdownWindows();
Save and close the file. Change the extension to *.js.
You can make a shortcut to that file to make it easy to shut down your system.
I find PowerShell to be more elegant than other Windows scripting options.
(New-Object -Com Shell.Application).ShutdownWindows()

Resources