0

When calling this method it just returns the error, system variable is undefined.

I am currently trying to make a GPO logon script that checks to see if a directory exists and if it doesn't create it.

I am just very confused as there are so many visual basic variants and I can't seem to find what I need. Is the visual basic I need vbs or vb.net or vb scrips im honestly lost.

System.IO.Directory just returns me an error and I have tried many others but receive the same error.

Option Explicit
Dim l: l = "Z:"
Dim s: s = "\\TEST-SERVER\Shared Folder"
Dim Network: Set Network = CreateObject("WScript.Network")
Dim CheckDrive: Set CheckDrive = Network.EnumNetworkDrives()
Dim DriveExists: DriveExists = False
Dim i
'check to see if drive exists
For i = 0 to CheckDrive.Count - 1
  If CheckDrive.Item(i) = l Then
    DriveExists = True
  End If
Next
'if drive doesnt map it
If DriveExists = False Then
  Network.MapNetworkDrive l, s, False
Else
 'drive already mapped
End If


Dim strDirectory 
strDirectory = "C:\Screensaver"
If(Not System.IO.Directory.Exists(strDirectory)) Then
    System.IO.Directory.CreateDirectory(strDirectory)
End If
  • What is the error that you are getting? In case it helps, this post shows how to use FileSystemObject in vbscript to check if a folder exists: https://stackoverflow.com/questions/14121790/vbs-script-to-check-if-a-folder-exist-and-then-run-a-file – Wiz Apr 15 '19 at 17:09
  • VBScript can only use COM objects, not .Net objects. Some .Net classes expose a COM interface and can be used that way (like `System.Collections.ArrayList`), but that's the exception, not the rule. – Ansgar Wiechers Apr 15 '19 at 20:13

1 Answers1

0

System.* is for VB.net, but the rest of your script looks like it wants to be VBS. VBS can use FileSystemObject to interact with folders.

Try this for the section where you try to create the directory:

Dim strDirectory
strDirectory = "C:\Screensaver"
Set fso = CreateObject("Scripting.FileSystemObject")
If(Not fso.FolderExists(strDirectory)) Then
    fso.CreateFolder(strDirectory)
End If
Chaos
  • 250
  • 2
  • 10