VBScript works in 32bit Windows XP, fails in 64bit Windows 7

Posted on 2011-03-17
Medium Priority
Last Modified: 2012-06-27
Hello all,

I'm having a little problem with one of my scripts that I'm going out on a limb and blaming either Windows 7 or the use of a 64bit OS.

Basically the story is I work in a Windows 2003 Server domain with primarily 32bit Windows XP clients. I have a script that runs on user logon that gathers details about the user/computer (username, IP address, etc) and records them in a database on the server.

Now this has all been working fine but recently we introduced 20+ Windows 7 x64 machines to the domain and now (among other things) this script does not seem to work. When I run the script manually from one of these machines there are no errors displayed, it all appears to work. I've used MsgBox to display the variables it collects in the process and it picks up all the correct values, it just doesn't seem to connect to the database or write to the database, something I'm not sure.

I've done a bit of reading regarding scripts that work on 32bit systems but not on 64bit systems (like running the script through SysWOW64) but I haven't had any success with any solutions offered. Would appreciate any suggestions!

The code is as follows:
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const Jet10 = 1
Const Jet11 = 2
Const Jet20 = 3
Const Jet3x = 4
Const Jet4x = 5

Dim adoConnection, adoRecordset

set fs = WScript.CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")

' Variables
dt = Now()
tm = FormatDateTime(dt,vblongtime)
LogDate = Year(dt)*1e4 + Month(dt)*1e2 + Day(dt)
LogMonth = Month(Now)
LogYear = Year(Now)
LogMonthFile = MonthName(LogMonth)
strComputerName = objNetwork.ComputerName
strIP = GetIPAddress(strComputerName)
strUserName = objNetwork.UserName
strLog = "Login"

strDBFile = "\\XXXXX\Logs\Student\" & LogYear & " - " & LogMonthFile & ".mdb"
strTable = LogDate

'// Initial DB setup (is processed only when not already exist)
' Fields going to be created (and can be used)
strFields = "RecordNumber COUNTER ,"  _
          & "UserName TEXT(50) ,"     _
          & "Log TEXT(6) ,"     _
          & "LogTime DATETIME ,"    _
          & "ComputerName TEXT(50) ," _
          & "IPaddress TEXT(50) ,"    _
          & "Notes MEMO"
Call CreateDataTable(strDBFile, Jet4x, strTable, strFields)

'// start Log logon event ---------------------------------------------
If fs.FileExists( strDBFile ) then

  ' Compose the INSERT statement.
  On Error Resume Next
  statement = "INSERT INTO " & strTable _
    & "(UserName,Log,LogTime,ComputerName,IPaddress)"
  statement = statement & " VALUES " _
    & "('" & strUserName & "','" & strLog & "','" & tm & "','" & strComputerName & "','" & strIP & "')"

  ' Initialize the database connection.
  Set adoConnection = CreateObject("ADODB.Connection")

  ' Open the database, use Microsoft Jet OLEDB data provider
  adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBFile

  ' Execute the statement.
  adoConnection.Execute statement, , adCmdText
  On Error GoTo 0
End If

wscript.quit 0

Function GetIPAddress(strComputer)
    Set TmpFolder = FS.GetSpecialFolder(2)
        TmpFile   = TmpFolder & "\" & FS.GetTempName
    With createobject("wscript.shell")
      Onreturn = .run("%comspec% /c ping.exe/a /4 -n 1 -w 1 " _
        & strComputer & ">" & Chr(34) & TmpFile & Chr(34),0 ,True)
    End With
    Set ts = FS.OpenTextFile(TmpFile, 1, True, 0)
    Do Until ts.AtEndOfStream
      strLine = ts.ReadLine
      If CBool(InStr(UCase(strLine),UCase(strComputer))) Then
        GetIPAddress = split(split(strLine,"[")(1),"]")(0)
        Exit Do
      End If
    FS.deletefile TmpFile
    GetIPAddress = GetIPAddress
End Function

Sub CreateDataTable(FileName, Format, sTable, sFields)
  On Error Resume Next
  'Create Access2000 database
  If Not fs.FileExists( FileName ) then
    Set Catalog = CreateObject("ADOX.Catalog")
    Catalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Jet OLEDB:Engine Type=" & Format & _
     ";Data Source=" & FileName
  End If
  If fs.FileExists( FileName ) then
    'create table
    Set adoConnection = CreateObject("ADODB.Connection")
    'check if table already exist (will not raise error)
    Set adoRecordSet = CreateObject("ADODB.Recordset")
    adoRecordset.Open "SELECT * FROM " & sTable , _
      adoConnection, adOpenStatic, adLockOptimistic
    If not err.number = 0 then
      If adoRecordset.RecordCount = 0 Then
        adoConnection.Open _
          "Provider= Microsoft.Jet.OLEDB.4.0; " & _
          "Data Source=" & FileName
        adoConnection.Execute "CREATE TABLE " & _
        sTable & "(" & sFields & ")"
      End If
    End If
  End If
