Can a batch run as admin launch another batch as limited user

mappeddriveuacwindows 7

I have a batch that is being run with administrative privileges on a Windows 7 machine. That batch has to run another batch, which should access a mapped network drive. However, network drives are only mapped for the non-administrator part of the logged-in user. Since the second batch doesn't need the administrative rights, I'd like it to run as a limited user, and that will let it access the mapped drives. Is there any way to do that?

To make what I want clear, I'd like to get the following flow:

  1. User eran logs into PC. eran is a local administrator.
  2. eran runs b1.bat as administrator.
  3. b1.bat runs b2.bat with eran's limited user credentials (how? that's what I'm asking…)
  4. b2.bat accesses some mapped drives is now has access to.

Just in case the reason for the problem is not clear…

Best Answer

You can use the runas command. Check out runas /? or Microsoft runas for more info. Put this in your b1.bat file.

runas /noprofile /user:username@domain.local "C:\batch\b2.bat"

Credit here


If that doesn't work you could map the drive in the b2.bat file. Add net map z: \\server\share. Then follow up with net use z: /d

Related Topic