CodeDom Black Box - vb.net

VB.Net Code. I want to hide the black box that opens up with a compiled code... how?
It opens a cmd shell whenever I compile it...
Public Shared Function CompileVBCode(sourceFile As String, exeFile As String) As Boolean
Dim vbprovider As VBCodeProvider = New VBCodeProvider()
Dim cp As New CompilerParameters()
cp.ReferencedAssemblies.Add("System.dll")
cp.GenerateInMemory = False
cp.GenerateExecutable = True
cp.OutputAssembly = exeFile
Dim cr As CompilerResults = vbprovider.CompileAssemblyFromSource(cp, sourceFile)

cp.CompilerOptions += "/t:winexe"

Related

Invoke EntryPoint of assembly without showing any window - VB.Net

I need to execute an application embeeded in my resources . Heres my code :
Dim MainAssembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
Dim resourceStream As Stream = MainAssembly.GetManifestResourceStream("MyApp.Nircmd.exe")
If resourceStream Is Nothing Then
Throw New NullReferenceException("error")
End If
Dim toolAssemblyBuffer(CInt(resourceStream.Length) - 1) As Byte
resourceStream.Read(toolAssemblyBuffer, 0, toolAssemblyBuffer.Length)
resourceStream.Close()
AudioTool = Reflection.Assembly.Load(toolAssemblyBuffer)
Dim args() As String = {Application.StartupPath, "argumentsHere"}
Dim parameters = New Object() {args}
Try
AudioTool.EntryPoint.Invoke(Nothing, parameters)
Catch
End Try
This application opens a new cmd.exe window everytime , so , i need to invoke the EntryPoint without showing any window .
Is there a WindowStyle property or something equal in an assembly ?
Thanks

Roslyn VB.Net Specify Compiler Version

I am trying to compile a VB program using the code below, the code requires VB 15.5 and even when I specify LanguageVersion.Latest or LanguageVersion.VisualBasic15_5, I still get error ERR_ExpectedNamedArgument - Named argument expected. Please use language version 15.5 or greater to use non-trailing named arguments. Some code was removed to simplify example.
Public Function CompileVisualBasicString(StringToBeCompiler As String, SeverityToReport As DiagnosticSeverity, ByRef ResultOfConversion As ConversionResult) As EmitResult
If StringToBeCompiler.IsEmptyNullOrWhitespace Then
ResultOfConversion.FilteredListOfFailures = New List(Of Diagnostic)
ResultOfConversion.Success = True
Return Nothing
End If
Dim syntaxTree As SyntaxTree = VisualBasicSyntaxTree.ParseText(StringToBeCompiler)
Dim assemblyName As String = Path.GetRandomFileName()
Dim PreprocessorSymbols As New Dictionary(Of String, Object) From {
{"NETSTANDARD2_0", Nothing}
}
Dim ParseOptions As VisualBasicParseOptions = New VisualBasicParseOptions(
languageVersion:=LanguageVersion.Latest,
documentationMode:=DocumentationMode.Diagnose,
kind:=SourceCodeKind.Regular,
preprocessorSymbols:=PreprocessorSymbols)
Dim CompilationOptions As VisualBasicCompilationOptions = New VisualBasicCompilationOptions(
outputKind:=OutputKind.DynamicallyLinkedLibrary,
optionExplicit:=False,
optionInfer:=True,
optionStrict:=OptionStrict.Off,
parseOptions:=ParseOptions
)
Dim compilation As VisualBasicCompilation = VisualBasicCompilation.Create(
assemblyName:=assemblyName,
syntaxTrees:={syntaxTree},
references:=References,
options:=CompilationOptions
)
Dim CompileResult As EmitResult
Using ms As MemoryStream = New MemoryStream()
CompileResult = compilation.Emit(ms)
End Using
Return CompileResult
End Function
Thank you George, you solved the problem I needed to include the VisualBasicParseOption to Parse in addition to compile.

LiveCharts not showing in vb.net

