Searching the registry for a string in vb.net? - vb.net

I am trying to do a query on the registry for uninstallation of a program but dont know where to start.
The structure would be like so:
If {123-456-789} exisits in registry then run
Msi.exe /x {123-456-789}
Otherwise run
Msi.exe /x {987-654-321}
Does anyone have any pointers on how to do this?

Start from here :-)
"Reading from and Writing to the Registry"
http://msdn.microsoft.com/en-us/library/85t3c3hf%28v=vs.71%29.aspx
Check how RegistryKey / Registry / RegistryHive class works,
Take a starting point (in the registry), then enumerate all the key/subkey/value, and compare the string/value found to check if they are what you are looking for.

https://superuser.com/questions/65714/how-can-i-search-the-windows-registry-with-regular-expressions googling for this - I found this article.. the exporting it idea might work for you?
Also this guy seems to do what you need.
http://www.vbdotnetforums.com/vb-net-general-discussion/38567-regex-visual-basic-net-2005-case-insensitive-registry-search.html

Related

Retrieving exit code in ProcessExit handler?

I'm writing a little C++/CLI application that calls a lot of libraries. Inside some of them there is at least one exit(xyz) and I catch it by handling AppDomain.ProcessExit(). Works fine. Since the call to exit(...) has already been done, I would like to retrieve the exit code passed to this function.
My problem is that it seems that the exit code is not available before the complete exit of the process and, of course, in my handler, the process is not "completely" terminated/exited. For example, I tried:
int ec = System::Diagnostics::Process:GetCurrentProcess()->ExitCode;
But I got an exception. Also it seems that the API Win32 GetExitCodeProcess() will return me a STILL_ACTIVE error??? I hope this value is registered/accessible somewhere?
Any idea? I'm running on Win 7 and Win 10. Thanks in advance for your help.
I have done this using a batch file before.
I create a file called runprogram.cmd(you can create your own name if desired) and place the following in it: -
#echo off
"programname.exe"
echo %errorlevel%
#echo on
pause
replace programname.exe with your exe's name.
double click on the file to run it.
System::Environment::ExitCode;
Process, AppDomain, Environment... I missed this one! I hope my question/answer will help someone some day!

Asterisk dial command return dialed number

I'm looking for a variable that can tell me which number 'won' the call on a multi-target Dial command.
Example:
Dial(SIP/1000&SIP/1001&SIP/1002,30)
Set(the_unlucky_winner=${...})
I'm not getting anything from the ${DIALEDPEERx} variables. Sounds like these vars are broken but I don't know if this is what I should be using.
Ancient version 1.2.14 deployed at this site. All clients are SIP
Thanks anyone
Only realistic way do that - cal via Local channle like freepbx do(check freepbx.org source) or use Macro on answer(i am afraid not work in 1.2)
Parse the contents of the CDR record for the file. One of the fields is dstchannel which will hold a value like SIP/1002-9786b0b0.
Also keep in mind that the call variable stack is wiped on hangup, unless you have an "h" (hangup) extension defined for the context. So, you can most easily handle your post-call processing there.
Further Reading:
http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/asterisk-SysAdmin-SECT-1.html
Please Note:
if this answer turns out to solve your problem, please "accept" it for the benefit of others trying to solve the same problem later
Hi all I have a solution to this problem. It is working fine for both normal dial and multi target dial.
In dialstring add a macro, here I am adding "followme" macro.
M(followme)
$agi->exec("dial", "SIP/6001#sip.example.com&SIP/6002#sip.example.com,rtTgM(followme)");
Then after call is answered it ll go to context
[macro-followme]
In this context you write one script to get the connected calls information by
$dstchannel=$agi->get_variable("DIALEDPEERNUMBER");
The way I managed to do it is as follows
Dial(SIP/1000&SIP/1001&SIP/1002,30,M(whoanswered))
[macro-whoanswered]
exten => s,1,NoOp(${CHANNEL})
You will see that the actual extension that answered is containes in ${CHANNEL}
If 1001 answered the channel will be something like SIP/1001-00017cf1
Just use the CUT command to cut it by / and -

VB.Net - Use wild card in My.Computer.Registry.GetValue

I have a VB.NET script that looks up the current version of java installed.
Everything worked great until java 8 came out.
Back in Java 7 i would do this.
My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment", "Java7FamilyVersion", Nothing)
In Java 8 (Java8FamilyVersion) is gone and has replaced with (FullVersion).
The problem is FullVersion is behind two more folders one with the version (18.0_25) Then another folder call MSI
So here is the problem; right now the first folder is called 18.0_25, but in the future it would be changed to something like 18.0.55ish.
I can't update my software that often, so i would like to use a wilcard in the getvalue
IE something like this
My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment\1.8.*\MSI", "FullVersion", Nothing)
Above didn't work is their anything that would work?
Use the GetSubKeyNamesmethod to enumerate the subkey(s) of "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment", then pick the alphabetically last (so that you do not fall for any old 1.7_xx keys or the 1.8 key)
You could grab a file version from one of the Java .dll files. Sorry, I don't have Java installed, but something like this might help you:
Dim fvi As FileVersionInfo = FileVersionInfo.GetVersionInfo("somefilename.dll")
Debug.Print(fvi.ProductVersion)
You can fiddle with the returned properties for major, minor, etc. You should be able to build a version string to get what you need.

