Jump to content

RequireAdmin & current user's directories


Recommended Posts

I am using #RequireAdmin

When I run the script from a limited account, and I try to create a shortcut on the current user's desktop, it creates the shortcut on the admin account's desktop instead.

FileCreateShortcut($InstallPath & "\ProgramName.exe", @DesktopDir ""\ProgramName.lnk", $InstallPath)

I noticed that the same is true for @StartupDir That is it will create the shortcut in the administrator's account, not in the current users account.

I tried putting $UserDesktopDir = @DesktopDir in before #RequireAdmin is called, and then calling $UserDesktopDir instead of @DesktopDir, but that didn't work :)

What am I doing wrong, or how can I fix this?

Link to comment
Share on other sites

I am using #RequireAdmin

When I run the script from a limited account, and I try to create a shortcut on the current user's desktop, it creates the shortcut on the admin account's desktop instead.

FileCreateShortcut($InstallPath & "\ProgramName.exe", @DesktopDir ""\ProgramName.lnk", $InstallPath)

I noticed that the same is true for @StartupDir That is it will create the shortcut in the administrator's account, not in the current users account.

I tried putting $UserDesktopDir = @DesktopDir in before #RequireAdmin is called, and then calling $UserDesktopDir instead of @DesktopDir, but that didn't work :)

What am I doing wrong, or how can I fix this?

I cannot test this myself at the moment but I would guess that UAC is another way of accessing the older XP/2000 'Runas'. When you use Runas, programs actually run as that user. If you are providing the local adminstrator's information when UAC launches it is likely that the script is actually running as the local administrator.

To test, kick off your script, provide the account\password information required and then look in the Task Manager's Processes list. Find your script in the list and see if it is running as the local administrator.

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

Sorry. As I reread your OP I realized that you already know the issue and are looking to resolve it. Perhaps you could ask the user for their user name after the UAC info is passed. Assign the user name to a variable and pass it to the full path of their start menu and desktop directory.

$UserID = InputBox("Username", "Enter your User Name")
FileCopy(@ScriptDir & "Shortcut.lnk", "c:\users\" & $UserID & "\desktop")

It would mean giving up the convenience of @DesktopDir, etc. but it should work. Perhaps someone else has a more elegant solution.

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

Perhaps you could ask the user for their user name after the UAC info is passed. Assign the user name to a variable and pass it to the full path of their start menu and desktop directory.

That would probably work if it were more advanced users that this was for, but I am doing this for an installer, and I know that a lot of people out there wouldn't know their own username.

Link to comment
Share on other sites

That would probably work if it were more advanced users that this was for, but I am doing this for an installer, and I know that a lot of people out there wouldn't know their own username.

It's the one they use to log on the PC with assuming you are on a domain where everyone logs in as themselves.

The solution that I'm using for now is using the common directories: @DesktopCommonDir and @StartupCommonDir - which does work, but it's not the solution that I want I really don't want to make global changes like this, and would much rather stay at the current user level.

Sorry if I am completely off base or don't understand you issue.

Can you post your code? It would probably make more sense that way.

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

It's the one they use to log on the PC with assuming you are on a domain where everyone logs in as themselves.

Nope, not on a domain, just standard Windows Vista.

Sorry if I am completely off base or don't understand you issue.

Can you post your code? It would probably make more sense that way.

I don't have code with me right now (away from the house), but I'll post it when I get a chance. Basically this is just an installer that I did using AutoIt, it's kinda like InstallShield (or other standard Windows installers). The installer needs to make registry changes for adding an entry to the Add/Remove programs list in Control Panel. Now this would works fine except that the user may try to install from a limited account. This is why I had to put the #RequireAdmin in the script.

When this installs it gives the user the option to create desktop shortcuts, and I don't want the shortcuts to be created for every user account - I only want desktop shortcuts to be created for the user who installs the software (only on that user's desktop).

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...