End Sub

Open in new window

Thanks all,

Question by:teztickles
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
  • 2
  • +2

Expert Comment

ID: 35161221
As you know there is no 64-bit provider for Jet or ACE.
All you need is force the script to run as 32-bit, i.e, you need to start the 32-bit scripting host cscript.exe which is in the syswow64 folder  

Author Comment

ID: 35161423
Hi pasolo,

I actually tried that but I still had the same result - no errors, just no writing to the database.

Author Comment

ID: 35161472
Ok I take that back!

I just tried it again and I got a successful result!

I guess now the question would be how do I get this script to run from cscript if it's running from a Windows 7 machine?
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more


Author Comment

ID: 35161535
Sorry I should have explained how this all works a little better. This script runs from user logon group policy rule so that when a user logs on to any computer in the domain the script runs. As there is now this mix of Windows XP x86 and Windows 7 x64 machines is there anyway to distinguish which operating system a user has logged onto and run the script accordingly?
LVL 11

Expert Comment

ID: 35161541
This has to do with UAC.  Have a look at this article for ways around this.
LVL 65

Accepted Solution

RobSampson earned 2000 total points
ID: 35162359
This snippet can tell you the OS Version, so just add a objWshShell.Run line there to run whatever you need to run for each OS.


Set objWshShell = WScript.CreateObject("WScript.Shell")
strOSVersion = objWshShell.RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
If strOSVersion = "5.1" Then
    'Insert Windows XP Statements
ElseIf strOSVersion = "6.0" Then
    'Insert Windows Vista Statements
ElseIf strOSVersion = "6.1" Then
    'Insert Windows 7 Statements
End If

Open in new window


Author Comment

ID: 35162444
Thanks for that Rob, I actually have just managed to make something very similar so when the script runs it knows which OS it's in and from there I can call the original script(s). Of course yours is much more streamlined though!

I have it now so it's working from XP, it calls the script and runs it from objWshShell.Run. To run it from the cscript in Windows 7 however would I would imagine I woudl just use the objWshShell.Run and then  put the path of the cscript.exe in the SysWOW64 folderfollowed by the path of the script to run it in (i.e. %windir%\SysWOW64\cscript.exe \\server\share\script.vbs). Would this be correct?

I'm actually at home now so can't test out my theory.

Thanks again,

LVL 65

Expert Comment

ID: 35162463
Yes, that looks correct.  I can't test it either, but I believe that's where the 32 bit CScript.exe is.


Expert Comment

ID: 35163164
Use a second script to launch the correct version, like this:

Set objWshShell = WScript.CreateObject("WScript.Shell")
if objWshShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") = "AMD64" Then
      objWshShell.run("%windir%\SysWOW64\cscript.exe \\server\share\script.vbs")
      objWshShell.run("%windir%\System32\cscript.exe \\server\share\script.vbs")
End If
LVL 51

Expert Comment

ID: 35166088

Try turning it off.

This was mentioned already!

No zupe for me!!!  LOL


Author Comment

ID: 35177009
Hi all,

Now that I'm back at work I've had a chance to quickly try turning off UAC (with restart) and that has had no effect on the script, it still runs without error but does not do what it's supposed to do.

I'll try out the scripting side of things now and post back when I'm done.


LVL 11

Expert Comment

ID: 35379614
When you used SysWoW64, did you run it like the below?  If not, give that a try.

C:\Windows\SysWoW64\cscript.exe C:\ScriptDirectory\Script.vbs

Here's an article about Jet on 64-bit systems.

The reason this is how it has to be done is referenced here.

Author Closing Comment

ID: 35406030
Thanks Rob!

Author Comment

ID: 35406040
Sorry for the very late reply. I've actually changed jobs now so I never got a chance to fully implement that script. I'd tried it out and it did work, I think there were a couple of little hiccups I wanted to fix but just never got round to doing that what with training my replacement.

Points awarded to RobSampson as his script had the desired effect that I was after, just a shame it was never fine tuned enough to implement.

Thanks all for your suggestions!

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Assume you have an outside contractor who comes in seasonally or once a week to do some work in your office, but you only want to give him access to the programs and files he needs and keep all other documents and programs private. Can you do this o…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

770 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