Nitsua

Hi All,

I am having problems with running an installation file that I grab off of a local server. Whenever I attempt to run it I get a "Open File - Security Warning" window which ask me again if I want to Run the program. I know of a couple ways around this problem but I am searching for another...

1) Run the program and make sure to uncheck the "Always ask before opening this file" option.

2) Go to the files Properties window and click the 'Unblock' button.

However, I wish to unblock this through C# code. This is becuase the program I am writing will call these types of installers and I don't wish to force my users to 'Unblock' the files themselves.

I attempted to do it with SendKeys:

Code Snippet

private void GrantAccess()

{

// Get a handle to the security window.

Thread.CurrentThread.Join(1000);

IntPtr SecurityHandle = FindWindow("#32770", "Open File - Security Warning");

// Verify that installer is a blocked file.

if (SecurityHandle != IntPtr.Zero)

{

SetForegroundWindow(SecurityHandle);

SendKeys.SendWait("%w");

Thread.CurrentThread.Join(500);

SendKeys.SendWait("%w");

Thread.CurrentThread.Join(500);

SendKeys.SendWait("%r");

Thread.CurrentThread.Join(500);

}

}

but ran into some problems with running this funciton in another Thread multiple times throughout my code. Therefore, I want to avoid the SendKeys method if possible.

So I guess I am asking if there is a simple way to unblock a file. Is there a registry key or something that needs to be changed Any help is appreciated.


Thanks



Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Peter Ritchie

If you digitally sign your installation and the user configures their computer to always accept files with your signature, they won't be asked if the file is okay.

If the security dialog could simply be circumvented by using SendKeys, that would be a huge security hole. Besides, how do you run that code if you're getting the security dialog by running your installation






Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Nitsua

I am sorry I should have been more clear.

I am writing a program that basically uninstalls and old version of another program and installs a newer version of that program, then uninstalls it, then installs it again. Sounds like a wonderfully useful program right

Anyways, the Security Window appear when my program tries to run the installer for the other program. I would like the Security Window to never pop up when my program attempts to run another installer. However, I have been unable to figure out how to do that.




Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Peter Ritchie

How are you running the other installer , Process.Start Is this XP or Vista




Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Nitsua

Process.Start and this is running under XP.



Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Peter Ritchie

Try copying the the installation program to the user's local file system, like their temporary folder, and run from there. e.g. call Path.GetTempFileName(), call File.Copy(remoteFilePath, tempPath, true), call Process.Start(tempPath). when the install is complete call File.Delete(tempPath).




Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Nitsua

The installation program is already located on the user's hard drive. Does having it stored and ran from the temporary folder like you suggested make any difference in bypassing the security window



Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Peter Ritchie

Nitsua wrote:
The installation program is already located on the user's hard drive. Does having it stored and ran from the temporary folder like you suggested make any difference in bypassing the security window
You said earilier it's on a "local server".






Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Nitsua

Sorry again for improperly explaining. When I said "installation file that I grab off of a local server" I should have elaborated on how exactly I run my program.

1) I go into a local serve and find the previous install file and the new install file.
2) I copy those two files into my programs directory on the hard drive of my computer.
3) I then execute my program.
4) My program in turn trys to execute the previous install file and the new install file in order to install/uninstall the different versions.
5) When my program attempts to run the install files it encounters the pop-up Windows Security Window.

I would like to figure out a way to programmatically remove the attribute that declares the files as being "unsafe".

Thanks Again!





Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Peter Ritchie

The "Open File - Security Warning" won't show up if you use Process.Start to run an install program (*.MSI, *.EXE). I cannot reproduce that dialog by simply running an install program on the local hard drive.

There must be something else going on, please supply sample code that reproduces the problem.






Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Nitsua

Code Snippet

OldFileName = programdir + oldinstallfile;

OldUninstallArgs = @"/L1033 /p" + oldpassword + @" /s /f1" + programdir + program + "_UNINSTALL_"

+ oldrevnumber + ".iss";

P1.StartInfo.FileName = OldFileName;

P1.StartInfo.Arguments = OldUninstallArgs;

P1.Start();

The above code builds the file's path and command line arguments using a settings file. Examples for OldFileName and OldUninstallArgs are listed below.

OldFileName = C:\ProgramName\OldInstall.exe

OldUninstallArgs = /L1033 /poldpassword /s /f1C:\ProgramName\program_UNINSTALL_12.iss

If you are trying to duplicate this problem you need to make sure that the Install.exe you try to run is blocked by your computer. If the program would run without the Security Window if you just plain double-clicked it than it will not show a Security Window if ran with the above code. I believe that if you execute the same OldFileName + OldUninstallArgs through the cmd.exe window than the Security Window gets bypassed, but for some reason P1.Start() does not bypass it the same way.

Thanks for the continued help Peter. An answer to this would help both myself and a friend that has also run into similar issues with a program he is writing.





Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Peter Ritchie

Nitsua wrote:

Code Snippet

OldFileName = programdir + oldinstallfile;

OldUninstallArgs = @"/L1033 /p" + oldpassword + @" /s /f1" + programdir + program + "_UNINSTALL_"

+ oldrevnumber + ".iss";

P1.StartInfo.FileName = OldFileName;

P1.StartInfo.Arguments = OldUninstallArgs;

P1.Start();

The above code builds the file's path and command line arguments using a settings file. Examples for OldFileName and OldUninstallArgs are listed below.

OldFileName = C:\ProgramName\OldInstall.exe

OldUninstallArgs = /L1033 /poldpassword /s /f1C:\ProgramName\program_UNINSTALL_12.iss

If you are trying to duplicate this problem you need to make sure that the Install.exe you try to run is blocked by your computer. If the program would run without the Security Window if you just plain double-clicked it than it will not show a Security Window if ran with the above code.

You didn't mention that the application you're trying to run is blocked. There nothing you can do to get around executing a blocked application; that's kinda the point of blocking an application. What's blocking the application






Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Nitsua

Not sure exactly sure. I assume Windows itself is blocking the application. At the bottom of the file's Properties window there is a Security warning saying:

"This file came from another computer and might be blocked to help protect this computer."

Beside that warning is an "Unblock" button which fixes the problem I want to try to solve programatically. Also, when the program is ran the "Open File - Security Warning" complians about an invalid digital signature and says the publisher could not be verified. Then asks if I really want to run this software.

I just figured out that if I unblock it while its on the server than its automatically unblocked if it ever gets downloaded from the server. That seems like it will solve my problems, but I still feel that there should be some way to unblock the file through C#. It seems like a file attribute that is turned on in certain cases and it seems like I should be able to unflag that attribute through code. Doesn't that seem like it should be possible




Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Peter Ritchie

If it's some sort of anti-virus software (AVS) like Live OneCare, you asking how to circumvent an anti-virus problem, which isn't possible. It's doing what it's supposed to do, inform the user an installation is being run. You shouldn't expect any amount of programming or signing would get around that. The user will have to manually configuring the AVS.




Re: Visual C# General Fixing "Open File - Security Warning" Window Problem

Nitsua

Alrighty, Thanks anyways for the help and the effort.