Solved

ShellExecute, permissions running as service vs. desktop

Posted on 2012-04-03
8
459 Views
Last Modified: 2012-04-09
Hi

I have a VC++ 6.0 application on Windows7 32bit that can be run as a GUI app direct from the desktop, or it can be run as a service using the "srvany" tool, which is how it is normally running.

One contained method of the application calls ShellExecute() to run a command line compression tool.

If I run the EXE from the desktop, logged in as administrator the call to ShellExecute runs as expected.

If however it is running as a service (configured for Local System login) then the call fails (hangs indefinitely)

The service did not used to fail though, until I put the computer in question onto a different domain. Now it does fail.

It must be a permissions thing, but which? I have tried adding network service, local service, "everybody" with full control rights to all of the folders I can think of to no avail.

Any thoughts?

Thanks
0
Comment
Question by:PMH4514
  • 4
  • 2
  • 2
8 Comments
 
LVL 10

Expert Comment

by:CSI-Windows_com
Comment Utility
It sounds like a job for Procmon. (http://live.sysinternals.com/procmon.exe).

If you create a procmon log and upload it to wetransfer.com, I will take a look for you.

You want to start procmon and then immediately issue a service start.

Once you know the error condition has occurred, immediately stop procmon monitoring.

Do a file save and zip the *.PML file before uploading.

You can contact me at http://csi-windows.com/contactus and I will respond with the email address to send the wetransfer notification to.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
What happens if you run the service as an account different to LocalSystem?
0
 

Author Comment

by:PMH4514
Comment Utility
Ok I figured it out I think.

When I ran the EXE from the desktop, when it tried to run the "7z.exe" (the compression utility) I saw a windows message warning me that it was not a trusted. I believe from the service this same dialog was probably running but without desktop access enabled, it hung..

When I then clicked the checkbox "don't show me this again", subsequent attempts while running as a service succeeded.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 250 total points
Comment Utility
Hmm, instead of reying on 3rd party tools, take a look at http://www.codeproject.com/Articles/4135/XZip-and-XUnzip-Add-zip-and-or-unzip-to-your-app-w ("XZip and XUnzip - Add zip and/or unzip to your app with no extra .lib or .dll") on how to do that in code, e.g.

HZIP hz = CreateZip("test.zip",0,ZIP_FILENAME);

  ZipAdd("test1.txt","test1.txt",0,ZIP_FILENAME);
  ZipAdd("test2.txt","test2.txt",0,ZIP_FILENAME);

  CloseZip(hz);

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Accepted Solution

by:
CSI-Windows_com earned 250 total points
Comment Utility
Doh,
I forgot this until now.  If you ever suspect that  service is popping up a message when running under Windows 7, enable a service called "Interactive Services Detection" and it will tell you a service is trying to display a message and ask if you want to see it.

What you have found makes sense since the marker that triggers the Open File Security Warning for a downloaded file is actually stored in the file itself.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
That's why I'd *never* trust any 3rd party program being launched by a service, especially if the task it has to perform can easily be done in your own code as well.
0
 

Author Comment

by:PMH4514
Comment Utility
thanks JKR I wasn't aware of that XZip ability. I always figured "zip" was tried and true, why even think of reinventing that wheel.

The Interactive Services Detection comment by @CSI-Windows_com is a nice reference for me as well..  

I'm gonna split points between you both unless anybody objects!
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
No objection ;o)
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Article by: Lee
Windows 7 Ultimate and Enterprise (and 2008 R2) introduced a new feature you may not be aware of - Boot from VHD.   Boot from VHD (or what Microsoft refers to asNative Boot allows you to install Windows to a VHD (Virtual Hard Disk) file that is t…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now