Run login command as Administrator

Page 2 of 2 FirstFirst 12

  1. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #11

    ultralame said:
    >When either Administrator or David logs on the machine the SUBST U: C:\ will run.

    What I need is to have the command run by BOTH David AND Administrator WHEN David logs on. Whenever any user logs in, the command needs to be run both normally and as the administrator in their logon session.

    Here's what I do now...

    1) Logon
    2) Open a cmd window, run the subst command. Close Cmd window.
    3) Open a cmd window AS ADMINISTRATOR, run same subst command. Close Cmd window.
    4) Check "My Computer". The subst drive is now visible.

    The only way I have been able to accomplish this is to create a batch file and then create two identical tasks for it in Task Scheduler. Both tasks run at User logon. One task is set up to run as the User, the other is set up to run as the Administrator.

    The problem now is that it does not seem to work every time, roughly 50/50.
    I am confused as to why it would need to run as the Administrator and David when David logs on.

    I can think of several solutions to this. Here is one that may work for you. I am assuming that the Administrator Password is known by everyone so that is not an issue.

    Since you already have a batch file working. Just add the batch file to the HKCU\....\Run key. Now every time David logs on it will make the SUBST for both accounts.

    That will accomplish what you need.
      My Computer


  2. Posts : 76
    XP, Vista, W7, all flavors
    Thread Starter
       #12

    On Vista and W7, in order to have a subst'd drive show up in explorer when the user is elevated, it needs to be run both as the user and elevated.

    This is only supposed to matter if you are running elevated programs that access the drive. However, I have seen that it doesn't always show up unless I run it as both User and elevated.

    I think I am going to give up and just use NET USE.

    (I also saw this in a tech note on the MS site, but here's a good explanation...)

    Creating drive mappings with SUBST
    When you create a drive mapping with SUBST, that mapping takes place in the context of the user account used to run the command. If you create a drive mapping as a regular user and try to access it with elevated privileges, the elevated-privilege process won't "see" the drive mapping. It can't, because the drive mapping has been done under a completely separate user account. This cuts both ways: If you create a drive mapping in the admin context and try to access it as a regular user, you can't. If you're running Vista, experiment with this yourself and see the results.
    As tempting as it is to call this a bug, it's not, and it shouldn't be regarded as one. Vista is simply honoring the fact that drive mappings created in one user account are not typically accessed in another. If you rely on drive mappings in both the regular and elevated security contexts, you may need to run your drive-mapping scripts twice—once in a regular-user context and again in an elevated context—as a workaround.
      My Computer


  3. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #13

    ultralame said:
    On Vista and W7, in order to have a subst'd drive show up in explorer when the user is elevated, it needs to be run both as the user and elevated.

    This is only supposed to matter if you are running elevated programs that access the drive. However, I have seen that it doesn't always show up unless I run it as both User and elevated.

    I think I am going to give up and just use NET USE.

    (I also saw this in a tech note on the MS site, but here's a good explanation...)

    Creating drive mappings with SUBST
    When you create a drive mapping with SUBST, that mapping takes place in the context of the user account used to run the command. If you create a drive mapping as a regular user and try to access it with elevated privileges, the elevated-privilege process won't "see" the drive mapping. It can't, because the drive mapping has been done under a completely separate user account. This cuts both ways: If you create a drive mapping in the admin context and try to access it as a regular user, you can't. If you're running Vista, experiment with this yourself and see the results.
    As tempting as it is to call this a bug, it's not, and it shouldn't be regarded as one. Vista is simply honoring the fact that drive mappings created in one user account are not typically accessed in another. If you rely on drive mappings in both the regular and elevated security contexts, you may need to run your drive-mapping scripts twice—once in a regular-user context and again in an elevated context—as a workaround.
    The "Creating drive mappings with SUBST" information will apply to "NET USE" as well.

    I still do not understand how this is a problem. When I log on my machine and do a SUBST or NET USE i have access to all i need. Granted if I run an elevated program or command prompt I don't have access, however this has been the situation since Windows NT 3.5. If you need to run something elevated and need access you have to SUBST or NET USE for that account.

    With my prior solutions if you load the user profile you will get your SUBST and NET USE drives.

    Are you using the Admin account to do something else? Mapping drives across many machines or something?
      My Computer


 
Page 2 of 2 FirstFirst 12

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 10:19.
Find Us