I need to run an Exchange 2007 powershell script in VB.Net, but I can't seem to find a method that shows how to do it with the module loaded.
What is the best method to do this?
You can run powershell scripts in VB, take a look at the following link
http://blogs.msdn.com/b/zainnab/archive/2008/07/26/calling-a-powershell-script-from-your-net-code.aspx
The link posted above takes you step by step on how to accomplish this.
Check out this question that relates to yours:
Running powershell scripts from within a .NET windows app
This following article is in C# but should help you understand the concept a bit better:
http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C
For VB.NET try this code:
Process.Start("powershell", "-File C:\YourFileLocation")
Basically, all you're doing is calling PowerShell and specifying an argument (the location of the cmdlet you're calling).
Related
I'm creating a script editor for my application, and I'd like to have it be able to run both C# and VB.NET scripts using Roslyn. I got this working with C# by using the CSharpScript class in the Microsoft.CodeAnalysis.CSharp.Scripting assembly/namespace, however there is no equivalent VisualBasicScript class that I can find, nor a Microsoft.CodeAnalysis.VisualBasic.Scripting assembly. I've scoured the web and can find nothing useful about running VB.NET scripts, and all the samples on the Roslyn github site are C#-specific. Am I missing something, or does support for running VB.NET scripts simply not exist the way it does for C# scripts?
Visual Basic Scripting is not currently available, presumably because it's not finished.
But its source is is the Roslyn repo, so you could try building it yourself.
When I do that, code like the following works for me:
Dim result = VisualBasicScript.RunAsync("Dim result = 1+1").Result
For Each variable In result.Variables
Console.WriteLine($"{variable.Name}: {variable.Value}")
Next
But this code does not work for me (it fails when compiling the script):
Console.WriteLine(VisualBasicScript.EvaluateAsync("1+1").Result)
I'm not sure whether this is because it's not finished, or whether it's intentional difference from C# scripting.
This is my first post and I hope I am posting in the right section. I would like to know if it is possible to execute a dll file (here, hashtab.dll) as if it's a standalone application. Tried using dependency walker, but I have no idea of interpreting the results and the errors. Only if I can do that, I'll be able to use rundll.exe to execute the function. Any ideas on how to get this done?
Over the past few months I have been struggling to find a way to execute external un-compiled classes from my program.
EXAMPLE:
I have a simple run button on a windows forum. When that run button is pressed I wan't to run the Main sub in run.vb. (Run.vb is not part of the program and is located in a directory)
Is their a way to do this without using .dll's?
You want to run VB.Net code as I see. There are a bunch of classes in System.CodeDom.Compiler namespace to deal with .Net source code.
See http://www.codeproject.com/Articles/5472/Compiling-NET-code-on-the-fly
There is a good example with explanation here.
If you want to run VB6 code, the only way is compiling it to dll and then dynamically load and run. Or you can use VBscript if it will suit you.
In fact, CodeDom compiles your code to dll assembly too, but keeps it in memory, so you don't need to clean up any mess after you app is dead
I'm having troubles registering windows script file. When I'm trying to do so it says "Cannot find the type library for this reference Some.Reference"
Basically, behaviour is very similar to one described in this question Windows Scripting can't find reference but I can't figure out what to use instead of c:\path\to\control.dll.
In my case Some.Reference is Msxml2.FreeThreadedDOMDocument.4.0. so what should I actually do? I tried to use different kinds of msxml.dll, but it didn't seem to help.
Or maybe there are other ways to solve this issue?
One more detail: I managed to register this script on Windows7 but I get described error in Windows Server 2008 sp 2
Hans, thanks for your comment, because what I did is I used this tool
http://www.nirsoft.net/utils/registered_dll_view.html to view registered dlls and I found that the only abailable object I had is Msxml2.FreeThreadedDOMDocument.6.0 so I just changed my script to use this version, and as I can see from your comment it was not the worst decision
Windows XP
The small company I work for just started using this command-line software and it's rather confusing and tedious. I was wondering if it would be feasible to make a GUI frontend and how I would start going about it.
If possible, I would like to have it get data to fill in dropdown boxes and such, but at the very least I'd like to be able to hit a button and perform whatever task. I have never done anything like this before so any help at all would be appreciated.
Thanks
There are two options here:
If the command line exe calls a dll or assemlbly to do the work, then you can work on a front end for the DLL based on the methods that it exposes (ie you can cut out the command line front end completely.
Alternatively you need to wrap the process that the command line runs in and catch its output, and pass it input as appropriate. There's a guide on how to write such a wrapper here: http://support.microsoft.com/kb/305994 (This one is based on writing the wrapper in c#).
One comment though - while it would be possible to do this in VB.Net using the illustrated techniques, doing it in VB6 would be much harder, or even impossible.