I have tried to implement LiveCharts in vb.net project but unsuccessful. Tried searching the internet but unfurtunately found no sample code. What might be the problem in my code?sample code
Private Sub InitializeChart()
Dim labelPoint As Func(Of ChartPoint, String) = Function(chartPoint) String.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Y, chartPoint.Participation)
'pieChartMain = New LiveCharts.WinForms.PieChart
Dim seriesCollection As SeriesCollection = New SeriesCollection
Dim pieSeries1 As PieSeries = New PieSeries
Dim pieSeries2 As PieSeries = New PieSeries
pieSeries1.Title = "MALE"
pieSeries1.Values = New ChartValues(Of Double) From {3}
pieSeries1.PushOut = 15
pieSeries1.DataLabels = True
pieSeries1.LabelPoint = labelPoint
pieSeries2.Title = "FEMALE"
pieSeries2.Values = New ChartValues(Of Double) From {6}
pieSeries2.DataLabels = True
pieSeries2.LabelPoint = labelPoint
seriesCollection.Add(pieSeries1)
seriesCollection.Add(pieSeries2)
pieChartMain.Series.Add(seriesCollection)
pieChartMain.LegendLocation = LegendLocation.Bottom
pieChartMain.Show()
End Sub
I think the sample needs more information to someone try a help...
What is the PIE control name?
Are you IMPORTING the libraries?
Imports LiveCharts.WinForms
Imports LiveCharts.Wpf
Imports LiveCharts
After the last PieChart command, try to force the redraw. For instance, in a Gauge control, I get success if utilize:
Gauge.resumelayout
So, try to REFRESH and also RESUMELAYOUT over the control

VB.NET Return Form Object using Form Name

I'm basically writing a custom Error Logging Form for one of my applications because users cannot be trusted to report the errors to me.
I am obtaining the Form Name using the 'MethodBase' Object and then getting the DeclaringType Name.
Dim st As StackTrace = New StackTrace()
Dim sf As StackFrame = st.GetFrame(1)
Dim mb As MethodBase = sf.GetMethod()
Dim dt As String = mb.DeclaringType.Name
How can I then use this to obtain the Form Object so I can pass this to my 'screenshot method' that screenshots the particular form referenced.
Public Sub SaveAsImage(frm As Form)
'Dim fileName As String = "sth.png"
'define fileName
Dim format As ImageFormat = ImageFormat.Png
Dim image = New Bitmap(frm.Width, frm.Height)
Using g As Graphics = Graphics.FromImage(image)
g.CopyFromScreen(frm.Location, New Point(0, 0), frm.Size)
End Using
image.Save(_LogPath & Date.Now.ToString("ddMMyyyy") & ".png", format)
End Sub
I posted the same solution to a similar question. Try this:
Dim frm = Application.OpenForms.Item(dt)

query an exchange distribution list

