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: Problem open command Window(administrator)


31 Dec 2009   #1
dreuzel

win7
 
 
Problem open command Window(administrator)

I'm trying to create some auto setup procedures but can not setup
a CMD administrator command ( non administrator seems to work)



registry tweak
Code:
;  //run  administrator command from explorer 
[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Open Command Window Here (Administrator)"
[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""
all seems to work perfectly on a local device
but as I'm using a networked device (win7/64 fresh install -stable)
the command prompt never apears (immedialty stops)

both on mapped device net user //server/share x: /persist:yes
and direct //server/share (workgroup//homegroup)

any tips to further debug the problem /maybe a solution ???


My System SpecsSystem Spec
31 Dec 2009   #2
TimStitt

Windows 7 Ultimate 64 bit
 
 

Hi dreuzel,

This reg entry appears to create a right click option called "Open Command Window Here (Administrator)", which in turn opens a CMD prompt with admin elevation. You are saying that mapped drives don't open but local drives do, this is correct so far yeah?

Take a look for any other entries in the registry that might effect the results. The places to check are:
Computer\HKEY_Classes_root\*\shell\runas
Computer\HKEY_Classes_root\Directory\shell\runas

Meanwhile I'll test this too and let you know what I find.


Attached Thumbnails
-cmd-registry-entries.png  
My System SpecsSystem Spec
31 Dec 2009   #3
TimStitt

Windows 7 Ultimate 64 bit
 
 

Well I did some testing and found that I would receive the error "The system cannot find the drive specified." when I used the "Open Command Window Here (Administrator)" right click option on a networked mapped-drive shorcut.

However there is a workaround - Don't use the mapped drive shortcut, use a UNC shortcut.

e.g.
\\networkedPC\myshare mapped as Z:\myshare
If you right click on the shortcut Z:\myshare it fails with "The system cannot find the drive specified" error opening in your CMD window.
If you rightclick on the shortcut \\networkedPC\myshare a temporary drive letter is allocated and it works.

Hope this helps.
My System SpecsSystem Spec
04 Jan 2010   #4
dreuzel

win7
 
 

exactly my point
Now using Dos commands I often get problems they can not handle the UNC
this is long term project of MS to get that in order .......
spec's so we are in a locked up situation
require UNC to work all over .....

is there a way to add a mapped device ... (adding something before the
mapped command @="cmd.exe /s /k pushd \"%V\""



are there alternatives as %cd%
what is %v in this case is this explained somewhere
My System SpecsSystem Spec
04 Jan 2010   #5
TimStitt

Windows 7 Ultimate 64 bit
 
 

Quote   Quote: Originally Posted by dreuzel View Post
exactly my point
Now using Dos commands I often get problems they can not handle the UNC
this is long term project of MS to get that in order .......
spec's so we are in a locked up situation
require UNC to work all over .....
Sorry I was away on a job last night... back now to help.

I'm not understanding a key piece of the puzzle here.
1. What are you creating auto setup procedures for (is it software, installation, policy roll outs, etc)? I'm just trying to understand why the right click to admin-cmd is needed? If there is a different way to get the same results, understanding the project will help me help you.
2. Is this to go into a batch or vbs script?
3. The workaround is not good because UNC paths fail for another part of your project is this correct?


Quote   Quote: Originally Posted by dreuzel View Post
is there a way to add a mapped device ... (adding something before the
mapped command @="cmd.exe /s /k pushd \"%V\""
In batch-file world yes; but not so with our mapped drives (and I have no idea why)
you can normally link to CMD lines together with the && command; but I tried for a few minutes and failed with our mapped drives.
I also looked at finding the current path with %~dp0
Code:
set 	curpath=%~dp0
pushd 	%curpath%
but I couldn't get it to work from a single command line (i.e. && fails on this command because the variable needs to be found before it can be pushed). I will try again this evening when I have more time. I'll also look at 'calling' a batch file where we have more options and any other ideas that spring to mind (currently it's 11 am for me).

Quote   Quote: Originally Posted by dreuzel View Post
are there alternatives as %cd%
what is %v in this case is this explained somewhere
@="cmd.exe /s /k pushd \"%V\"
The V% is the variable, in your example it is the directory that CMD is called to.

Yep there's plenty of alternatives depending on what you want to do.
For example if I was to.....
Code:
net use X: \\media\PICTURES
X:
I don't need to cd to get to X, just 'X:' on it's own suffices. But I can't do this in one line 'net use X: \\media\PICTURES && X:' because the drive needs to be mapped first before it can be found.

You could use ~dp0 in place of %cd% for some instances.
for an example paste these into a bat or a command window
Code:
echo this is %%cd%%  %cd%
echo this is %%~dp0 %~dp0
Lastly, for your scenario, is a shortcut that opens a CMD windows in a pre-specified mapped target an option?
My System SpecsSystem Spec
06 Jan 2010   #6
TimStitt

Windows 7 Ultimate 64 bit
 
 

A follow-up.

It doesn't work for me outside of the workaround I provided earlier. Hmm strange stuff.

Let me know the answers to my questions above and we'll think of a route forward.
My System SpecsSystem Spec
11 Jul 2010   #7
mastapat11

win7 ulti x64
 
 
fix

i've been looking for how to do this in win7 for a while. it was SO much more simple in XP. your solution was close and got me started.

here is a fix that worked for me:

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /k \"pushd %L && title Command Prompt\""
My System SpecsSystem Spec
11 Jul 2010   #8
TimStitt

Windows 7 Ultimate 64 bit
 
 

Quote   Quote: Originally Posted by mastapat11 View Post
i've been looking for how to do this in win7 for a while. it was SO much more simple in XP. your solution was close and got me started.

here is a fix that worked for me:

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /k \"pushd %L && title Command Prompt\""
Thanks Mastapat11 for posting that here. I've seen your solution on a number of other threads but I totally couldn't remember "this" thread to find it. It's good of you to leave that here for other readers (and of course triggering this to appear in my active threads once more. Stick around we can do with a fee more script writers ever now and then.
My System SpecsSystem Spec
Reply

 Problem open command Window(administrator)




Thread Tools



Similar help and support threads for2: Problem open command Window(administrator)
Thread Forum
Open Command Window Here as Administrator Tutorials
Open Command Window Here Tutorials
Solved No REG Command in "Open elevated command window here" DOS Box General Discussion
Open Command Window Here - Add or Remove Tutorials
Solved Open Network window with a command? Customization
Open Command Window Here General Discussion
Solved Open elevated command window here General Discussion

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 04:36 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App