javiwhite Posted February 4, 2015 Share Posted February 4, 2015 Hi all, I've stumbled across an issue with running my application as an administrator, The script itself runs fine, But the macro's i have in my script are using the administrators account, as opposed to the logged in users account example: msgbox(0,0,@DesktopDir) ; Produces a message box stating 'C:\Users\Ryanw\Desktop' #RequireAdmin Msgbox(0,0,@DesktopDir) ; Produces A message box stating 'C:\users\Administrator\Desktop' I realise this is most likely due to the script being run as a different account; But I require both the ability to run the application as administrator, And access the logged in users desktop... What would be the most effective way of achieving this? I've considered running cmd files from the main script, that echo back the username variable, But this seems to inherit the permissions from the calling script by default. I'm at a loss as to how to get the username of the logged on user, whilst still requiring an admin to accept the UAC request beforehand. The only workaround I can think of is having a separate application that is run initially, and parses the username to the secondary (main application) that is then run as an administrator, But would prefer to keep the script down to one file. Any Help is greatly appreciated. Many Thanks Javi give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 4, 2015 Moderators Share Posted February 4, 2015 Many have gone the two-script route. You can also look at HKLMSOFTWAREMicrosoftWIndowsNTCurrentVersionWinLogonDefaultUserName to get the last logged in user. javiwhite 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Solution javiwhite Posted February 4, 2015 Author Solution Share Posted February 4, 2015 (edited) Fair enough, I did kind of expect to end up creating a separate script to parse the login info. Although reading the registry doesn't sound like too much of a bad idea either, I'll have a play around with it! Thanks! - Javi EDIT: Thanks To JLogan's Suggestion I was able to extract the logged in user using RegRead. The suggested Registry key for some reason doesn't update as expected on Windows 7 machines (according to various MSDN forum pages found in a quick google search of 'DefaultUserName' anyway.) But this lead me to find the following key: HKLMSOFTWAREMicrosoftWindowsCurrentVersionAuthenticationLogonUILastLoggedOnUser. Thanks JLogan, I appreciate the guidance Edited February 4, 2015 by javiwhite give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime. Link to comment Share on other sites More sharing options...
zalomalo Posted February 7, 2015 Share Posted February 7, 2015 The UAC in windows is a reall pain to us. I have spend more than one year fighting vs UAC, and now at last i can deal with it. Tell me if i could help you in something.. My english shucks, i know it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now