1
votes

I'm trying to use the current path of the script using the following snippet:

Set oShell = CreateObject("WScript.Shell")
Set oFileSystemObj = CreateObject("Scripting.FileSystemObject")

PathName = oFileSystemObj.GetParentFolderName(Wscript.ScriptFullName)

But, it keeps throwing up the error saying

'Wscript' Object Required.

1
Your code produces no errors for me! - GTAVLover
Is there something you've done to change whether 64bit or 32bit wscript.exe is running on your machine? - Harshil
@GTAVLover I'm running this on a 64 bit Windows 10 machine, is there anything I need to do to fix up which wscript.exe should be used (System32/SysWOW64)? - Harshil
Do not create that object wscript.shell.... It works on some of the machines without setting that object if the code is stored in a .vbs file. Just comment that line and try again. - Mithilesh Indurkar
Are you running the code as a plain VBScript file (.vbs) with either wscript.exe or cscript.exe? Or are you using some other engine (HTA, QTP, ...)? Not all VBScript engines have a builtin WScript object. - Ansgar Wiechers

1 Answers

0
votes

In this case, use the following code to get current path of the script:

Dim oFileSystemObj: Set oFileSystemObj = CreateObject("Scripting.FileSystemObject")

PathName = oFileSystemObj.GetParentFolderName(oFileSystemObj.GetAbsolutePathName("."))