Run login command as Administrator

ultralame

New member
Member
Local time
9:09 AM
Messages
76
I used to have a network drive mapped to U:, but I have moved it to the local machine.

Some programs (one in particular: iTunes) don't do well if you move their file paths around, plus it would be nice if all the machines on the network could have the same setup. So now I want to have a virtual u: mapped to a location on C:\.

I could use NET USE. However, 1) this means I now have to maintain share permissions as well as local permissions (although this is not a big deal) and 2) I am not sure if this is a waste of resources- is the system now routing all this traffic through the network layer when it doesn't have to?

So I want to use "subst". The problem on Vista/W7 is that this is a per-user command, and it will not show up in the explorer unless it has been run twice- as both the current user and as Administrator.

So the question becomes: How do you run the command (either in a batch file or through some registry entry) as an Administrator at User login?

(Note: I am currently using NET USE with a localhost address. If someone has a better solution to this, please post. But it would also be nice to know how to run the admin command for any and all users at login).
 

My Computer

OS
XP, Vista, W7, all flavors
SUBST U: C:\

Add it to the RUN in the registry so it will run everytime someone logon's in.

Add the command to the RUN key in the registry under HKLM
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
Will that run it as the administrator? Everything that's running now from those keys is running under the logged in user.
 

My Computer

OS
XP, Vista, W7, all flavors
Well, I looked all around the web and found only one way to do it. Set up a batch file and then use Task Scheduler to run it as the Admin at the USER logon. (You need to enable the Admin account and set a password first).

To accomplish my subst command, you also need to set up the same Task to run as the User (in my case, all users) at logon also.

Now, when I log in, I have the local drive mapped to a distinct drive letter, without going through the network layer! Hallelujah!
 

My Computer

OS
XP, Vista, W7, all flavors
Will that run it as the administrator? Everything that's running now from those keys is running under the logged in user.

It will run as ANY user, including Administrator.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
Right- those keys will run at login for the user who is logging in. But I need the command to run both as the User and as Administrator. Those keys do not allow you to specify another user.

It is annoying. Also, my solution above does not seem to work consistently. The admin invocation does not always seem to run.
 

My Computer

OS
XP, Vista, W7, all flavors
Right- those keys will run at login for the user who is logging in. But I need the command to run both as the User and as Administrator. Those keys do not allow you to specify another user.

It is annoying. Also, my solution above does not seem to work consistently. The admin invocation does not always seem to run.

You can specify a user by using HKCU key. This will run only as that user. I Hope that helps. This way you can have a key for Administrator, User, David, Bill, Joe etc..
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
> You can specify a user by using HKCU key. This will run only as that user. I Hope that helps. This way you can have a key for Administrator, User, David, Bill, Joe etc..

Are you saying that you can set up a key so that when David logs in, the command will execute under both David and Administrator? HKCU will only run the command as the user that is logging in (David).
 

My Computer

OS
XP, Vista, W7, all flavors
> You can specify a user by using HKCU key. This will run only as that user. I Hope that helps. This way you can have a key for Administrator, User, David, Bill, Joe etc..

Are you saying that you can set up a key so that when David logs in, the command will execute under both David and Administrator? HKCU will only run the command as the user that is logging in (David).

Yes here is how:

Scenario:

You have 5 users on your machine.
You want User Administrator and User David to run the SUBST command.
You have Users Bill, Joe, and Mary and you DO NOT want them to run the SUBST command.

Add the SUBST U: C:\ command in HKCU for both Administrator and David.

Don’t add the command to any of the other users.

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

When anyone else logs on to the machine, since the command does not exist in their profile nothing will get substituted.

I hope that helps.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
>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.
 

My Computer

OS
XP, Vista, W7, all flavors
>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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
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

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

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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
Back
Top