I thought I could make a simple, one-line script to add the current user to the local admins group:
runas /env /user:administrator “net localgroup administrators /add %USERDOMAIN%\%USERNAME%”
…but it doesn’t work when run from a network drive because Administrator doesn’t have the drive mapped, so I get a “directory name is invalid” error. Which is annoying, because if I run it from a UNC path, it would self-correct to %WINDIR%.
Then you need to establish a new system %PATH%. It looks through this path for where the CMD.EXE is. If there is nothing set in the %PATH% then it will not find the CMD.EXE and give you the error you are getting.
So to fix it just run the following command…
set path=%path%;c:\windows\system32
this way it will find the cmd.exe no matter what working path you are in.
Which is what the %windir% is because if you typed echo %windir% you would get “c:\windows”. Like you said the work around is to put the path in before the command like…
%windir%\system32\runas /user:administrator %windir%\system32\cmd
And it would find the RUNAS and CMD executables and you would no longer get the direcotry not found.
http://www.microsoft.com/resources/…
I hope this is what you ment but your posts are little hard to follow.
As for the drive mapping thing I understand the Administrator could not see a drive that was mapped under the users session so I was suggesting you map the drive under the administrators session like…
runas user:administrator “net use u: \\server\directory”
So that it would map the drive for the administrator as well.
BUT IN THE END
We could help you better if you just simply tell us what it is that you are trying to do. From the commands you already showed us it look like you are trying to add a Domain User to the Local Administrator group maybe to give them administrator access to run an install or update only an administrator can do hens your attempts at the runas.
Can you simply tell us what it is you are trying to do and there may be a better approach than the one you are attempting?