Referencing network folders in vbscript

Glitterati2006
Glitterati2006 used Ask the Experts™
on
This script will work if I remove the part that references the network folder. The code looks to me like it should work but it does nothing.  No error.  Nothing.  What am I doing wrong?

Option Explicit
Dim file1, file2, fso, shell, objNetwork, curUser

set shell = createobject("wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
curUser = objNetwork.Username
file1 = "C:\\Temp\\done.txt"
file2 = "S:\\" & curUser & "\\done.txt"

msgbox file2

If fso.FileExists(file1) Then
      msgbox "This file exists."
  If fso.FileExists(file2) Then
      msgbox "This files already exists on the S drive"
      Else
            MsgBox("The file does not exist.  Install new client")  
            shell.run "chubbard.bat"
            set file1 = fso.CreateTextFile("C:\\Temp\\done.txt")
            set file2 = fso.CreateTextFile("S:\\" & curUser & "\\done.txt")
            
  End if
End If
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
can you try to reference the network path like this

"\\Server\C$\"& curUser & "\\done.txt"
where c$ will be the hard drive that contain the Share resource for the Network that is mapped
Ex:

set file2 = fso.CreateTextFile("\\KDTestServer\D$\Temp\"& curUser & "\\done.txt")

Author

Commented:
That was a great idea but still no love.
Did the User has rights to write on this folder??

Try this to see if pop up any error

Option Explicit
Dim file1, file2, fso, shell, objNetwork, curUser

set shell = createobject("wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
curUser = objNetwork.Username
file1 = "C:\\Temp\\done.txt"
file2 = "S:\\" & curUser & "\\done.txt"

msgbox file2

If fso.FileExists(file1) Then
      msgbox "This file exists."
  If fso.FileExists(file2) Then
      msgbox "This files already exists on the S drive"
      Else
            MsgBox("The file does not exist.  Install new client")  
        Try
            shell.run "chubbard.bat"
            set file1 = fso.CreateTextFile("C:\\Temp\\done.txt")
            set file2 = fso.CreateTextFile("S:\\" & curUser & "\\done.txt")
    Catch ex As Exception
         msg(ex.Message)
    End Try
 Catch Er as Err
     End if
End If
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Author

Commented:
When it gets to "Catch ex As Exception" I get the following error:

"Expected end of statement"
Sorry was my mistake is like this

Option Explicit
Dim file1, file2, fso, shell, objNetwork, curUser

set shell = createobject("wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
curUser = objNetwork.Username
file1 = "C:\\Temp\\done.txt"
file2 = "S:\\" & curUser & "\\done.txt"

msgbox file2

If fso.FileExists(file1) Then
      msgbox "This file exists."
  If fso.FileExists(file2) Then
      msgbox "This files already exists on the S drive"
      Else
            MsgBox("The file does not exist.  Install new client")  
        Try
            shell.run "chubbard.bat"
            set file1 = fso.CreateTextFile("C:\\Temp\\done.txt")
            set file2 = fso.CreateTextFile("S:\\" & curUser & "\\done.txt")
    Catch ex As Exception
         msg(ex.Message)
    End Try
End If

Author

Commented:
:-(

Same error in the same place.
replace  msg(ex.Message)
with msgbox(ex.Message) and also add another End If at the End of the statement


If fso.FileExists(file1) Then
      msgbox "This file exists."
  If fso.FileExists(file2) Then
      msgbox "This files already exists on the S drive"
      Else
            MsgBox("The file does not exist.  Install new client")  
        Try
            shell.run "chubbard.bat"
            set file1 = fso.CreateTextFile("C:\\Temp\\done.txt")
            set file2 = fso.CreateTextFile("S:\\" & curUser & "\\done.txt")
    Catch ex As Exception
         msgbox(ex.Message)
    End Try
 End If
End If

Author

Commented:
Same error in the same place.  Maybe this just simply can't be done using a VBScript?
I managed to get it to work with the following script.  Apparently it was hatin' on my nested IF statements.

Option Explicit
Dim file1, file2, fso, shell, objNetwork, curUser
Dim strDriveLetter, strRemotePath
strRemotePath = "S:"

Set objNetwork = CreateObject("WScript.Network")

set shell = createobject("wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
curUser = objNetwork.Username

file2 = "C:\Temp\done.txt"
file1 = strRemotePath & "\" & curUser & "\done.txt"

If fso.FileExists(file1) Then
      msgbox "This file exists."
end if
If fso.FileExists(file2) Then
      msgbox "The file exists on S drive"
      Else
        MsgBox "File doesn't exist.  Install new client"
            shell.run "chubbard.bat"
            set file2 = fso.CreateTextFile("C:\Temp\done.txt")
            set file1 = fso.CreateTextFile (strRemotePath & "\" & curUser & "\done.txt")
End If

Author

Commented:
No user answers solved my problem.  I was able to resolve the issue on my own.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial