KrypticChewie / USMTScripts

These are the scripts I use with USMT to transfer files and settings between PCs.
6 stars 0 forks source link

Detect administrator access #15

Open KrypticChewie opened 5 years ago

KrypticChewie commented 5 years ago

USMT requires administrator privileges. Right now, if the scripts are not being run with administrator privileges, after using the script you will get an error when ScanState or LoadState actually run. It would be more convenient if the script could detect that it does not have administrator privileges as it is run.

KrypticChewie commented 5 years ago

One method found to do this is to check if Net Session throws an error. The assumption being if it throws an error it's because access is denied and access is denied because there is no administrator access.

Batch script: how to check for admin rights https://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights

KrypticChewie commented 4 years ago

https://www.sevenforums.com/software/420165-check-administrator-rights-batch-file.html

KrypticChewie commented 4 years ago

The script can catch the USMT executable throwing an error for no admin access in commit https://github.com/KrypticChewie/USMTScripts/commit/992ba29b7765af633b2aa677670f0edc806e4032

This is not the required behaviour though. I would like to script to do the detection itself before the user has to do anything else. I would also like it to exit and run itself with administrative privilege.