execute registry script from vb.net - vb.net

I am trying to work for an application where i need to embed registry code in my program. Basically this is a Windows App.
My registry code is
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\DesktopBackground\Shell]
"icon"=""
"Position"="Bottom"
[HKEY_CLASSES_ROOT\DesktopBackground\Shell]
#="system.exe -L"
This code is stored in a registry file. All i need to do is invoke this script on an event handler say button_click.
Options i have is write this code as a string and execute this string.. or simply have a collection of *.reg files which i may execute on button_click.
I understand my app requires UAC, and i would be giving that permission for my app in App Manifest.
Can anyone pls suggest me how to execute registry file (.reg) stored placed in a folder

Use Process.Start with a ProcessStart.UseShellExecute = True

Related

Unable to add excel add-in for all users

We have an application which shows up as an Excel ribbon.
We have installed the application in our test environment through administrator login. We are trying to make a per machine installation.(Please note that in production environment, the installation will be through system account).
When we login as user to the same PC, we don't see the excel addin in the Excel ribbons. We don't see the addins anywhere in the list of addins as well.
We have tried using Active setup,Userstat,setting the values of properties as ALLUSERS=1, RegisterForAllUsers= True, InstallScope= perMachine, InstallAllUsers = Everyone, RunActionsAsInvoker = True . Also the privileges has been changed from user to admin in all the cutom actions and in manifest file as well. All these changes where made as we understood that the application used to package is Addin express and so the msi creation with privileges as admin is possible.
Unfortunately none of these changes seems to help us.
What we would need is an msi which we can install on per machine basis.
From the situation mentioned in the question, we had tried a lot of options and finally following approach works for us:-
Create a package which would place a powershell shortcut in the startup folder.
The shortcut would in turn call or execute a powershell script.
The powershell script would
1. check if the registry key for that particular add-in is available in HKCU.
We had our registry key as "HKCU\Software\Manufacturer Name\Product Name" which in turn had a string value "Installed".
If the registry key is not available for the user, then install the package with tranform.
3.If the registry is already available, then script doesn't make any change.
The package is installed as an Admin and once the user logs in, then automatically the cmd file is executed and the add-in is installed.
Since this was the first version of the product, we didn't have to handle version compatibility.

WiX Shell Command Conditional Installation

I'm new to WiX (and Windows development in general), and I'd like to add logic to my installer that will cause the installation to fail with a friendly error if the shell command fails. I've seen the ShellExecute CustomAction and instructions for Conditional Installation, but I'm not sure how to tie these together.
I prefer to write my own Custom Action in either VbScript or C# while calling API method ShellExecute. In this way, we have good control over its return code (if ShellExecute fails) and we can display our own user friend message and terminate the installation (or set it to roll back).
Here is an example not specific to ShellExecute, but how to quit from Installation while showing your own user friend message:
http://devdare.blogspot.com/2012/07/how-to-quit-installation-from-vbscript.html
For using ShellExecute in VBScript Custom Action:
http://ss64.com/vb/shellexecute.html
Hope this helps.

Custom Action running as 64-bit on 32-bit install

This application is a plugin for a larger application. To complete our installation, we need to run a batch script provided by the main application. The batch script errors saying that a certain registry key doesn't exist, but it exists in the WOW6432 part of the registry. It appears that the custom action is being ran as 64-bit, attempting to fetch the registry without the WOW6432. I have no access or control of the batch file, so I can't change that to check both parts of the registry.
How can I make sure the custom action is ran as 32-bit?
The cmd process is running in 64-bit mode when the batch file is ran.
Edit: To check if it is running 64 vs 32, I created a seperate batch script which checks looks for a registry key in HKLM/Software/SomeKey. The key is actually located in HKLM/Software/Wow6432/SomeKey. Manually running it with %windir%\SysWow64\cmd.exe (task manager flags this process as *32) works fine. Running it with the regular cmd.exe it cannot find the registry key. Putting this same batch file as a custom action in wix results in the non-*32 cmd to open and the regkey search failure.
I set this batch in Wix like this:
<CustomAction Id="batchCA" Property="BATCHFILE" ExeCommand="" Execute="deferred" />
Where BATCHFILE is a property set the the batchfile path. i.e "C:\temp\batch.cmd". It seems to run fine, but am I doing this wrong?
You should explicitly specify the command-line exe to be 32bit. So instead of directly calling your batch like "yourScriptName.cmd", you should use this:
%windir%\SysWoW64\cmd.exe /c yourScriptName.cmd

Running VBScript from UIAccess VB app using MSScriptControl

I'm trying to run some VBSCRIPT from within my application. This works fine when I run my program from within VB. But once I add "UIAccess=true" to my manifest and digitally sign my exe with my certificate, I am unable to run the code any more. It gives errors when I try to interface with any program saying "429: ActiveX component can't create object: 'myApp.Application'". Anyone have any idea why it would run fine in the IDE but not with an application with uses UIAccess? Here is the code:
Dim scriptRunner As New MSScriptControl.ScriptControlClass
scriptRunner.Language = "VBScript"
scriptRunner.AllowUI = True
scriptRunner.Timeout = 3000
scriptRunner.AddCode(scriptStr)
scriptRunner = Nothing
In googling around, I found this website.
it says
Applications with the uiAccess flag set to true must be Authenticode signed to start properly. In addition, the application must reside in a protected location in the file system. \Program Files\ and \windows\system32\ are currently the two allowable protected locations.
maybe it works in your IDE because your IDE is within \program Files\, but outside of your IDE you are running the signed application NOT within \program files or \windows\system32

How can i create a directory in drive C:\?

i am trying to create a directory in drive C: (at a win7 target machine) with Directory.CreateDirectory but so far no luck.
I believe the problem has to do something with permissions-security... So here i am..
How can i create a directory in drive C?
You need to run your application in elevated mode (via UAC). How this can be done is shown in the above StackOverflow thread:
UAC, Vista and C# - Programatically requesting elevation
Before executing the code to switch in elevated mode you should do a check if you application is running on Vista, Windows 7 or above.
You should not use the root of C for an ordinary application. If you're just using it because you think it's a folder you can count on, use AppData or Temp instead. If this is not an ordinary application, but is instead an administrative application, then put a manifest on it requesting it elevate (requireAdministrator) so that it can gain access to the areas of the hard drive and registry protected by UAC.
DirectoryInfo dir = new DirectoryInfo(#"c:\MyDir");
dir.Create();
hope this will help u...