Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
680 views
in Technique[技术] by (71.8m points)

web applications - Using a variable from a VBScript in a ASP.Net website

I've been researching this for a majority of the day and can't find the answer. I am relatively new to stackoverflow. Is there a certain etiquette for asking a number of questions (I've asked three in the last few days)?

Anyways,

Here is the code in a codebehind file. It executes a script systeminfo.vbs, and that is working fine. But in the script I have some variables assigned.

Dim WshShell = CreateObject("WScript.Shell")
        WshShell.Run("wscript.exe c:systeminfo.vbs")

vbscript

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!" & strComputer & "
ootcimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings 
dim osName 
osName = objOperatingSystem.Name
Wscript.Echo "OS Name: " & objOperatingSystem.Name
dim osVer
osVer = objOperatingSystem.Version
Wscript.Echo "Version: " & objOperatingSystem.Version
Wscript.Echo "Service Pack: " & _
    objOperatingSystem.ServicePackMajorVersion _
        & "." & objOperatingSystem.ServicePackMinorVersion
Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next

I want to use osName and osVer and put the values into a label on the ASP side. I understand that osName and osVer are simple examples, but I just need to figure out the concept of putting variables from a VBScript into ASP. My client has multiple VBScripts they use on a daily basis and I need to automate those scripts and produce a report saying if it failed or not.

Thank you for the help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

David,

As a person new to Stack Overflow myself, I was happy to find this very comprehensive FAQ for Stack Exchange sites. See the 3rd question "Is there a limit on how many questions I can ask?" for an answer to your first inquiry.

Regarding the heart of your question, I agree with @Ramhound that using a log file to exchange information between your WSH/VBScript script and your ASP.NET page is a feasible approach.

What you need is the Scripting.FileSystemObject. Here is a comprehensive WSH reference as a downloadable Windows help file.

Hint: as the download page advises at the bottom, to unblock the help page, 1) Right click on script56.chm, 2) Choose Properties, and 3) Click on "Unblock."

You'll find an intro to FileSystemObject under the heading "Script Runtime."

One more suggestion: since you'll be running this script via ASP.NET in a multi-user environment, you may find you'll need to create a log file per user or per page access. If that is the case, you'll need to generate a temporary file name for each log file to avoid name collisions with other log files. To generate your temporary file, see GetTempName in the WSH reference.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...