I have windows 7 64-bit, I've been trying to figure out how to set up a bat file to run with admin privilege so my wife can back up her computer by just clicking on it. It's been a journey.

I'm a programmer, so I know something of how easy this should have been.

My current problem is that I've somehow messed up the behavior of double-clicking on a bat file in Win explorer. It opens it in my own editor (what I use instead of notepad). At one time I was trying to set it so that choosing 'edit' on the file would do that, but I didn't want it to be default. Now I can't figure out how to go back.

I've been in my now backed-up registry to HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.bat and deleted it and everything under it. That got me past the point where double-clicking a bat file in explorer started the CMD prompt but didn't run the bat file.

What I am hoping to do is restore the default behavior and create a shortcut, then give the shortcut admin priv so that it performs the backup correctly. The tricky part of that is that it cannot live on the desktop; I would really like it if it could be on the start menu, but I tried creating a shortcut, giving it priv, and then putting it on the start menu, but it lost the priv when I did that. Next I'll try putting it on the start menu and THEN giving it priv, once I get past this current thing. But if someone has a comment to make on that, especially if it's in addition to fixing my current default problems, that'd be great.


In your bat/cmd file use runas

runas /savecred /profile /user:Administrator YourBackupScript.cmd

You can reset bat file association by creating some file with .reg extension and run it lately with following content

Windows Registry Editor Version 5.00



@="\"%1\" %*"

or try simply use extension .cmd instead of .bat

  • For others who may find this -- Registry Editor is sensitive to the text encoding of the file; I created this in a commercial text editor and RegEdit said it was not a registry import file; I pasted it from there to Notepad, saved as ANSI, and it continued to give that error. Not until I opened Notepad, retyped it all, and saved as ANSI, did it work. – rcook Jul 25 '15 at 10:37
  • This should get half-credit. The second part restored my .bat file (which is worth the check mark), but the first part doesn't work in my environment. 'savecred' doesn't work on Win 7 Home (acc to its documentation) and the "/profile /user:" options evidently require a non-blank password on the account. – rcook Jul 25 '15 at 10:43
  • RegEdit is smart enough to catch incorrect text encoding. ANSI encoding was used in Win9x/NT4 and mark header of reg file as Ver.4, but Ver 5 of RegEdit used unicode encoding. Anyway it shouldn't be a plain unicode characters, regedit 5 encode such characters as HEX format as hex(4):41,00,41,00,00,00 while regedit 4 in such cases use hex(4):41,41,00. So the problem is in copy/pasting and your editor. Try notepad++ for such things, it will automatically set ANSI encoding for any .reg files. – Alex Jul 25 '15 at 18:28
  • As about runas: Make a favor for youself and NEVER-EVER run computer without password on administrators account. And never ever work in administrative account. Create a standard user account and use administrators one ONLY for system wide changes. I agree with at least on that with Microsoft to not allow to use /savecred on acct with empty password and you BTW are wrong, /savecred is working on Home version of Windows 7, but you NEED to set password on administrators account, it is a HUGE security breach and no one antivirus will protect you better than a simple rule used for decades – Alex Jul 25 '15 at 18:37
  • @Everyone-except-Alex: if you paste regedit merge statements or whatever they're called into Notepad and save them as ANSI, and try to import them, they may not work. Mine didn't work (Win7 Pro 64-bit). I think it's an encoding problem, but Alex insists "RegEdit is smart enough to catch incorrect text encoding." Whatever. If you're having trouble getting it to import, mine worked after I typed it all in instead of using copy-paste. – rcook Jul 26 '15 at 1:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.