Solved

.NET - Using Shell function to unzip a file raises a security error

Posted on 2008-10-20
5
219 Views
Last Modified: 2013-12-04
I have a FileSystemWatcher that watches for files in a directory.

When a zip file lands in there, i execute winzip 11 using the following command;

Shell("C:\Program Files\WinZip\WINZIP32.EXE -e " & FilePath & " C:\Unzipped\", AppWinStyle.Hide, True)

When this command executes, .NET does not fall over. Instead, a message pops up FROM WINZIP (not from .NET - no exception is raised);

"Could not open C:\Test.zip
Probable cause: file sharing or file permissions problem."

I need to be able to call winzip under the administrator account - which seems strange because this application runs under the administrator account.
0
Comment
Question by:tfsln
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
MatthiasVance earned 500 total points
ID: 22762839
Are you sure the file is fully written when your FileSystemWatcher fires the event?
It also fires when the file is created or during writes.
I suggest you try reading the file programmaticaly, if that succeeds, shell winzip again.

Kind regards,

Matthias Vance
0
 

Author Comment

by:tfsln
ID: 22762852
If the file has not yet been created, then how can i instruct the FileSystemWatcher to not report files until they are created?

If what your saying is correct, and it fails programmatically (which i suspect it will), then what would i do?
0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22762914
If your program gets an IOException when trying to read the file you don't Shell() Winzip, otherwise, you do. I think this is safe because the FileSystemWatcher will fire another event when another block of the file (and possibly the last) is written. This time your read will succeed and it will run winzip.

Kind regards,

Matthias Vance
0
 

Author Comment

by:tfsln
ID: 22772902
Your original answer solved my problem.

I did some testing and just for your own information; the FileSystemWatcher does not raise the Created event on each block of the file written. It raises one event when the file is created (the event will fire even if the file isnt finished copying - which caused my problem).
0
 

Author Closing Comment

by:tfsln
ID: 31508064
Cheers mate.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Security measures require Windows be logged in using Standard User login (not Administrator).  Yet, sometimes an application has to be run “As Administrator” from a Standard User login.  This paper describes how to create a shortcut icon to launch a…
Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

13 Experts available now in Live!

Get 1:1 Help Now