Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Run login command as Administrator

25 Feb 2010   #11
WindowsStar

Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 

Quote   Quote: Originally Posted by ultralame View Post
>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 System SpecsSystem Spec
.
25 Feb 2010   #12
ultralame

XP, Vista, W7, all flavors
 
 

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

Quote:
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 System SpecsSystem Spec
25 Feb 2010   #13
WindowsStar

Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 

Quote   Quote: Originally Posted by ultralame View Post
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...)

Quote:
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 System SpecsSystem Spec
.

Reply

 Run login command as Administrator




Thread Tools




Similar help and support threads
Thread Forum
Open Command Window Here as Administrator
Add or Remove "Open Command Window Here as Administrator" to Context Menu This will show you how to add or remove Open Command Window Here as Administrator to the context menu of a folder, drive, and desktop of all users to open an elevated command prompt with the focus at the library, folder,...
Tutorials
Run as Administrator command name
Is there a command to insert into a batch file so the file can ask for administrator approval before continuing?
System Security
Cannot Run command as Administrator
Hello, I have been buried by a cascade of issues that just drove me to a dead end. Everything started when one of the applications I use couldn't install properly. Now everytime I try to run this application it says that the folder d:\windows\assembly\gac_32\mscorlib\... is corrupted. Weirdly...
Performance & Maintenance
Run as administrator command has stopped working
Whenever I try to "run as administrator" a .exe file nothing happens aside from the window I was using to browse to the file freezing. Any ideas on what is wrong or how to fix it?
General Discussion
How to Login As Administrator (not shown in login screen)
After 3 days of installing windows 7 Ultimate and all the softwares/games, I made a mistake by changing user group and removing administrative privileges from user Miky. Right now I have the following user accounts: Administrator -> Account disabled LogMeInRemoteUser -> Administrator group with...
General Discussion
I've lost my Run As Administrator command
In my context menu, I had lost my Run As Administrator command. I had installed a Take Ownership command for installing WMP11 but uninstalled it because I wanted RAA. But, it doesn't show up in my context menu anymore. Anyway to solve?
Performance & Maintenance


Our Sites

Site Links

About Us

Find 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 07:14.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App