IIS5/XP/aspnet_wp, changing user

  • Thread starter Thread starter Mark
  • Start date Start date
Hi Allen...

Another stumper, though not directly related to asp.net.

When I run the command through MyDll2 with
appName = "cmd.exe"
commandLine = "/S /C 2>&1 > C:\run.log MyCmd.exe -args=1..."

it works and output is put in the log file.

If I put quotes around the command I really want to run (i.e.
appName = "cmd.exe"
commandLine = "/S /C 2>&1 > C:\run.log \"MyCmd.exe -args=1...\""
)
the log file is created but no output is put in it.

If I run the whole thing from the prompt (i.e.
cmd /s /c 2>&1 > C:\run.log "MyCmd.exe -args=1..."
)
the whole thing runs and puts the output in the log file.

Why would putting quotes around the ultimate command and args cause it not
to work in MyDll2?

I started down this route because I wanted to compound a few commands in
what MyDll2 was running. Some of the things I want to run are baked .exe's,
so I was going to do the following:
cmd /s /c 2>&1 > C:\Run.log "echo Run by John & date /t & time /t &
MyCmd.exe -args=1..."

That's when I discovered that quoting the ultimate execution command stopped
the output and probably the execution when run through MyDll2. Works fine
from the prompt though.

THanks
Mark
 
Hi Mark,
You seemed to imply that <website>/bin should automatically be on the PATH to
find the dll, but it didn't seem to be the case. I know that ASP.Net finds
any .net dlls in /bin. Is that different for bringing in unmanaged dlls?

I assume you're using Web Application. It seems you're writing Web Site
application, however. Refer to the following discussion for more details
please:
http://stackoverflow.com/questions/344608/unmanaged-dlls-fail-to-load-on-asp
-net-server
I'm also curious why the standard framework mechanisms and even pinvoke to
unmanaged code failed so badly when tried from inside ASP.Net in so many
different ways but it's probably beyond the scope of the forum to get to the
bottom of it.

This is by design. The cause is mentioned in my first reply. In a word,
what you want to do is not a safe action. If you have to do so you can run
as LocalSystem.
If I run the whole thing from the prompt (i.e.
cmd /s /c 2>&1 > C:\run.log "MyCmd.exe -args=1..."
)
the whole thing runs and puts the output in the log file.

It looks like if I try this it works fine:

/s /c \"C:\\TestApp.exe\" > C:\\log\\run.log 2>&1

Could you test it to see if it works?

Regards,
Allen Chen
Microsoft Online Support
 
Hi Mark,
Why would putting quotes around the ultimate command and args cause it not
to work in MyDll2?

Have you solved this issue?

Regards,
Allen Chen
Microsoft Online Support
 
Hi Allen...

Nope...

As I said, originally I stumbled across this because I was trying to run
compound commands to augment the output (e.g. "date/t & time /t &
MyCommand.exe ...")

The first problem I had was that redirecting the output at the *end* of the
command line only ended up redirecting the output of the last command. In
otherwords even though it ran date and time, that output didn't get
redirected to the log.

That's when I discovered that redirecting the output at the beginning of the
line (e.g.
cmd /s /c 2>&1 > out.log "date /t & time/t & MyCommand.exe...") caught *all*
the output in the log file - at least when run from a cmd box.

When I did this through MyDll2.dll, I got no output at all. That's when I
discovered the weird situation that, when run through MyDll2.dll, quoting the
commands to execute produce no output and run no programs.

In other words,
cmd /s /c 2>&1 > out.log "anything.at.all.exe"
doesn't work through MyDll2.dll but works just fine if you just
cut-paste-run it in a dos box.

cmd /s /c 2>&1 > out.log anything.at.all.exe
works just fine either way, but then you don't get to compound any commands.

Thanks
mark
 
Well guess what... You try all possible permutations sometimes you stumble
across one that works.

What finally ended up working was quoting *and* parenthesizing the compound
commands: e.g.

cmd/s /c "(date/t & time /t & MyCommand.exe)" 2>&1 > out.log

Thanks
Mark
 
Well guess what... You try all possible permutations sometimes you
stumble
across one that works.
What finally ended up working was quoting *and* parenthesizing the compound
commands: e.g.
cmd/s /c "(date/t & time /t & MyCommand.exe)" 2>&1 > out.log

Good work Mark! Finally we have a solution to this issue! But please notice
this is not a secure behavior. First your application is running under
localsystem account, which has a lot of priveleges that may cause security
issues. Secondly to start cmd potentially let users have more control to
the server than what you expected. You need to find a way to prevent string
injection attact etc.

Thank you for using our Newsgroup Support Service!

Regards,
Allen Chen
Microsoft Online Community Support



=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
=================================================
 
Back
Top