VBSCript support

valsensor

New Member
Messages
2
Hi,

We are using Windows 8 pre version to verify our software support for this OS, and when we run the vbscript file, got the error 'Variable is undefined:Session'
Our script has this line of code
UILevel = Session.Property(CustomActionData)

What is wrong , the same script is executing successfully on all other windows OS

Please help us to solve this issue

thanks
 
Hi,

Here is my script

Option Explicit

Sub DoStartService()

Dim objWMIService, objService, UILevel
Dim colListOfServices, strComputer

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='myService'")
UILevel = Session.Property("CustomActionData")
For Each objService in colListOfServices
err = objService.StartService()
If (err = 0) Then
Else
If ( UILevel <> 2) Then
MsgBox "StartService failed. Error = " & Err.Number
End If
Exit For
End If
Next

End Sub
 
Microsoft changed Applications (install, run, and programmed) in Windows 8.

This is a very old way to check for a started service. You will need to modify the script removing the UILevel = Session.Property("CustomActionData") for testing if the service is started. You can do it like this:

Option Explicit

Dim strComputer,strServiceName
strComputer = "." ' Local Computer
strServiceName = "myService" ' My Service

If isServiceRunning(strComputer,strServiceName) Then
Wscript.Echo "The '" & strServiceName & "' service is running on '" & strcomputer & "'"
Else
Wscript.Echo "The '" & strServiceName & "' service is NOT running on '" & strcomputer & "'"
End If

' Function to check if a service is running on a given computer
Function isServiceRunning(strComputer,strServiceName)
Dim objWMIService, strWMIQuery

strWMIQuery = "Select * from Win32_Service Where Name = '" & strServiceName & "' and state='Running'"

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

If objWMIService.ExecQuery(strWMIQuery).Count > 0 Then
isServiceRunning = true
Else
isServiceRunning = false
End If

End Function
 
I too use a simple legacy VBScript that works under 64-bit Win-7 but crashes under 64-bit Win-8. If anyone can suggest what is different in Win-8, I would be grateful.

The script "create.vbs" ASCOM FITS driver uses a FITS.dll "driver" to capture images under the astronomical ASCOM environment ASCOM - Standards for Astronomy

This driver is registered using "regsvr32 FITS.dll" which creates Windows Registry entries for the ASCOM camera "CCDSimulator.Camera".

The script first creates a camera object:

Set camera = CreateObject("CCDSimulator.Camera")

then an image object:

Set image = CreateObject("FITS.Image")

Under Win-7 it then retrieves the image array from the camera and produces a FITS image with:

image.ImageArrayVariant = camera.ImageArrayVariant

But it CRASHES under Win-8 at that line.
If that line is commented out, a file is produced (without the image data) but including

image.ExposureInterval = exposuretime

The image file is written out with:

image.WriteToFile filename

Usage for 64-bit Windows using an Administrator shell:
C:\windows\syswow64\cscript.exe create.vbs testimage.fit

Short listing for create.vbs script:
---------------------------------------
Sub Main

filename = WScript.Arguments.Item(0)
exposuretime = 2 ' seconds

' Create the CCD simulator object
Set camera = CreateObject("CCDSimulator.Camera")
camera.Connected = True

' Expose with the simulator
WScript.Echo "exposing " & exposuretime & " seconds..."
exposurestarttime = now
camera.StartExposure exposuretime, True
While Not camera.ImageReady
WScript.Sleep 100
Wend

' Create the ASCOM FITS driver object
Set image = CreateObject("FITS.Image")

' Fetch image array (raw pixel data) from the camera and feed it directly to our image object
image.ImageArrayVariant = camera.ImageArrayVariant

' Set some properties for our new FITS file
image.ExposureInterval = exposuretime

' Finally create the new FITS file
image.WriteToFile filename

End Sub
---------------------------------------
 
Back
Top