?
Solved

VBS and %lOGONSERVER%

Posted on 2005-04-14
5
Medium Priority
?
1,625 Views
Last Modified: 2008-02-01
Hi guys please can you help me out here, I have a script that copies a file to the pc's system32 directory but I am having difficulty, I would like to set the %netlogon% as the source folder.

at the moment is errors saying "source folder not found" however I replace the source folder with a UNC server name and path it all works fine. I am in a desperate hurry for this so I have put 500 points on it, I would put 10,000 if I could thanks in advanced !!!

'==========================================================================
dim strSource, strDestination
strSource = "\\wfflongham01\netlogon\logo\"
strDestination = "c:\windows\system32\logo\"
'==========================================================================

SynchroniseFiles strSource, strDestination

function SynchroniseFiles(byval strSourceFolder, byval strDestinationFolder)

     CheckForBackSlash strSourceFolder
     CheckForBackSlash strDestinationFolder
     
     dim objFSO
     set objFSO = Createobject("scripting.filesystemobject")
     
     if not objFSO.folderexists(strDestinationFolder) then
          objFSO.createfolder(strDestinationFolder)
     end if

     dim file
     for each file in objFSO.getfolder(strSourceFolder).files
     
          if not objFSO.fileexists(strDestinationFolder & file.name) then
               objFSO.copyfile file, strDestinationFolder & file.name
          else
               if file.DateLastModified > objFSO.getfile(strDestinationFolder & file.name).DateLastModified then
                    objFSO.copyfile file, strDestinationFolder & file.name
               end if
          end if
     next

     set objFSO = nothing

end function


function CheckForBackSlash(byref strFolder)
     if right(strFolder, 1) <> "\" then
          strFolder = strFolder & "\"
     end if
end function
0
Comment
Question by:Blackduke77
  • 2
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
JesterToo earned 2000 total points
ID: 13798885
Try adding these lines to your script...

   set WshShell = CreateObject("WScript.Shell")
   set WshEnv   = WshShell.Environment("Process")
   strSource      = WshEnv("NetLogon") & "\netlogon\logo\"

Are you certain the env var name is "netlogon"?  Windows usually names it as "LogonServer".  Issue a "set" command at a command prompt and double check... if it really is netlogon then you might need to compensate in line 3 (of my addon lines) in case a more complete path is present instead of just the logon server name.

HTH,
Lynn
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13806250
Did the suggestion that JesterToo work ? Just curious as I have seen this question for quite some time and wanted to know if it did help or not, if not then we can try and help you further !

I know there is a 21 day period or there abouts and I am not trying to bug you about anything , just would be nice to know so that other experts can help you further if required !
0
 
LVL 1

Author Comment

by:Blackduke77
ID: 13815053
Going to try it now, will post my results after


Robbie
0
 
LVL 1

Author Comment

by:Blackduke77
ID: 13815554
I could not get it working with the sugestion above but I did via MSDN news group please find working code below, thanks to jester for getting me on the right track.

'CHANGE THESE TO ALTER WHERE THE SOURCE AND DESTINATION LOCATIONS ARE
'=========================================================================
dim strSource, strDestination
dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")
strSource = WshShell.ExpandEnvironmentStrings("%LogonServer%\netlogon\logo\")
strDestination = WshShell.ExpandEnvironmentStrings("%windir%\system32\logo\")
'=========================================================================

SynchroniseFiles strSource, strDestination

function SynchroniseFiles(byval strSourceFolder, byval strDestinationFolder)

      CheckForBackSlash strSourceFolder
      CheckForBackSlash strDestinationFolder
      
      dim objFSO
      set objFSO = Createobject("scripting.filesystemobject")
      
      if not objFSO.folderexists(strDestinationFolder) then
            objFSO.createfolder(strDestinationFolder)
      end if

      dim file
      for each file in objFSO.getfolder(strSourceFolder).files
      
            if not objFSO.fileexists(strDestinationFolder & file.name) then
                  objFSO.copyfile file, strDestinationFolder & file.name
            else
                  if file.DateLastModified > objFSO.getfile(strDestinationFolder & file.name).DateLastModified then
                        objFSO.copyfile file, strDestinationFolder & file.name
                  end if
            end if
      next

      set objFSO = nothing

end function


function CheckForBackSlash(byref strFolder)
      if right(strFolder, 1) <> "\" then
            strFolder = strFolder & "\"
      end if
end function


'function GetUserAppDataFolder
'      dim objUserData
'      set objUserData = Createobject("WinNTSystemInfo")
'      GetUserAppDataFolder = "C:\Documents and Settings\" & objUserData.Username & "\Application Data\"
'      set objUserData = nothing
'end function
0
 
LVL 22

Expert Comment

by:JesterToo
ID: 13816165
Hmmm, that code fragment I provided has always worked well for me... I'll have to do a bit of research now to satisfy my own curiosity.

Glad you got everything working and thanks for the grade!

-- Lynn
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 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