Solved

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

Posted on 2008-10-20
5
222 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: btan
The intent is not to repeat what many has know about Ransomware but more to join its dots of what is it, who are the victims, why it exists, when and how we respond on infection. Lastly, sum up in a glance to share such information with more to help…
Recently, I read that Microsoft has analysed statistics for their security intelligence report. It revealed: still, the clear majority of windows users do their daily work as administrator. An administrative account is a burden, security-wise. My ar…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

806 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