Avatar of Glitterati2006
Glitterati2006

asked on 

Referencing network folders in vbscript

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
ASP

Avatar of undefined
Last Comment
Glitterati2006
Avatar of Jesus Rodriguez
Jesus Rodriguez
Flag of United States of America image

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")
Avatar of Glitterati2006
Glitterati2006

ASKER

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
Avatar of Glitterati2006

ASKER

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
Avatar of Glitterati2006

ASKER

:-(

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
Avatar of Glitterati2006

ASKER

Same error in the same place.  Maybe this just simply can't be done using a VBScript?
ASKER CERTIFIED SOLUTION
Avatar of Glitterati2006
Glitterati2006

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Glitterati2006

ASKER

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

Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.

82K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo