8

I made a program in C#. It copies itself to startup if the user ticks the box to do so.

The application adds itself to startup using the registry key "SOFTWARE\Microsoft\Windows\CurrentVersion\Run".

It works fine, aside from the problem that every time the machine is restarted, the user is prompted whether they're sure they want to run the program because it's blocked by Windows because it "comes from another computer".

Any way I can get rid of this Windows "blocked" flag through the code so that the user isn't prompted everytime the program tries to run itself?

Thanks

General Grievance
  • 4,555
  • 31
  • 31
  • 45
user3418061
  • 97
  • 1
  • 1
  • 2
  • File is copied locally or from another computer? – thepirat000 Mar 14 '14 at 01:31
  • 2
    Another solution in this case would be to do the copy manually, i.e., read the data from the source file and write it to the destination file rather than using file copy. That way, the extra data tagged to the file will be stripped out. On the downside, so will the timestamp information. – Harry Johnston Mar 14 '14 at 06:37
  • Use [DeleteFile](http://pinvoke.net/default.aspx/kernel32/DeleteFile.html?diff=y) API passing the filename followed by :Zone.Identifier, i.e. `DeleteFile("c:\\yourfile.exe:Zone.Identifier");` – thepirat000 Mar 14 '14 at 15:08

2 Answers2

2

When downloaded/copied to the machine, Windows attached a Zone Identifier (http://msdn.microsoft.com/en-us/library/dn392609.aspx) based in the location it the file came from (http://msdn.microsoft.com/en-us/library/ms537183.aspx)

In order to unblock the file, you will either have to have the user open up the file properties and click the Unblock button, or remove it yourself.

You can find more information on how this happens and a few ways to do so (including with code) here: http://weblogs.asp.net/dixin/archive/2009/03/14/understanding-the-internet-file-blocking-and-unblocking.aspx

Brendan Grant
  • 937
  • 7
  • 16
  • The question was about how to do this in C# code, and your answer was "have the user do it with file properties or do it yourself in code". As *how to do so in code* was the entire question, I'm failing to see where the answer is here. – Ken White Mar 14 '14 at 02:09
  • @KenWhite Actually the last link has another link and the code to do it programmatically, you probably have to read the entire article. [This](http://www.codeproject.com/Articles/2670/Accessing-alternative-data-streams-of-files-on-an) explains how to access alternate data streams from C# – thepirat000 Mar 14 '14 at 02:27
  • 5
    @thepirat000: If the question is posted here, the answer should be posted here. External links should be used as additional references, not as the main content. "The off-site link has another off-site link that has information that includes code." is not an answer **here**. It's about as much an answer as "Google says you can look here and follow the links for an answer" would be, IMO. – Ken White Mar 14 '14 at 02:33
-1

try powershell script http://technet.microsoft.com/en-us/library/hh849924.aspx

Unblock-File Unblocks files that were downloaded from the Internet. Syntax Parameter Set: ByPath Unblock-File [-Path] [-Confirm] [-WhatIf] [ ]

Parameter Set: ByLiteralPath Unblock-File -LiteralPath [-Confirm] [-WhatIf] [ ]

Detailed Description The Unblock-File cmdlet lets you open files that were downloaded from the Internet. It unblocks Windows PowerShell script files that were downloaded from the Internet so you can run them, even when the Windows PowerShell execution policy is RemoteSigned. By default, these files are blocked to protect the computer from untrusted files. Before using the Unblock-File cmdlet, review the file and its source and verify that it is safe to open. Internally, the Unblock-File cmdlet removes the Zone.Identifier alternate data stream, which has a value of "3" to indicate that it was downloaded from the Internet. For more information about Windows PowerShell execution policies, see about_Execution_Policies (http://go.microsoft.com/fwlink/?LinkID=135170). This cmdlet is introduced in Windows PowerShell 3.0.

user299654
  • 36
  • 3