Jump to content

#RequireAdmin + Various User based Macro's


Go to solution Solved by javiwhite,

Recommended Posts

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

  • Moderators

Many have gone the two-script route.

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

"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

  • Solution

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...