Create a context menu entry doing runas

B

bxb7668

I have a number of Perl scripts that I often have to execute as a
different userid. Up to now I open a command prompt and launch the
script using the runas command.

I would like to be able to add an item to the Windows context menu for
items with a .pl extension to automatically launch the script using
runas. I've created the menu entry as:

%windir%\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

This doesn't work. It gives me an error message of:

C:\cc_trigs\thescript.pl
Access is denied

If I right-click and select the default Open, the script runs just
fine.

Another problem with runas when I use it from the command line is that
it doesn't remember drives that I've already mapped. I'm guessing that
this is because the runas userid hasn't been authenticated. To get the
mapped drive to work I must use the "net use P: \\server\share"
command to make it available. I assume that to get the context menu to
work, the target Perl script must either be on my local drive or I
must include the "net use" command as part of the command string.

Can anyone help me with these issues?

Thank you
Brian
 
R

Ramesh, MS-MVP

Try:

runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

-or-

C:\Windows\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

-or-

%windir%\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*
(In this case, make sure that the value type is REG_EXPAND_SZ, not REG_SZ)

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows Shell/User]
Windows® Troubleshooting http://www.winhelponline.com


I have a number of Perl scripts that I often have to execute as a
different userid. Up to now I open a command prompt and launch the
script using the runas command.

I would like to be able to add an item to the Windows context menu for
items with a .pl extension to automatically launch the script using
runas. I've created the menu entry as:

%windir%\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

This doesn't work. It gives me an error message of:

C:\cc_trigs\thescript.pl
Access is denied

If I right-click and select the default Open, the script runs just
fine.

Another problem with runas when I use it from the command line is that
it doesn't remember drives that I've already mapped. I'm guessing that
this is because the runas userid hasn't been authenticated. To get the
mapped drive to work I must use the "net use P: \\server\share"
command to make it available. I assume that to get the context menu to
work, the target Perl script must either be on my local drive or I
must include the "net use" command as part of the command string.

Can anyone help me with these issues?

Thank you
Brian
 
A

Another Brian

Thank you, Ramesh. the first suggest worked with one caveat.

Unfortunately the Perl script is on a networked drive that isn't
authenticated to the different userid. Consequently it is unavailable
until I run a "net use p: \\server\share" command. I got around this
by having the runas command execute a bat file that was local to my
PC. The bat file contains:

@net use p: \\app-nwss-001\cc_isoall
perl %1

which activates the P: drive and then executes the script. If the
script happens to be on the C: drive, no matter. The final command
that I put into the context menu item is:

runas.exe /user:nw\myuserid "cmd /k C:\Perl\bin\DKP_PERL.BAT %1" %*

Thank you for pointing me in the right direction.

Try:

runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

-or-

C:\Windows\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

-or-

%windir%\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*
(In this case, make sure that the value type is REG_EXPAND_SZ, not
REG_SZ)

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows Shell/User]
Windows® Troubleshooting http://www.winhelponline.com


I have a number of Perl scripts that I often have to execute as a
different userid. Up to now I open a command prompt and launch the
script using the runas command.

I would like to be able to add an item to the Windows context menu for
items with a .pl extension to automatically launch the script using
runas. I've created the menu entry as:

%windir%\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

This doesn't work. It gives me an error message of:

C:\cc_trigs\thescript.pl
Access is denied

If I right-click and select the default Open, the script runs just
fine.

Another problem with runas when I use it from the command line is that
it doesn't remember drives that I've already mapped. I'm guessing that
this is because the runas userid hasn't been authenticated. To get the
mapped drive to work I must use the "net use P: \\server\share"
command to make it available. I assume that to get the context menu to
work, the target Perl script must either be on my local drive or I
must include the "net use" command as part of the command string.

Can anyone help me with these issues?

Thank you
Brian
 
R

Ramesh, MS-MVP

You're welcome, Brian.
Thanks for the update!
--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows Shell/User]
Windows® Troubleshooting http://www.winhelponline.com


Thank you, Ramesh. the first suggest worked with one caveat.

Unfortunately the Perl script is on a networked drive that isn't
authenticated to the different userid. Consequently it is unavailable
until I run a "net use p: \\server\share" command. I got around this
by having the runas command execute a bat file that was local to my
PC. The bat file contains:

@net use p: \\app-nwss-001\cc_isoall
perl %1

which activates the P: drive and then executes the script. If the
script happens to be on the C: drive, no matter. The final command
that I put into the context menu item is:

runas.exe /user:nw\myuserid "cmd /k C:\Perl\bin\DKP_PERL.BAT %1" %*

Thank you for pointing me in the right direction.

Try:

runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

-or-

C:\Windows\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

-or-

%windir%\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*
(In this case, make sure that the value type is REG_EXPAND_SZ, not
REG_SZ)

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows Shell/User]
Windows® Troubleshooting http://www.winhelponline.com


I have a number of Perl scripts that I often have to execute as a
different userid. Up to now I open a command prompt and launch the
script using the runas command.

I would like to be able to add an item to the Windows context menu for
items with a .pl extension to automatically launch the script using
runas. I've created the menu entry as:

%windir%\system32\runas.exe /user:nw\myuserid "cmd /k
C:\Perl\bin\perl.exe %1" %*

This doesn't work. It gives me an error message of:

C:\cc_trigs\thescript.pl
Access is denied

If I right-click and select the default Open, the script runs just
fine.

Another problem with runas when I use it from the command line is that
it doesn't remember drives that I've already mapped. I'm guessing that
this is because the runas userid hasn't been authenticated. To get the
mapped drive to work I must use the "net use P: \\server\share"
command to make it available. I assume that to get the context menu to
work, the target Perl script must either be on my local drive or I
must include the "net use" command as part of the command string.

Can anyone help me with these issues?

Thank you
Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top