Convert VBS to ASP or JavaScript

Posted on 2006-06-07
Medium Priority
Last Modified: 2008-02-01
i was giving a .vbs file and i need to run it using either ASP, ASP.NET or Javascript but i cant code in ASP or ASP.NET and dont know what to change for it to work in Javascript.

Can somebody provide a helping hand please to convert it?


Option Explicit

Dim StrComputer
strComputer = ""

strComputer = Trim(strComputer)
If strComputer = "" Then strComputer = "."

Dim sCompName : sCompName = GetProbedID(StrComputer)

Dim sFileName
sFileName = strComputer & "_software_list.txt"

Dim s : s = GetAddRemove(strComputer)

If WriteFile(s, sFileName) Then
'optional prompt for display
'If MsgBox("Finished processing.  Results saved to " & sFileName & _
'vbcrlf & vbcrlf & "Do you want to view the results now?", _
'4 + 32, sTitle) = 6 Then
'WScript.CreateObject("WScript.Shell").Run sFileName, 9
'End If
End If

Function GetAddRemove(sComp)
  'Function credit to Torgeir Bakken
  Dim cnt, oReg, sBaseKey, iRC, aSubKeys
  Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
  Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
              sComp & "/root/default:StdRegProv")
  sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
  iRC = oReg.EnumKey(HKLM, sBaseKey, aSubKeys)

  Dim sKey, sValue, sTmp, sVersion, sDateValue, sYr, sMth, sDay

  For Each sKey In aSubKeys
    iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, "DisplayName", sValue)
    If iRC <> 0 Then
      oReg.GetStringValue HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
    End If
    If sValue <> "" Then
      iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, _
                                "DisplayVersion", sVersion)
      If sVersion <> "" Then
        sValue = sValue & " Ver: " & sVersion
        sValue = sValue & vbTab
      End If
      iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, _
                                "InstallDate", sDateValue)
      If sDateValue <> "" Then
        sYr =  Left(sDateValue, 4)
        sMth = Mid(sDateValue, 5, 2)
        sDay = Right(sDateValue, 2)
        'some Registry entries have improper date format
        On Error Resume Next
        sDateValue = DateSerial(sYr, sMth, sDay)
        On Error GoTo 0
        If sdateValue <> "" Then
          sValue = sValue '& vbTab & "Installed: " & sDateValue
        End If
      End If
      sTmp = sTmp & sValue & vbcrlf
    cnt = cnt + 1
    End If
  sTmp = BubbleSort(sTmp)
  GetAddRemove = sTmp
End Function

Function BubbleSort(sTmp)
  'cheapo bubble sort
  Dim aTmp, i, j, temp
  aTmp = Split(sTmp, vbcrlf)  
  For i = UBound(aTmp) - 1 To 0 Step -1
    For j = 0 to i - 1
      If LCase(aTmp(j)) > LCase(aTmp(j+1)) Then
        temp = aTmp(j + 1)
        aTmp(j + 1) = aTmp(j)
        aTmp(j) = temp
      End if
  BubbleSort = Join(aTmp, vbcrlf)
End Function

