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

ASP and WMI 2

Status
Not open for further replies.

Niavlys

IS-IT--Management
Jun 3, 2002
197
CA
Hi, I'm trying to do this on an ASP page :


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


Just want to create shares on a server. It works well in vbscript but when I try to implement it in ASP I get error '80041003'.

But I red that on msdn.microsoft.com ...

"It is not possible to use the GetObject function provided by VBScript and JScript when running scripts embedded within an HTML page, as Microsoft® Internet Explorer disallows the use of this call for security reasons."


Is there any walkthrough?

Any Ideas?
Thanks!
 
Niavlys,

Try this code

'
'********************

' *** This script will execute a WBEM (WMI) compliant command on a target computer from a local computer
'*** This Script requires WBEM (WMI) loaded on the local and remote computers
' *** If UserName and Password are left blank, the program will use the context of the machine executing the command
' *** For example, if you want to execute a command on the remote computer as somebody other than yourself
' *** Enter the username and password
' *** By Scott Souther ScottSouther@hotmail.com
'********************

Dim Locator, Server, UserName, Password, Command, service, instance

'********************

' *** Here we need the Server to connect to, the command to run, and the context which to connect to the server
' *** The Username can be from the remote computer, a domain or a master domain
' *** If UserName and Password are left blank, the program will use the context of the machine executing the command
' *** For example, if you want to execute a command on the remote computer as somebody other than yourself
' *** Enter the username and password
'********************

Server = "Here you enter the remote computer name"
Command = "Here you enter the command you want to run"
UserName = "Optional"
Password = "Optional"

'********************
' *** This next section establishes a WBEM (WMI) session to the remote computer
'********************

Set Locator = CreateObject("WbemScripting.SWbemLocator")
Set Service = Locator.ConnectServer (Server, NameSpace, UserName, Password)

'********************
' *** This next section runs the command on the remote computer
'********************

Service.Security_.impersonationlevel = 3
Set Instance = Service.Get("Win32_Process")
intStatus = Instance.Create(Command, null, null, intProcessId)


fengshui_1998
 
The account that asp pages run under is the IUSR_COMPUTERNAME, this user might not (should not) have the right to create shares.
So you need to run that asp page under the power user or another account that has to right to do the things you want (admin??)
To do so you need to open the IIS console (mmc) and browse to the file that runs your wmi script => right click this file => properties => file securety => enable anonymous ... there is a button Edit => only check alow anonymous (or when it's an Intranet application and you want admins to run this asp then check Integrated Windows authentication but this only works when you use IE and some proxy does not remove the HTTP headers that identify you) => if you have only checked anonymous then click edit and here you can set the account that the page will be run under.
 
Thanks guys, it works great now, I removed the anonymus access to the web page so it forces the user to login and then I can set the privileges in Active Directory. I just did it with:

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & HomeServer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create(SharePath & Uname, Uname, 0, 25, "Private share for" & " " & Uname)

[smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top