Compiling and Llnking to used modules in external directory Compaq Fortran command prompt

I've already asked a similar question, here:
Linking to modules in external directory Compaq Visual Fortran command prompt
And I thought that the first answer was correct (that is, in the manual they say you can simply specify the path name before the module), but after deleting the temporary files in my library folder, this approach seemed to stop working. Trying with the /include[:path] approach, here is my .bat file:
df /include:..\FORTRAN_LIB\ __constants
myIO griddata_mod myfdgen myDiff magneticField /exe:magneticField
And an error is returned saying:
__constants
myIO
griddata_mod
myfdgen
myDiff
magneticField
f90: Severe: No such file or directory
... file is '__constants'
Again, I apologize that this question is VERY specific, but it seems like it should be simple and does not work at all.
p.s. Originally, I was using:
df ..\FORTRAN_LIB\__constants ..\FORTRAN_LIB\myIO
..\FORTRAN_LIB\griddata_mod ..\FORTRAN_LIB\myfdgen
..\FORTRAN_LIB\myDiff magneticField /exe:magneticField
But, as I've said, it stopped working after I deleted the temporary files in my FORTRAN_LIB folder. Also note, these .bat files used only one line, I've broken them into several lines just for readability. I would prefer using the /include[:path] option since that seems like a better solution.
Okay, so I think I figured out a workaround at the very least. I understood that the /include[:dir] specifies to search in "dir" for included files. But it seemed from documentation, that this also specifies to search for USEd modules but that doesn't seem to be the case.
My program now looks like this:
include '..\FORTRAN_LIB\__constants.f90'
include '..\FORTRAN_LIB\computeError.f90'
include '..\FORTRAN_LIB\griddata_mod.f90'
include '..\FORTRAN_LIB\myfdgen.f90'
include '..\FORTRAN_LIB\myDiff.f90'
include '..\FORTRAN_LIB\myIO.f90'
program magneticField
use constants
use computeError_mod
use griddata_mod
use myfdgen_mod
use myDiff_mod
use myIO_mod
implicit none
...
And my DF command like this:
df magneticField /exe:magneticField
And everything seems to work fine. It would be nicer to have the /include[:dir] option, but so long I'm able to reach in a separate directory, I'm satisfied. If anyone can find a better solution I'll switch the checkmark. I hope this helps with anyone else who was confused like me.

How to convert certain C# code to VB.NET

I've been googling around around and read this article
C# How to get SQL Server installation path programatically?
and this is exactly what i need in VB.NET , however i'm not good in translating this code into VB.NET Code. So, any help would greatly appreciated. Thank you.
Note : I'm using SQL Server 2005 and Visual Basic 2008
While the question was originally titled about retrieving SQL Server's installation path, I felt it was more about a code translation problem (the solution already existed, just not in the right language).
But then I thought that the method in the original code was fairly blunt.
Evan provided you with what I assume is a workable translation of the existing solution. But probably a much easier way to perform this specific task - assuming you just need to find the installation path for an instance you're already connected to, and assuming that a user who can read the registry will also have VIEW SERVER STATE permissions - is to issue this simple query against the DMV sys.dm_os_loaded_modules from your program:
SELECT name
FROM sys.dm_os_loaded_modules
WHERE name LIKE '%sqlservr.exe';
This will give you something like this:
C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\Binn\sqlservr.exe
You have some parsing to do, depending on exactly what you're after (e.g. do you want to stop at MSSQL, or Binn?), but this is much easier than reading the registry or other methods that are out there IMHO.
I just used a code converter ... There are only basic things that need to be changed ..
Using sqlServerKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Microsoft SQL Server")
For Each subKeyName As String In sqlServerKey.GetSubKeyNames()
If subKeyName.StartsWith("MSSQL.") Then
Using instanceKey As RegistryKey = sqlServerKey.OpenSubKey(subKeyName)
Dim instanceName As String = instanceKey.GetValue("").ToString()
If instanceName = "MSSQLSERVER" Then
'say
Dim path__1 As String = instanceKey.OpenSubKey("Setup").GetValue("SQLBinRoot").ToString()
path__1 = Path.Combine(path__1, "sqlserver.exe")
Return path__1
End If
End Using
End If
Next
End Using
If you were to just read a quick article on C#, you would notice that strings are declared differently, and minor syntax discrepancies exist such as foreach vs for each
You can read here for some more common differences.
I use a very good (offline) tool, called Convert .NET Free
It's from www.fishcodelib.com
Here's a direct link to the latest release (as of 19/04/14) Size: 2.06MB, File: Zip :
[Direct Link]
Hope this is of some use ;)
P.S. This software requires .NET Framework 4.5.
This almost never fails! :) Good Luck
http://www.developerfusion.com/tools/convert/csharp-to-vb/