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

type mismatch and activex object error

Status
Not open for further replies.

kurayami

Technical User
Mar 12, 2008
31
vbscript is save in an external file called "sd.vbs"

Here is my code:

sub shutdown

strComputer = "." ' Local Computer
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOs = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

For Each objOs in colOs
objOs.Win32Shutdown(1)
Next

End Sub

-------------------

<html>
<head>
<script type="text/VBScript" src="sd.vbs"></script>
</head>
<body onload = "vbscript:shutdown">
</body>
</html>

-------------------

What I am trying to do is when the page loads the PC shuts down. The script works when I open the vbs file itself. I am having errors when loading the page.

----------
ActiveX can't create object. 'GetObject
----------

When I edit this part from:

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

to:

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

I get this error:

----------
type mismatch "shutdown"
----------

Anyone has a clue on what's wrong?

"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
-Douglas Adams
 
Some things in VBS cannot be done within a web document because of trust. Web documents are typically executed using iexplorer.exe or mshta.exe processes which don't share the same level of trust as wscript.exe (.vbs compiler) and are subject to the advanced setting in Internet Options.

MS offers a better explanation

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
When I edit this part from:

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

to:

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

I get this error:

----------
type mismatch "shutdown"
----------

The only difference I see is that the first bit of code is (correctly) on two lines. The & _ is a line continuation, meaning that the same line of code continues on the following line.

The second bit of code has a continuation, but is all on one line, which is incorrect. But this would generate an invalid character error, not a type mismatch.
 
You can also do it like this

Code:
strComputer = "."
set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "shutdown -t 0 -f -m \\" & strComputer, 0, true

-t 0 = Zero second countdown (30 secs is default if -t is omitted)
-f = Force the command
-m = machine name

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top