Solved

Microsoft VBScript runtime error: Object required: 'objfso' in (50, 13)

Posted on 2009-03-31
7
1,409 Views
Last Modified: 2013-11-25
I have been modifying a script to create and map a drive if it does not exist. I am not able to get past the error indicated above. Any help would be greatly appreciated. The code is as follows:


Set objGroupRFTime = GetObject("LDAP://CN=RFEM Time,OU=Department-function distribution groups,OU=RFEM,DC=RFEK,DC=com")

 

For Each oUser In objGroupRFTime.Members

      

   If oUser.Class = "user" Then

 

   Set objNet = WScript.CreateObject("WScript.Network")

   Set FSO = CreateObject("scripting.filesystemobject")

 

   sUserName = objNet.UserName

   sDomainName= objNet.UserDomain

 

   If LCase(oUser.samAccountName) = LCase(sUserName) Then

      folderToCheckFor = "\\rfaccount\d$\OLMS\Orion\RFEMTime\" & sUserName

      If (FSO.FolderExists(folderToCheckFor)) = False Then

         FSO.CreateFolder(folderToCheckFor)

         Set WshShell = WScript.CreateObject("WScript.Shell")

         

         for i=1 to 15

            if objfso.folderexists(folderToCheckFor)<>0 then

               Call WshShell.Run("CACLS " & folderToCheckFor & " /T /E /C /G " & sDomainName & "\" & sUserName & ":F",2,True)  

               exit for

            end if

            WScript.Sleep 1000

         next

         

         Set WshShell = Nothing      

      End If

      

      a="\\rfaccount\d$\OLMS\Orion\RFEMTime\" & sUserName

      

      If FSO.DriveExists("W:") = False Then

         for i=1 to 15

            If objfso.folderexists(a)<>0 Then

               objnet.mapnetworkdrive "w:",a

               exit for

            end if

            WScript.Sleep 1000

         next

      Else

 

         objnet.removenetworkdrive "w:", True

         WScript.sleep 1000

         for i=1 to 15

            if objfso.folderexists(a)<>0 then         

               objnet.mapnetworkdrive "w:",a

               exit for

            end if

            WScript.Sleep 1000

         next

      End If

 

   End If

   Set FSO = Nothing

   Set objNet = Nothing

 

   End If

   oUser.SetInfo

   Set oUser = Nothing

Next

 

WScript.Quit

 

for i=1 to 15

  If objfso.folderexists(a)<>0 then

     objnet.mapnetworkdrive "w:",a

     Exit for

  End if

  WScript.Sleep 1000

Next

Open in new window

0
Comment
Question by:RFEMHelpdesk
  • 4
  • 3
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 24032541

Set objGroupRFTime = GetObject("LDAP://CN=RFEM Time,OU=Department-function distribution groups,OU=RFEM,DC=RFEK,DC=com")

 

For Each oUser In objGroupRFTime.Members

      

   If oUser.Class = "user" Then

 

   Set objNet = WScript.CreateObject("WScript.Network")

   Set FSO = CreateObject("scripting.filesystemobject")

 

   sUserName = objNet.UserName

   sDomainName= objNet.UserDomain

 

   If LCase(oUser.samAccountName) = LCase(sUserName) Then

      folderToCheckFor = "\\rfaccount\d$\OLMS\Orion\RFEMTime\" & sUserName

      If (FSO.FolderExists(folderToCheckFor)) = False Then

         FSO.CreateFolder(folderToCheckFor)

         Set WshShell = WScript.CreateObject("WScript.Shell")

         

         for i=1 to 15

            if FSO.folderexists(folderToCheckFor)<>0 then

               Call WshShell.Run("CACLS " & folderToCheckFor & " /T /E /C /G " & sDomainName & "\" & sUserName & ":F",2,True)  

               exit for

            end if

            WScript.Sleep 1000

         next

         

         Set WshShell = Nothing      

      End If

      

      a="\\rfaccount\d$\OLMS\Orion\RFEMTime\" & sUserName

      

      If FSO.DriveExists("W:") = False Then

         for i=1 to 15

            If FSO.folderexists(a)<>0 Then

               objnet.mapnetworkdrive "w:",a

               exit for

            end if

            WScript.Sleep 1000

         next

      Else

 

         objnet.removenetworkdrive "w:", True

         WScript.sleep 1000

         for i=1 to 15

            if FSO.folderexists(a)<>0 then         

               objnet.mapnetworkdrive "w:",a

               exit for

            end if

            WScript.Sleep 1000

         next

      End If

 

   End If

   Set FSO = Nothing

   Set objNet = Nothing

 

   End If

   oUser.SetInfo

   Set oUser = Nothing

Next

 

WScript.Quit

 

for i=1 to 15

  If FSO.folderexists(a)<>0 then

     objnet.mapnetworkdrive "w:",a

     Exit for

  End if

  WScript.Sleep 1000

Next

Open in new window

0
 

Author Comment

by:RFEMHelpdesk
ID: 24032942
Please and thank you. The code works if an administrator but not as a user. I am getting the error at 29,10 Permission denied. I have shared out the location with full permissions in an effort to determine the cause with the same result. I have also granted NTFS level permissions. Still no luck, any ideas?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24032958
Line 29 is blank...but I can tell you're trying to access an administrative/hidden share (d$) which is restricted for admins only...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:RFEMHelpdesk
ID: 24033169
So now that I have my mental defect out of the way! I have removed the call to the hidden share and replaced it with the share name and all works quite smoothly. Thank you for your rapid replies to this issue. In addition, so that I may learn from this, what was it that was changed in the script to make it function correctly?
Set objGroupRFTime = GetObject("LDAP://CN=RFEM Time,OU=Department-function distribution groups,OU=RFEM,DC=RFEK,DC=com")

 

For Each oUser In objGroupRFTime.Members

      

   If oUser.Class = "user" Then

 

   Set objNet = WScript.CreateObject("WScript.Network")

   Set FSO = CreateObject("scripting.filesystemobject")

 

   sUserName = objNet.UserName

   sDomainName= objNet.UserDomain

 

   If LCase(oUser.samAccountName) = LCase(sUserName) Then

      folderToCheckFor = "\\rfaccount\RFEMTime\" & sUserName

      If (FSO.FolderExists(folderToCheckFor)) = False Then

         FSO.CreateFolder(folderToCheckFor)

         Set WshShell = WScript.CreateObject("WScript.Shell")

         

         for i=1 to 15

            if FSO.folderexists(folderToCheckFor)<>0 Then

               Call WshShell.Run("CACLS " & folderToCheckFor & " /T /E /C /G " & sDomainName & "\" & sUserName & ":F",2,True)  

               exit For

            end If

            WScript.Sleep 1000

         Next

         

         Set WshShell = Nothing      

      End If

      

      a="\\rfaccount\RFEMTime\" & sUserName

      

      If FSO.DriveExists("W:") = False Then

         for i=1 to 15

            If FSO.folderexists(a)<>0 Then

               objnet.mapnetworkdrive "w:",a

               exit For

            end If

            WScript.Sleep 1000

         Next

      Else

 

         objnet.removenetworkdrive "w:", True

         WScript.sleep 1000

         for i=1 to 15

            if FSO.folderexists(a)<>0 then         

               objnet.mapnetworkdrive "w:",a

               exit For

            end If

            WScript.Sleep 1000

         Next

      End If

 

   End If

   Set FSO = Nothing

   Set objNet = Nothing

 

   End If

   oUser.SetInfo

   Set oUser = Nothing

Next

 

WScript.Quit

 

For i=1 to 15

  If FSO.folderexists(a)<>0 then

     objnet.mapnetworkdrive "w:",a

     Exit for

  End if

  WScript.Sleep 1000

Next

Open in new window

0
 

Author Comment

by:RFEMHelpdesk
ID: 24033228
I see now, on lines 34,45 and 65 the obj was removed clarifying the call to the FSO.folderexisits variable.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 24033316
Correct - you can call the reference to the file system object anything...
For example:

Set PeanutButter = CreateObject("Scripting.FileSystemObject")

You just have to be certain you always use it as that name in your code...

Set objFolder = PeanutButter.GetFolder("C:\Folder\")
If PeanutButter.FolderExists("C:\Folder\") Then  ' ...

0
 

Author Closing Comment

by:RFEMHelpdesk
ID: 31565014
Thank You SIRBOUNTY! Sorry for the delay in closing the request.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now