I'm building an unattended win7 install, and running into one final problem:

My current process will install a bunch of programs in the post-install phase, and then run some batch scripts and registry keys to clean up the start menu, desktop, and context menus.

Everything seems to work, except that after logging in for the first time and Preparing Your Desktop etc., some of the icons and context menu items return / are generated on first login.

I have written a batch file that corrects every single one of these undesired changes, but I cannot for the life of me figure out how to get it to auto-run after that preparation phase is done.

I've tried:

  • having my script copy it into the start menu's Startup - this doesn't work as it doesn't have admin rights that way
  • having my script copy a run-as-admin shortcut to the script into Startup - this doesn't work because, i think, startup won't do run-as-admin shortcuts?
  • running all the instructions in the post-install phase - this doesn't work because some of the stuff i'm removing seems to be generated in the desktop preparation phase

I need to be able to have this script run automatically upon first login, after desktop-prep, and to build that functionality into my unattended ISO. It would be nice to not have to accept a UAC prompt, but I don't think that's possible - so a UAC prompt is acceptable.

To be clear, if I manually execute this script I've written, and accept the UAC prompt, it does everything i want perfectly. I just cannot seem to get it to auto-trigger at the right time.

Is there any way to do this entirely within the windows install media?

  • It seems to me that you are asking two separate (or at least separable) questions: (1) How do I get my script to run after everything else is done and the dust has settled? and (2) How do I get my script to run as administrator?  Am I right, or do you know the answer to one of them?  (The answer to #1 might be “wait n seconds, maybe polling (something) to see whether the other stuff is done.”) If you are actually asking two separate questions, maybe you should actually ask two separate questions, i.e., click on Ask Question and ask one separately. May 21, 2017 at 21:52
  • I know how to run the script at the right phase, but only in a way that doesn't allow admin - and I know how to run the script as admin, but not during the right phase... so It's one question of two intertwined complications. From what I do understand, I will need a different approach from either of the failed ideas I've had. May 21, 2017 at 21:58

1 Answer 1


If I understand the question correctly, you want the PC to silently execute the batch as admin after reboot.

If this is the case, I recommend inserting a string value in the 'RunOnce' registry key before reboot to launch a Visual basic script that gets admin privileges (this may ask for user input, usually just clicking 'Yes') and then launch the batch. I know it's kinda bulky, but That's how I made it work for me. VBS below:

Set UAC = CreateObject("Shell.Application") 
UAC.ShellExecute "cmd.exe", "/c FILEPATH", "", "runas", 1 
  • Thanks, I will try this. Specifically, I want to run the script after it creates the user's profile stuff - the desktop shortcuts, start menu items etc. - as it is now, I have a script that completely wipes everything in the start menu and on the desktop out, then replaces them with new stuff... but during the "preparing your desktop" for the first time thing, a handful of the icons I've deleted seem to come back (IE etc) so I want to run this script and delete those (this phase also seems to make some registry changes that overwrite what I did in post-install - so my script changes those) May 26, 2017 at 3:21

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.