Here are the error details:
In the Error List:
Error 1 Cannot register assembly "C:\Users\cboardman\Documents\Visual Studio 2008\Projects\ExcelAddIn1\ExcelAddIn1\bin\Debug\ExcelAddIn1.dll" - access denied. Please make sure you're running the application as administrator. Access to the registry key 'HKEY_CLASSES_ROOT\ExcelAddIn1...' is denied. C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets 3019 9 ExcelAddIn1
In the Build Output:
Target UnmanagedRegistration:
C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(3019,9): error MSB3216: Cannot register assembly "C:\Users\cboardman\Documents\Visual Studio 2008\Projects\ExcelAddIn1\ExcelAddIn1\bin\Debug\ExcelAddIn1.dll" - access denied. Please make sure you're running the application as administrator. Access to the registry key 'HKEY_CLASSES_ROOT\ExcelAddIn1...' is denied.
Done building target "UnmanagedRegistration" in project "ExcelAddIn1.csproj" -- FAILED.
From what I have found online, I need to be running Visual Studio as administrator. This seems like a big hammer for a small nail. Is there a way around this (like a way to run just the registration as administrator)?
Unfortunately there is not an easy way to do this. By default registering the components adds entries to protected keys in the registry (under HKLM in particular). This cannot be done without administrative rights.
It is technically possible to register COM components as a non-admin by using the equivalent keys under HKCU. However it is not a trivial change and I do not believe the .Net tools which register the assemblies can be configured to do this.
I think your best option is to disable registration during build. Then have a separate Admin window open where you can hand register the DLL From for debugging purposes. The re-registration is only really necessary if you change the COM related interfaces or location of the DLL so it doesn't have to be done for every F5.
Closing Visual Studio and re-opening right-clicking on it -> Run as Administrator solved the problem for me.
I had this same problem with Visual Studio 2017.
JaredPar's answer led me to this implementation:
Goto the project's properties
Select Build
Untick Register for COM interop screenshot
Select Build Events
add a Post-build event command line:
for /f %%a in ('dir %windir%\Microsoft.Net\Framework\regasm.exe /s /b') do set current_regasm="%%a"
set command=%current_regasm% $(TargetPath) /tlb:$(TargetDir)\$(TargetName).tlb /codebase ^; sleep 2
set elevated_command="Start-Process PowerShell.exe -Wait -ArgumentList \"-ExecutionPolicy Bypass -Command %command%\"
powershell -noprofile -ExecutionPolicy Bypass -Command %elevated_command% -Verb RunAs"
In the drop-down run the post-build event: select: On successful build screenshot
Run a build
At the end of the build you will see a powershell window run as administrator (depending on your settings you may have a User Account Control (UAC) popup asking you to confirm before it will run).
Note:
This will find the latest .NET framework version and use regasm from there (credit: Scott C).
Increase the ; sleep 2 if you want longer to look at the output to confirm the registration (or use ; pause instead).
Related
I know my question is very similar to this one (Visual Studio Package Installation Error: "Failed to initialize the PowerShell host."). But still the answer that was given there didn't solve my issue.
So like the guy in the link above I have a problem in Visual Studio when I try to create a Web Forms Application or when I want to download and install some Nuget packages (example: AWS DynamoDB sdk) it gives me this error:
failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.
When I did some browsing I came across this command:
Set-ExecutionPolicy Unrestricted
But that didn't help. I still got the error. In the link above someone shares this command:
start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
But I don't really know what difference it makes or what it actually does. After trying the first command and doing:
Get-ExecutionPolicy
I got a response that the value is Unrestricted. But in the other command it was still AllSigned. I also tried running Visual Studio as administrator and that didn't help either.
I figured out, that there was a certificate from Microsoft on the Untrusted list, and I needed to delete it, and now it works.
I am currently testing permissions as an administrator and need to test something as a standard user. There are ways to make standard users run as administrator, but I can't think of a way to run as a standard user as an administrator. If I were to remove my administrator rights, it would take awhile for IT to give me my admin rights back. Is there a better option that doesn't include setting up my dev environment as another user? I'm trying to run Visual Studio as a standard user, if that helps.
Thanks in advance
Create a file with the contents "filename.reg":
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT*\shell\forcerunasinvoker]
#="Run without privilege elevation"
[HKEY_CLASSES_ROOT*\shell\forcerunasinvoker\command]
#="cmd /min /C \"set __COMPAT_LAYER=RUNASINVOKER && start \"\" \"%1\"\""
Run the file and apply registry changes, and then right click "Run without privilege elevation" on the file that needs to be tested. Found this solution from another thread! Thanks!
With visual studio 2012 I created a DLL file in C# which can be used in Access 2013 by referencing it. This all works fine. I Created the DLL and registered it with CMD doing: RegAsm.exe -tlb -codebase C:\MyFolderX\MyDLL.dll
This all works fine, but because the DLL needs to be registered at multiple computers I wanted to do this with 1 click instead of doing it manually at each user computer.
Because users already use a BATCH file to launch the Access frontend application (which uses the DLL) I thought it would be wise to register it once when they use the BATCH startup. So to do this this I added the following in my BATCH script:
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
RegAsm.exe -tlb -codebase C:\MyFolderX\MyDLL.dll
This sadly doesn't work because it has to be done in admin mode and checking the checkbox run as administrator just jumps through my BATCH code without doing anything for some reason.
So I though, why not use a Powershell script to do the same and launch that from my batch script.
To do this I created the following script:
#Register the assembly
$RegAsm = 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe -codebase -tlb'
$Assembly = 'C:\MyFolderX\MyDLL.dll'
Start-Process $RegAsm $Assembly
pause
This however keeps giving the error:
Start-Process : This command cannot be run due to the error: The system cannot find the file specified. At C:\users\me\Desktop\RegisterMyDLL.pst1
+Start-Process $RegAsm $Assembly
InvalidOperation: (:) Start-Process
FullyQualifiedErrorId : InvalidOperationException, Microsoft.Powershell.Commands.StartProcessCommand
I double checked the location of the DLL and it it just there.. Anyone have a clue what I am doing wrong? Perhaps some syntax error or quote to much? Already tried to escape my backslashes but this didn't had any effect.
Or perhaps there is an better way to achieve easy DLL registering at multiple users?
Does this work?
."C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" -codebase -tlb $Assembly
I have checked extensively for a solution to the below error to no avail.
When opening Package Manager Console in Visual Studio, I receive an error stating that "There was an error in loading the format data file.. Path --> to file" cannot be loaded because its execution is blocked by software restriction policies. For more information contact your administrator.
These are all of the things i've done to correct but failed.
Running Powershell as an Administrator.. I Set-ExecutionPolicy to RemoteSigned and Unrestricted in powershell(x86), powershell ISE (x86) and also both 64bit versions..
Running Powershell as an Administrator.. I Set ExecutionPolicy -scope for process, currentuser and localmachine to RemoteSigned and Unrestricted.
Reinstalled Visual Studio.
Set the ExecutionPolicy in Registry Editor to RemoteSigned and Unrestricted.
But I am still getting the error.. Can someone please help..
Thanks
Let me know if you tried the following:
PowerShell says "execution of scripts is disabled on this system."
http://sqlish.com/file-ps1-cannot-be-loaded-because-the-execution-of-scripts-is-disabled-on-this-system-please-see-get-help-about_signing-for-more-details/
Powershell profile.ps1 cannot be loaded because its operation is blocked by software restriction policies
if all fails do the below:
It's possible that you changed the execution policy for 64-bit
powershell and the package manager is running 32-bit (or vice versa).
I'd try opening 32-bit console (PowerShell (x86)) and setting the
execution policy there, as the error is definitely pointing to that
kind of resolution.
Make sure you restart visual studio after changing execution policy so
that changes can take effect. Also make sure you changed execution
policy globally with administrator username and password.
Source:file cannot be loaded because the execution of scripts is disabled on this system
As a workaround, I found this solution (more details at stackoverflow.com/a/53433786/8358565)
Execute the following commands in the Package Manager Console
Set-ExecutionPolicy -Scope Process Bypass
Import-Module "your-solution-directory/packages/EntityFramework<your EF version>/EntityFramework.psd1"
I am trying to get a project to build on a machine but i get the following:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(744,5): warning MSB3075: The command "regsvr32 /s "C:\builds\working\\Win32\Debug\projx86.dll"" exited with code 5. Please verify that you have sufficient rights to run this command.
The previous error was converted to a warning because the task was called with ContinueOnError=true.
Build continuing because "ContinueOnError" on the task "Exec" is set to "true".
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(756,5): error MSB8011: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions.
The user account i am using is an Administrator on the machine so should that not have the highest privileges?
I can go to the startup and right click and run as administrator and that might sort it, but im trying to do an automated build and run of this project, so i cant use that method.
Anyone know how i might fix this?
Solution Explorer ->[YourProject]->Properties->Linker ->General->Per-user Redirection "TRUE"
I found this same issue when working on an C++ ATL project.
In my case, when I added a new ATL class I was missing a line in the resource file (.rc) that adds a resource type "registry" of the new class resource file (.rgs) . This creates the same permission issue stated above.
#LittleFairy answer is probably the best. But you could run Visual Studio as administrator.
Note: You need to explicitly start Visual Studio as administrator. Just the user account having admin rights isn't enough.