?
Solved

ActiveX component cant create object: "WScript.Network"

Posted on 2003-03-16
6
Medium Priority
?
2,966 Views
Last Modified: 2007-12-19
I'm getting a runtime error when running the following in an asp page - yet it works fine in a .vbs script when executed from the command line:
<Script Language="VBScript">
     Dim objNet
     Dim strInfo
        Set objNet = CreateObject("WScript.NetWork")
     strInfo = "User Name is     " & objNet.UserName & vbCRLF & _
               "Computer Name is " & objNet.ComputerName & vbCRLF & _
                "Domain Name is   " & objNet.UserDomain
     MsgBox strInfo
     
     Set objNet = Nothing                        
</Script>

The error returned is ActiveX cant create object "WScript.Network".  This is on a W2K SP3 server running IIS5.  I have searched for answers and have checked for/verified the following:

execute permissions to the page
ntfs permissions on the page
presence of wsh - script works as a standalone vbs

Any help appreciated.

0
Comment
Question by:DougO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

by:gator4life
ID: 8150248
Try running it like this in an ASP page:

<%
     Dim objNet
     Set objNet = Server.CreateObject("WScript.NetWork")

     Dim strInfo
     strInfo = "User Name is     " & objNet.UserName & vbCRLF & _
               "Computer Name is " & objNet.ComputerName & vbCRLF & _
               "Domain Name is   " & objNet.UserDomain

     MsgBox strInfo
   
     Set objNet = Nothing
%>

I always use the Server object within an ASP page to be able to access its CreateObject method.

However, if that isn't the case, then this error usually means that the dll that creates the instance of the class needed is not present on the machine.  Do you have the latest Windows Script installed?  It doesn't make sense that this will work in a normal .vbs file though...

I also found this as a possible solution:

"This occurs when the World Wide Web service is stopped and restarted.  Go to Control Panel, and then double-click Services.  Click IIS Administrative Service, and then click Stop.  When a dialog box appears confirming that you want to stop other child services, click OK.  After the services stop, start the IIS Administrative service.  After the IIS Administrative service starts, click World Wide Web Publishing Service, and then click Start."

I hope one of these ideas may lend you a hand.  Or, when in doubt, just reboot the server! ;-)  Let me know how things go...

gator4life
(chomp, chomp)
0
 
LVL 4

Expert Comment

by:arthuryeung
ID: 8150532
gator4life:
I think you got the wrong meaning, he seems to be trying to run the script in client side. You suggestion is to run it in server side. Btw, how can you do a "MsgBox" in ASP ?

DougO:
Please make sure that you want to run the above in client side or server side. From your case, you want to display the computer name of the client computer or the server computer ?

If you are trying to run it in client side, i.e. displaying the computer name of the client computer to the user, your problem is not with ASP, but with permission to run ActiveX of the client browser. The browser have some default security constrain to disallow dangerous ActiveX component (like Scripting.Network) to run in client side.

You can run in a .vbs form because there is no such restriction in your command prompt.

Follow this instruction to allow the running of it in a certain browser:
In IE, Tools -> Internet Options -> Security -> Trusted Site -> Sites, add your URL in the Trusted Sites list

The following code should work after the above settings:
<Script Language="VBScript">
    Dim objNet
    Dim strInfo
       Set objNet = CreateObject("WScript.NetWork")
    strInfo = "User Name is     " & objNet.UserName & vbCRLF & _
              "Computer Name is " & objNet.ComputerName & vbCRLF & _
               "Domain Name is   " & objNet.UserDomain
    document.write strInfo
   
    Set objNet = Nothing                        
</Script>

If you are trying to run in server-side, i.e. you want to display the computer name of the Server Computer to the user, the following ASP code should work:

<%
    Dim objNet
    Set objNet = Server.CreateObject("WScript.NetWork")

    Dim strInfo
    strInfo = "User Name is     " & objNet.UserName & vbCRLF & _
              "Computer Name is " & objNet.ComputerName & vbCRLF & _
              "Domain Name is   " & objNet.UserDomain

    response.write strInfo
   
    Set objNet = Nothing
%>
0
 

Accepted Solution

by:
bluebucket earned 200 total points
ID: 8150577
Hi,

This is a security related issue. The script is not permitted to create the object on the client machine. You can test this by manually adding the IIS server (or http://localhost if this is what you are using) in the Internet Explorer "Tools | Internet Options | Security | Trusted Sites" list. IE will now ask you if it should grant permission to the script and if you answer yes your script will show the information.

Gator4life's solution is server-side but I suspect this is not the solution you were looking for?
0
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
LVL 5

Expert Comment

by:gator4life
ID: 8151807
"Btw, how can you do a "MsgBox" in ASP ?"

My bad...I wasn't really focusing on that part of the code.  Thanks for catching that.

gator4life
(chomp, chomp)
0
 
LVL 4

Expert Comment

by:anderson22
ID: 8154164
WScript cannot be instantiated by the IUSER.  You have to have machine access permissions (not anonymous).  When you run .vbs files, you are running them as the logged in, authenticatd user.  Change the directory security on the IIS directory (remove anonymous) and try again.  You might still have problems because I don't know that WScript can be instantiated under the IIS Process (no matter the permissions).

-rca
0
 

Author Comment

by:DougO
ID: 8155214
Thank you all for your suggestions.    My browser was blocking unsigned ActiveX objects - changing the default settings to prompt before instantiating fixed the problem.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question