Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting the MMC console problem

Status
Not open for further replies.

roontoon

MIS
Sep 25, 2010
15
0
0
US
I would like to add a snap in via vbscript and I have been having a problem getting the snap in to add to the console. It will be run in a Windows 7 environment. If someone could have a look see and direct me in the right direction I would be most grateful. Thanks.

Code:
'Elevated privileges start
'Start of UAC workaround code
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If WScript.Arguments.length =0 Then
	Set objShell = CreateObject("Shell.Application")
	objShell.ShellExecute "wscript.exe", Chr(34) & _
	WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else


consoleName = "C:\Burnett.msc"

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(consoleName) Then
	Wscript.Echo "console already exists"
Else
	On Error Resume Next
	Set objMMC = CreateObject("MMC20.Application")
	If err.Number <> 0 Then
		Wscript.Echo "an error occurred. unable to create mmc console"
		Wscript.Quit(0)
	End If

	objMMC.Show
	Set objDoc = objMMC.Document
	objDoc.snapins.add("Local Computer\Non-Administrators")
	if err then
	'Trap the error just after the statement where an error/exception can occur and handle it elegantly
		msgbox("Snap-in Not found")  
		err.clear
	end if
	objDoc.ActiveView.StatusBarText = "Pane 1|Pane 2|Pane 3"
	objMMC.UserControl = 1
	objDoc.Name = consoleName
	objDoc.Save()
End If

Set fso = Nothing


End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top