Solved

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

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

830 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