• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3087
  • Last Modified:

ActiveX component cant create object: "WScript.Network"

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
DougO
Asked:
DougO
1 Solution
 
gator4lifeCommented:
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
 
arthuryeungCommented:
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
 
bluebucketCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gator4lifeCommented:
"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
 
anderson22Commented:
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
 
DougOAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now