Function GetProbedID(sComp)
  Dim objWMIService, colItems, objItem
  Set objWMIService = GetObject("winmgmts:\\" & sComp & "\root\cimv2")
  Set colItems = objWMIService.ExecQuery("Select SystemName from " & _
  For Each objItem in colItems
    GetProbedID = objItem.SystemName
End Function

Function GetDTFileName()
  dim sNow, sMth, sDay, sYr, sHr, sMin, sSec
  sNow = Now
  sMth = Right("0" & Month(sNow), 2)
  sDay = Right("0" & Day(sNow), 2)
  sYr = Right("00" & Year(sNow), 4)
  sHr = Right("0" & Hour(sNow), 2)
  sMin = Right("0" & Minute(sNow), 2)
  sSec = Right("0" & Second(sNow), 2)
  GetDTFileName = sMth & sDay & sYr & "_" & sHr & sMin & sSec
End Function

Function WriteFile(sData, sFileName)
  Dim fso, OutFile, bWrite
  bWrite = True
  Set fso = CreateObject("Scripting.FileSystemObject")
  On Error Resume Next
  Set OutFile = fso.OpenTextFile(sFileName, 2, True)
  'Possibly need a prompt to close the file and one recursion attempt.
  If Err = 70 Then
    Wscript.Echo "Could not write to file " & sFileName & ", results " & _
                 "not saved." & vbcrlf & vbcrlf & "This is probably " & _
                 "because the file is already open."
    bWrite = False
  ElseIf Err Then
    WScript.Echo err & vbcrlf & err.description
    bWrite = False
  End If
  On Error GoTo 0
  If bWrite Then
  End If
  Set fso = Nothing
  Set OutFile = Nothing
  WriteFile = bWrite
End Function
Question by:ellandrd
  • 3
  • 2
  • 2
  • +1
LVL 19

Expert Comment

ID: 16853611
What exactly is this script supposed to do?  Much of this would work unaltered in ASP, however some of the functions may have problems.

The WriteFile Function - Are you trying to write to the Web Server or to the client computer?  In ASP, the file system object will be writing to the Server, but I'm not sure if this is what you intend.

Your references to wscript will need to be looked at.  You can create a wscript object in ASP, but it needs to be done similar to the way you are creating the FileSystemObject in the WriteFile function.

In the GetProbedID function, you are using getObject.  I've not tried using that in ASP and am not sure if it is valid.

The biggest thing to think about though is that ASP is Server Side Code.  I have a feeling that the original script is designed to be run on a client computer (although I'm not sure of that).  All of the functions that run will run on the server, not the client.  

I hope I've at least given you some thoughts on where to start.

LVL 16

Author Comment

ID: 16853655
the vbs code was giving to my boss by another developer.  it lists all the installed software and its version on a machine by passing an IP address.

so for exmaple, file.vbs exists on our intranet server and i run file.vbs passing it my client IP address(internal as its on an intranet).

 well it will list all the software ive installed with the version.  but i cannot run this .vbs file so i need convert it to javascript or ASP so i can run it... but i can code in either
LVL 19

Accepted Solution

nschafer earned 1500 total points
ID: 16853794
OK, so the vbs file creates a report of all the software installed on the machine that calls it?  

Here's where there is a problem.  As I mentioned above ASP is server side code.  It has no ability to gather information from a client computer, only from the server.  So ASP will not work for what you are trying to do.  

Javascript is generally used for client-side code, so the possibility exits that you may be able to this with Javascript, but I wouldn't hold out a lot of hope as I don't think that any browser is going to allow a call to the registry from a Javascript in a webpage.  (I could be wrong here there might be a way, but if so I don't know of it)

I don't use ASP.Net, I keep thinking I should start heading that direction, but it's too easy to fall back on what you already know.  In any case I think you will find the same problem with ASP, that you are looking at Server Side code, not client side.

Sorry I can't be of more help.


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 15

Expert Comment

ID: 16854242
Nothing jumps out at me that won't work in ASP other than "WScript.Echo" should be changed to "response.write".  
If it doesn't work in ASP it's probably a permissions issue.
LVL 16

Author Comment

ID: 16859189
>>OK, so the vbs file creates a report of all the software installed on the machine that calls it?



Can you help then?  i have no idea where to start?
LVL 14

Expert Comment

ID: 16864009
ellandrd your best bet would be to look into writing an ActiveX component. These components can be downloaded through browsers but don't have the security restrictions that ASP/JavaScript do. ASP.Net might have a way of doing this but most likely it uses a library component itself so you're better off just writing your own. Do you have Visual Basic 6.0?
LVL 15

Expert Comment

ID: 16867072
Start by changing "WScript.Echo" to "response.write" and let us know what error you get.    Changing IIS to run under your id would help troubleshoot a permssions problem assuming you can run the vbs file under your ID.
LVL 16

Author Comment

ID: 16868073
i dont have vb6...


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question