Solved

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

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# GridRow get Old/New Value 1 55
WPF - Tooltips for ComboBox items 5 40
Compromised PC? 17 177
Error on link 14 40
In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

23 Experts available now in Live!

Get 1:1 Help Now