C++/VB - what's wrong with this code?

Asked By max
20-Mar-07 11:27 PM
hi all,

i'm writing a simple vbscript to execute another jscript with
following code.

Dim Controller, RemoteScript
Set Controller = WScript.CreateObject("WSHController")
Set RemoteScript = Controller.CreateScript("init2.js")
RemoteScript.Execute

when i run the script, it give me this error

Line: 3
Error: ActiveX component can't create object

the file "init2.js" is on the same path of current script, even though
i add path, it also giving me the same error..

What's wrong with this??

Thanks.
RemoteScript
(1)
WSHController
(1)
CreateObject
(1)
CreateScript
(1)
WScript
(1)
ActiveX
(1)
ADSI
(1)
MVP
(1)
  Richard Mueller [MVP] replied...
21-Mar-07 07:58 AM
You need to make a change in your registry. See this link:

http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_immo.mspx

See section titled "Setup Required to Run Scripts Remotely".

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Create New Account
help
oTargetFile, oFi, sR, iU _ , arr(), arr2, s0, s1, iRowBeg, iRowEnd, sVer, bNewSheet set fso = createObject("scripting.fileSystemObject") set wso = createObject("wScript.shell") sub BeginCScript(bDebug, bMaxWin) if "WSCRIPT" = uCase(fso.getBaseName(wScript.fullName)) then if wScript.arguments.count > 0 then sArg = wScript.arguments(0) ' wso.run "cScript.exe / / nologo" & left(" / / d", -4 * bDebug wScript.scriptFullName & """ """ & sArg & """", 1 -2*bMaxWin, false set fso = nothing: set wso = nothing: wScript.quit: dim
sUserBackupsShareName, sUserBackupsPath Dim sDomainNetBIOS, sTemplate_UserData Dim bInheritanceError Create_Common_Objects Check_Arguments Configuration Create_Physical_Namespace If bDFSNamespaceMode Then Create_DFS_Namespace WScript.Echo sUsernameFolder & " provisioned." Sub Create_Physical_Namespace() ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ' Create physical namespace for %username% folder and the user's it exists. If not, create it. If that fails, quit. If Not FolderPath_Create(sUsernameFolder) Then WScript.Echo "Folder could not be found and could not be created." WScript.Quit End If ' Determine the user name by looking at the last folder in the arr = Execute_Capture(sCommand, 10, True) if arr(0) > 0 then bInheritanceError = True If bInheritanceError Then WScript.Echo "There was an error enabling inheritance using icacls.exe." & VbCrLf & VbCrLf & _ VbCrLf & _ & VbCrLf & _ VbCrLf & VbCrLf & _ enabled" &VbCrLf & _ WScript.Echo End If ' PERMISSIONS AND OWNERSHIP ' We've been creating all of these folders. We _ sUserDFSFolder & " """ & sUserLast & ", " & sUserFirst & """" arr = Execute_Capture( sCommand, 10, True) End Sub Sub Create_Common_Objects() Set FSO = CreateObject("Scripting.FileSystemObject") Set WSHShell = CreateObject("Wscript.Shell") End Sub Sub Check_Arguments() Dim sDFS On Error Resume Next If Right(" " & WScript.Arguments
winmgmts: \ . \ root \ cimv2") set obcls = obj.execquery("select * from win32_volume") for each so in obcls wscript.echo so.capacity next - -- -- -- -- -- -- -- -- -- - But I found that is method called "get". Then i figured following code: - -- -- -- -- -- -- -- -- -- - set obj = getobject("winmgmts: \ . \ root \ cimv2") set obcls = obj.get("win32_volume") wscript.echo obcls.capacity - -- -- -- -- -- -- -- -- -- - But in this case appears popup with "null" How to retrieve properties winmgmts: \ . \ root \ cimv2") | set obcls = obj.execquery("select * from win32_volume") | | for each so in obcls | wscript.echo so.capacity | next | - -- -- -- -- -- -- -- -- -- - | | But I found that is method called "get". | Then i figured following code: | | - -- -- -- -- -- -- -- -- -- - | set obj = getobject("winmgmts: \ . \ root \ cimv2") | set obcls = obj.get("win32_volume") | | wscript.echo obcls.capacity | - -- -- -- -- -- -- -- -- -- - | | But in this case appears popup with "null" | | How to retrieve properties Set objWMIService = GetObject("winmgmts: \ " & strComputer & Set colItems = objWMIService.ExecQuery( _ For Each objItem in colItems Wscript.Echo "- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" Wscript.Echo "Win32_OperatingSystem instance" Wscript.Echo "- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" Wscript.Echo "BootDevice: " & objItem.BootDevice Wscript.Echo "BuildNumber: " & objItem.BuildNumber Wscript.Echo "BuildType: " & objItem.BuildType Wscript
script that is run and called by script 1. below is script 1; - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Dim Controller, RemoteScript, strcomputer, text1, wshshell, oexec 'Variables Set Controller = WScript.CreateObject("WSHController") text1 = "You did not enter a computer name!" Set WshShell = CreateObject("WScript.Shell") strscriptloc = "C: \ scripts \ cmdexec.vbs" 'Ask the user which computer that they would like If the user didn't enter anything, then close the app gracefully If strcomputer = "" Then WScript.Echo Text1 wscript.quit end if 'check connectivity to the computer before running execution xp / 2003 only wmiQuery
is the script. Thank You Const HKEY_LOCAL_MACHINE = &H80000002 Const ForReading = 1 Dim shell Set shell = CreateObject("WScript.shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("c: \ scripts \ EPO.txt", ForReading) Do Until objTextFile.AtEndOfStream FrameworkService.exe") Verison = objFSO.GetFileVersion (Path) Current = "3.6.0.546" If version = Current Then WScript.Echo " Version are equal" Else WScript.Echo " Version are not equal" set objWMIService = getobject("winmgmts: / / "_ & strComputer & " / root / cimv2") objFSO.CopyFolder "C: \ EPO_Agent_McAfee_85i \ 2007 \ EPO_3.60_Patch1", " \ " & strComputer & " \ c$ \ temp \ " WScript.Echo "Copy Done, running batch file for updating EPO" Net use shell.Run "c: \ temp EPO_3.60_Patch1 \ install.bat" End If WScript.Echo strComputer & ":" & " EPO File Version is " & objFSO.GetFileVersion (Path) Loop objTextFile.Close VBScript Discussions Scripting.FileSystemObject (1) ObjTextFile.AtEndOfStream (1) WScript.CreateObject (1) ObjFSO.OpenTextFile (1) Controller.CreateScript (1) ObjWMIService.Create (1) RemoteScript.Execute (1) RemoteScript