Sunday, December 7, 2014

Bat file added to registry not working on windows



I'm trying to make a bat file run at boot by adding it to the system registry; the bat is very easy, it's just:



mkdir new



Obviously when I normally run it, it works and a folder named "new" spawns in the bat file directory(Desktop), but when I try to add the file to both "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" and
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", add a string like "C:\[...]\Desktop\test.bat", on boot I see for a moment a cmd windows pop up and then immediately close but no "new" folder. Does anyone know how to solve that?


Answer



A start-up key such as:



[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Run"="C:\users\bob\desktop\run.bat"



...where "run.bat" contains:



mkdir new


..will start in the following directory: "C:\windows\system32\".



The command line will be:




C:\WINDOWS\system32\cmd.exe /c ""C:\Users\bob\Desktop\run.bat" "


and it will be running as the user "bob".



Trying to create a directory in "C:\WINDOWS\system32\" will get you access denied.



If you like, you can put the command:



pause



in the batch file "before" and "after" your command(s) so you can see it happen at logon. You can even run Process Monitor (https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx) after the first pause to see the outcome.


No comments:

Post a Comment