I'm trying to find some code that I can use in vb.net 4.0 to query the our exchange 2013 server. It will be housed on a web server and that server does not have outlook installed on it. Looks like I need to use EWS to do this but I've tried a lot of code snippets and still have not been able to figure this out. The distribution list i'm trying to query is in the public folders/Office Contacts. I've tried examples that use nesting to go through the public folder seen there is no deep traversal but I'm not doing something right there. I am not posting code because i'm not sure it would help. I was hoping someone has already done this and would give me some nuggest of info to get me started.
The examples I've found do not query the distribution list but rather add to it. It's not that I haven't tried... I've got hundreds of lines of code from different places that I've tried and tried to learn from.. but i'm not getting it done. Anyway.. help would be great.
Sorry about not posting any code.. I actually thought I deleted this post.. but i'll post the code that is now working for me. This code does a query to the public folder and then grabs some of the data about each contact in that contact list.
Public Sub MS()
Dim oTheListS As New List(Of TheList)
Dim service As New ExchangeService(ExchangeVersion.Exchange2010_SP1)
service.Credentials = New WebCredentials("userid", "password")
service.AutodiscoverUrl("email#address")
'Get Public Folder
Dim sf As SearchFilter = New SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Office Contacts")
Dim rrRes As FindFoldersResults = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, sf, New FolderView(1))
Dim OfficeContacts As Folder = rrRes.Folders(0)
'Find the Distribution List
Dim dlSearch As SearchFilter = New SearchFilter.IsEqualTo(ContactGroupSchema.DisplayName, "Merit Board")
Dim ivItemView As New ItemView(1)
Dim fiResults As FindItemsResults(Of Item) = OfficeContacts.FindItems(dlSearch, ivItemView)
If fiResults.Items.Count = 1 Then
'Enumeate Members
Dim cg As ContactGroup = DirectCast(fiResults.Items(0), ContactGroup)
cg.Load()
For Each gm As GroupMember In cg.Members
Dim o As New TheList
o = MS2(gm.AddressInformation.Address)
oTheListS.Add(o)
'Dim o As New TheList
'Dim ncCol As NameResolutionCollection = service.ResolveName(gm.AddressInformation.Address, ResolveNameSearchLocation.ContactsOnly, True)
'With o
' .Name = gm.AddressInformation.Name
' .Email = gm.AddressInformation.Address
'End With
'oTheListS.Add(o)
Next
End If
End Sub
Public Function MS2(pEmail As String) As TheList
Dim o As New TheList
Dim service As New ExchangeService(ExchangeVersion.Exchange2010_SP1)
service.Credentials = New WebCredentials("userid", "password")
service.AutodiscoverUrl("email#address")
Dim sf As SearchFilter = New SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Office Contacts")
Dim rrRes As FindFoldersResults = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, sf, New FolderView(1))
Dim OfficeContacts As Folder = rrRes.Folders(0)
'Find the Distribution List
Dim dlSearch As SearchFilter = New SearchFilter.IsEqualTo(ContactSchema.EmailAddress1, pEmail)
Dim ivItemView As New ItemView(1)
Dim fiResults As FindItemsResults(Of Item) = OfficeContacts.FindItems(dlSearch, ivItemView)
If fiResults.Items.Count = 1 Then
Dim con As Contact = fiResults.Items(0)
'Dim ncCol As NameResolutionCollection = service.ResolveName(gm.AddressInformation.Address, ResolveNameSearchLocation.ContactsOnly, True)
With o
If con.DisplayName IsNot Nothing Then
.Name = con.DisplayName
End If
Dim em As New EmailAddress
If con.EmailAddresses.TryGetValue(EmailAddressKey.EmailAddress1, em) = True Then
.Email = con.EmailAddresses(EmailAddressKey.EmailAddress1).ToString
End If
If con.JobTitle IsNot Nothing Then
.Title = con.JobTitle
End If
Dim phy As New PhysicalAddressEntry
If con.PhysicalAddresses.TryGetValue(PhysicalAddressKey.Business, phy) = True Then
.Address = con.PhysicalAddresses(PhysicalAddressKey.Business)
End If
If con.PhoneNumbers.TryGetValue(PhoneNumberKey.BusinessPhone, String.Empty) = True Then
.PhoneBusiness = con.PhoneNumbers(PhoneNumberKey.BusinessPhone)
End If
If con.PhoneNumbers.TryGetValue(PhoneNumberKey.MobilePhone, String.Empty) = True Then
.PhoneMobile = con.PhoneNumbers(PhoneNumberKey.MobilePhone)
End If
If con.CompanyName IsNot Nothing Then
.Comapny = con.CompanyName
End If
End With
End If
Return o
End Function
Public Class TheList
Public Property Name As String
Public Property Email As String
Public Property PhoneMobile As String
Public Property PhoneBusiness As String
Public Property Comapny As String
Public Property Title As String
Public Property Address As PhysicalAddressEntry
End Class
I just got it working so I haven't started to refine it yet.. but hopefully this will help someone else as I didn't find any code that did this