|It's not a path thing. cmd is in the path. Actually, I guess I should technically change that part to be %COMPSPEC% for maximum compatibility.|
I don't understand what's so hard about what I'm trying to do.
For the sake of saving on typing, when I say RUNASADMIN, I mean runas /env /user:administrator.
If I'm at a C:\> prompt, and I type RUNASADMIN cmd, I get a C:\> prompt as administrator.
But if I'm at a U:\> prompt and type RUNASADMIN cmd, I would get a U:\> prompt as administrator. But the U: drive doesn't exist as administrator, so instead, I get a "Directory not found" error, and I never see a command prompt. I can't run net use, because there's nowhere to run it from.
So I created a batch file that includes RUNASADMIN, and it works fine, as long as it's run locally. If I copy it to a server and browse to it via a UNC path and double-click, it still works, because even though CMD.exe doesn't recognize UNC paths as a working directory, it defaults back to C:\Windows. But if I map a drive, and browse to the batch file via the mapped drive, THAT's when I get the error. Because the U: drive, my current context, DOES NOT EXIST for administrator. By switching my working directory to C: by adding %SYSTEMDRIVE% && before my command, it doesn't matter where the file was run from. So no errors.
PLEASE tell me you understand what's going on now. Please?