Sign in to follow this  
Followers 0
javiwhite

#RequireAdmin + Various User based Macro's

4 posts in this topic

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.

Share this post


Link to post
Share on other sites



Many have gone the two-script route.

You can also look at HKLMSOFTWAREMicrosoftWIndowsNTCurrentVersionWinLogonDefaultUserName to get the last logged in user.

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0