Disassembler0 / Win10-Initial-Setup-Script

PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
MIT License
4.7k stars 1.08k forks source link

Cannot run as administrator #224

Closed dfrigon closed 5 years ago

dfrigon commented 5 years ago

When I run the Default.cmd it start and ask for PowerShell to allow to make changes but when I click yes I can see the PowerShell pop and close directly and the cmd also closes and none of the functions runs from the Win10.ps1 file.

I bypassed the RequireAdmin function in the Default.preset and now it works fine but I assume any modifications that requires Administration privilege won't work

Any clues? Thanks!

dfrigon commented 5 years ago

And I would be really comfortable to manually enter my credentials when running the script if I need to.

dfrigon commented 5 years ago

Finally I was looking way to far... I commented the Exit in the if statement of the RequireAdmin Function and it worked.. I think that normally it would open a separate PowerShell application and close de CMD but on my side it seems to be handled in the Command Prompt directly so by keeping it open instead of closing it it works.. is this all normal?

Disassembler0 commented 5 years ago

Download a fresh copy of version 3.6 from GitHub releases and add -NoStop after -NoProfile in both Default.cmd and Win10.ps1 (line 11). This should cause the PowerShell window to stay open after the script interrupts and allow you to examine the error you're getting.

And I would be really comfortable to manually enter my credentials when running the script if I need to.

That's what the script in cooperation with UAC should already do, depending on your UAC settings. But for some reason it doesn't on your machine.

I commented the Exit in the...

Which means that the script will continue running without elevation. Probably not what you want.

is this all normal?

None of what you describe is :)

Disassembler0 commented 5 years ago

Correction: add -NoExit after -NoProfile

dfrigon commented 5 years ago

Well it's worse than I expected then!

With the addition of the -NoExit in both files the Command Prompt stays open with this:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS Z:\Desktop\Win10-Initial-Setup-Script-3.6>

The PowerShell window do the same thing as before which is to pop open and close instantly.

Disassembler0 commented 5 years ago

Is your Z:\ by any chance a network drive? That would explain a lot of things. Everything, actually :)

dfrigon commented 5 years ago

When I first tried before opening this issue I was running of the C: drive and it wasn't working (but I figured out I wasn't administrator at this time with the user I had..) so I assumed that running on the Z: with the same issue was in the code but now with all the right autorisations and running on the C: it works!

Thanks a lot for your time!