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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script doesn't work on 2003 box

Status
Not open for further replies.

JBorecky

IS-IT--Management
Mar 16, 2002
55
US
Ok guys,

I've been away for a while but this one has me stumped.

This code works fine on a XP box but I get Access Denied on a 2k3 box. I'm an Admin on both, can anyone tell me why?

strComputer = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = strName
objNewPort.Protocol = intProtocol
objNewPort.HostAddress = strHostAddress
objNewPort.PortNumber = intPort
objNewPort.SNMPEnabled = bolSNMP
objNewPort.SNMPCommunity = strSNMPCommunity
objnewPort.SNMPDevIndex = SNMPIndex
objNewPort.Put_

MCSE 2003: Security
MCDBA
 
Check the WMI permissions. Even though you are an admin, that does not mean you have WMI permissiosn.

Right click My Computer, Choose Manage
Under Services and Applications, Right click WMI Control
Choose Properties
Click the Security Tab
Check the permissions to the CIMV2 database.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hmmmm interesting.

I didn't know that was there, but unfortunatly that wasn't it. Admins have full control in every namespace. Thanks though.

MCSE 2003: Security
MCDBA
 
OK Here we go for those of you who are in suspense. I guess you need to declare the priviledges you need when you make your connection like below.

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate ,(LoadDriver)}!\\" & _ strComputer & "\root\cimv2")

OR

objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True


This code works for those of you who like R&D (Rob and Duplicate)

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate ," _
& "(LoadDriver)}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = strName
objNewPort.Protocol = intProtocol
objNewPort.HostAddress = strHostAddress
objNewPort.PortNumber = intPort
objNewPort.SNMPEnabled = bolSNMP
objNewPort.SNMPCommunity = strSNMPCommunity
objnewPort.SNMPDevIndex = SNMPIndex
objNewPort.Put_



MCSE 2003: Security
MCDBA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top