Unable to run vbs on windows server 2019 (working on Windows Server 2014/16 and Windows 10)

Willy Taveras 1 Reputation point
2022-01-18T17:49:27.183+00:00

Hi, I hope you all are fine.

I have a VBS Script that is working fine when using Windows 10, Windows Server 2014/2016 but it doesn't work on Windows Server 2019.
Is a fresh installation, I'm doing the same steps. All permissions are granted.

The script stops when executing the following line: executeglobal fso.opentextfile("C:\Scripts\MyFile.txt", 1).readall

Testing, seems like the issue is with "executeglobal" and "execute" commands on Windows Server 2019.

No error is shown, no messages on the console.

wscript.exe stays running but never ends.

Thanks for your support.

Regards,
WT

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 31,581 Reputation points
    2022-01-19T14:14:45.807+00:00

    Why does this have a windows-server-powershell tag?

    Probably because the Powershell tag will be seen by folks who tend to answer scripting questions. Like you and me.

    The script stops when executing the following line: executeglobal fso.opentextfile("C:\Scripts\MyFile.txt", 1).readall

    I think that the best course of action would be to build a test script that recreates the error. That way forum users who have access to 2019 server can run it to verify that there is a bug in the OS.

    Given that MS is no longer enhancing VB script, I would be surprised if there was a change in 2019 that broke your script. I would suspect something else in the script or something in your environment (antivirus?) that might be the root problem.

    Willy, do you have a test script, or can you build a generic one based on however your script uses function's, sub's, and whatever?

    I threw this together just to play with. It works on Win10, but I don't have a 2019 server to test on.

     option explicit
     Const ForReading = 1, ForWriting = 2, ForAppending = 8
      Dim oFs, oF
      Dim strData
        Dim somefile
     somefile = "C:\temp\tst.txt"        ' <<<===== put a file name here
     wscript.echo "Script host version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion
     Foo
     Foo2
     wscript.echo "Done."
    
    function Foo()
     Set ofs = CreateObject("Scripting.FileSystemObject")
        strData = oFs.opentextFile(somefile,ForReading).readall
     wscript.echo len(strData)
     strData = ""
        executeglobal "strData = oFs.opentextFile(somefile,ForReading).readall"
     wscript.echo len(strData)
     strData = ""
        execute "strData = oFs.opentextFile(somefile,ForReading).readall"
     wscript.echo len(strData)
    end function 
    
    Sub Foo2()
     Set ofs = CreateObject("Scripting.FileSystemObject")
        strData = oFs.opentextFile(somefile,ForReading).readall
     wscript.echo len(strData)
     strData = ""
        executeglobal "strData = oFs.opentextFile(somefile,ForReading).readall"
     wscript.echo len(strData)
     strData = ""
        execute "strData = oFs.opentextFile(somefile,ForReading).readall"
     wscript.echo len(strData)
    end sub 
    
    0 comments No comments

  2. Rich Matheisen 45,011 Reputation points
    2022-01-19T15:44:35.717+00:00