0
votes

Alright, so, I'm working on a script to execute some commands in an MMC Snapin, and I'm not very experienced with doing this kind of scripting, but i've made a lot of progress...the problem I am having, is if I create a new object every time the script runs, it will massively delay my overall script while the snapin and everything in it loads(which can take as long as five minutes). If it could load the snapin content once and then just take control of it as needed, and only create a new object IF there's not one open already, I'll save a massive amount of time when I run the script sometimes 100 times in a day.

The problem is, I'm not entirely certain how to achieve this. I thought, after some research, that it would be GetObject, but when I do

Dim objMMC
Set objMMC = GetObject("", "MMC20.Application")

It seems to create a new mmc window with no snapins loaded, rather than get the existing one with snapins loaded that I want.

Any advice? Am I just totally off base here, using completely the wrong command, or is there some simple change that I can make to fix this?

Edit: Is there some weird workaround way I could achieve this, like storing an object to a temporary file so i can at least reuse it through a single session.

I'm in a weird situation where I am trying to add functionality to a powershell script and couldn't find a way to do it directly in powershell, so i'm setting up a vbscript to do one piece of it and calling the vbscript from powershell. I already had to do a lot of research to figure out how to do it in vbscript(and i'm still not sure about all of it) so i guess before i go any further, I'll try to figure out if this is even viable(in vbscript or c# or c++ or any other language someone could suggest)...

What i want to do, overall, is check if an MMC window is open that contains a DHCP snapin. If so, assign it to a variable. If not, create one. Then it will read from a csv or txt file, and use the values to determine what node to navigate to within the snapin(DHCP>ServerName>IPv4>ScopeName>Scope Options).(I've mostly solved this part in vbscript, but don't know how to do it in C++ or C#) Finally, I need to be able to execute a right-click menu item to "configure options", navigate the tabs of the popup that comes up, enter a value, and apply the changes/hit ok to close the popup. Worst case, If I can't do it "normally" by actually sending commands to the objects themselves, this part I can do with imitating keystrokes, but i don't want to do that if it's avoidable because it's sloppy. Then, I basically will just need to somehow alert the powershell script that i'm "finished" so it can continue, or give an alert if there's an error.

I'm not asking anyone to walk me through all this, I just want to know if any of those steps aren't viable as i've described them, especially if I'm going to have to switch to c++ or c# to achieve the first part and therefore relearn the commands needed.

1

1 Answers

0
votes

... and only create a new object IF there's not one open already ...

No, this is not possible in VBS, you need to do

Dim objMMC
Set objMMC = WScript.CreateObject("MMC20.Application")

if I create a new object every time the script runs, it will massively delay my overall script

In this case is the VBS the wrong language, you need to use C# or C++ executable.